[RFC PATCH] virt-sysprep:add ipconfig for preparation
Hi Rich: I just send a patch to request for your comments, then will do further work about this. things like this: [root@Allen ~]# virt-sysprep --ipconfig="eth0:192.168.1.2,255.255.255.0,192.168.1.1" --enable=ipconfig -d clone-6u1 OR [root@Allen ~]# virt-sysprep -d clone-6u1 Please comments. Thanks -Wanlong Gao Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- clone/virt-sysprep.in | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/clone/virt-sysprep.in b/clone/virt-sysprep.in index d505532..e4486d0 100644 --- a/clone/virt-sysprep.in +++ b/clone/virt-sysprep.in @@ -26,7 +26,7 @@ version="@PACKAGE_VERSION@" TEMP=`getopt \ -o a:c:d:vVx \ - --long help,add:,connect:,domain:,enable:,format::,hostname:,list-operations,selinux-relabel,no-selinux-relabel,verbose,version \ + --long help,add:,connect:,domain:,enable:,format::,hostname:,ipconfig:,list-operations,selinux-relabel,no-selinux-relabel,verbose,version \ -n $program -- "$@"` if [ $? != 0 ]; then echo "$program: problem parsing the command line arguments" @@ -91,6 +91,9 @@ while true; do --hostname) hostname_param="$2" shift 2;; + --ipconfig) + ipconfig_param="$2" + shift 2;; --list-operations) enable=list shift;; @@ -135,6 +138,7 @@ if [ -z "$enable" ]; then dhcp_client_state=yes dhcp_server_state=yes hostname=yes + ipconfig=yes logfiles=yes mail_spool=yes net_hwaddr=yes @@ -150,6 +154,7 @@ elif [ "$enable" = "list" ]; then echo "dhcp-client-state" echo "dhcp-server-state" echo "hostname" + echo "ipconfig" echo "logfiles" echo "mail-spool" echo "net-hwaddr" @@ -168,6 +173,7 @@ else dhcp-client-state) dhcp_client_state=yes ;; dhcp-server-state) dhcp_server_state=yes ;; hostname) hostname=yes ;; + ipconfig) ipconfig=yes ;; logfiles) logfiles=yes ;; mail-spool) mail_spool=yes ;; net-hwaddr) net_hwaddr=yes ;; @@ -286,6 +292,48 @@ if [ "$hostname" = "yes" ]; then esac fi +if [ "$ipconfig" = "yes" ]; then + case "$type/$distro" in + linux/fedora|linux/rhel) + if [ -d $mnt/etc/sysconfig/network-scripts ]; then + if [ -z $ipconfig_param ]; then + rm_ipconfig () + { + sed '/^IPADDR=/d;/^BOOTPROTO=/d;/^NETMASK=/d;/^GATEWAY=/d;/^DNS/d' \ + < "$1" > "$1.new" + echo "BOOTPROTO=dhcp" >> "$1.new" + mv -f "$1.new" "$1" + } + export -f rm_ipconfig + find $mnt/etc/sysconfig/network-scripts \ + -name 'ifcfg-*' -type f \ + -exec bash -c 'rm_ipconfig "$0"' {} \; + else + for (( i=1; i<8 ; i+=2 )); do + __device=$(echo "$ipconfig_param" | awk -v j=$i -F: '{print $j}') + if [ -z $__device ]; then + break + fi + __ipconfig=$(echo "$ipconfig_param" | awk -v j=$((i+1)) -F: '{print $j}') + __config_file=$(echo "$mnt/etc/sysconfig/network-scripts/ifcfg-$__device") + if [ -e $__config_file ]; then + __ip=$(echo "$__ipconfig" | awk -F, '{print $1}') + __mask=$(echo "$__ipconfig" | awk -F, '{print $2}') + __gw=$(echo "$__ipconfig" | awk -F, '{print $3}') + sed '/^IPADDR=/d;/^BOOTPROTO=/d;/^NETMASK=/d;/^GATEWAY=/d;/^DNS/d' \ + < "$__config_file" > "$__config_file.new" + echo "IPADDR=$__ip" >> "$__config_file.new" + echo "BOOTPROTO=static" >> "$__config_file.new" + echo "NETMASK=$__mask" >> "$__config_file.new" + echo "GATEWAY=$__gw" >> "$__config_file.new" + mv -f "$__config_file.new" "$__config_file" + fi + done + fi + fi + esac +fi + if [ "$logfiles" = "yes" ]; then case "$type" in linux) -- 1.7.9.2
Hi Rich, If have time, please give a comment ;) Thanks -Wanlong Gao
Hi Rich: I just send a patch to request for your comments, then will do further work about this. things like this:
[root@Allen ~]# virt-sysprep --ipconfig="eth0:192.168.1.2,255.255.255.0,192.168.1.1" --enable=ipconfig -d clone-6u1
OR
[root@Allen ~]# virt-sysprep -d clone-6u1
Please comments.
Thanks -Wanlong Gao
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- clone/virt-sysprep.in | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/clone/virt-sysprep.in b/clone/virt-sysprep.in index d505532..e4486d0 100644 --- a/clone/virt-sysprep.in +++ b/clone/virt-sysprep.in @@ -26,7 +26,7 @@ version="@PACKAGE_VERSION@"
TEMP=`getopt \ -o a:c:d:vVx \ - --long help,add:,connect:,domain:,enable:,format::,hostname:,list-operations,selinux-relabel,no-selinux-relabel,verbose,version \ + --long help,add:,connect:,domain:,enable:,format::,hostname:,ipconfig:,list-operations,selinux-relabel,no-selinux-relabel,verbose,version \ -n $program -- "$@"` if [ $? != 0 ]; then echo "$program: problem parsing the command line arguments" @@ -91,6 +91,9 @@ while true; do --hostname) hostname_param="$2" shift 2;; + --ipconfig) + ipconfig_param="$2" + shift 2;; --list-operations) enable=list shift;; @@ -135,6 +138,7 @@ if [ -z "$enable" ]; then dhcp_client_state=yes dhcp_server_state=yes hostname=yes + ipconfig=yes logfiles=yes mail_spool=yes net_hwaddr=yes @@ -150,6 +154,7 @@ elif [ "$enable" = "list" ]; then echo "dhcp-client-state" echo "dhcp-server-state" echo "hostname" + echo "ipconfig" echo "logfiles" echo "mail-spool" echo "net-hwaddr" @@ -168,6 +173,7 @@ else dhcp-client-state) dhcp_client_state=yes ;; dhcp-server-state) dhcp_server_state=yes ;; hostname) hostname=yes ;; + ipconfig) ipconfig=yes ;; logfiles) logfiles=yes ;; mail-spool) mail_spool=yes ;; net-hwaddr) net_hwaddr=yes ;; @@ -286,6 +292,48 @@ if [ "$hostname" = "yes" ]; then esac fi
+if [ "$ipconfig" = "yes" ]; then + case "$type/$distro" in + linux/fedora|linux/rhel) + if [ -d $mnt/etc/sysconfig/network-scripts ]; then + if [ -z $ipconfig_param ]; then + rm_ipconfig () + { + sed '/^IPADDR=/d;/^BOOTPROTO=/d;/^NETMASK=/d;/^GATEWAY=/d;/^DNS/d' \ + < "$1" > "$1.new" + echo "BOOTPROTO=dhcp" >> "$1.new" + mv -f "$1.new" "$1" + } + export -f rm_ipconfig + find $mnt/etc/sysconfig/network-scripts \ + -name 'ifcfg-*' -type f \ + -exec bash -c 'rm_ipconfig "$0"' {} \; + else + for (( i=1; i<8 ; i+=2 )); do + __device=$(echo "$ipconfig_param" | awk -v j=$i -F: '{print $j}') + if [ -z $__device ]; then + break + fi + __ipconfig=$(echo "$ipconfig_param" | awk -v j=$((i+1)) -F: '{print $j}') + __config_file=$(echo "$mnt/etc/sysconfig/network-scripts/ifcfg-$__device") + if [ -e $__config_file ]; then + __ip=$(echo "$__ipconfig" | awk -F, '{print $1}') + __mask=$(echo "$__ipconfig" | awk -F, '{print $2}') + __gw=$(echo "$__ipconfig" | awk -F, '{print $3}') + sed '/^IPADDR=/d;/^BOOTPROTO=/d;/^NETMASK=/d;/^GATEWAY=/d;/^DNS/d' \ + < "$__config_file" > "$__config_file.new" + echo "IPADDR=$__ip" >> "$__config_file.new" + echo "BOOTPROTO=static" >> "$__config_file.new" + echo "NETMASK=$__mask" >> "$__config_file.new" + echo "GATEWAY=$__gw" >> "$__config_file.new" + mv -f "$__config_file.new" "$__config_file" + fi + done + fi + fi + esac +fi + if [ "$logfiles" = "yes" ]; then case "$type" in linux)
On Mon, Mar 05, 2012 at 11:21:54PM +0800, Wanlong Gao wrote:
Hi Rich,
If have time, please give a comment ;)
It needs documentation (in clone/virt-sysprep.pod) :-) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On 03/06/2012 05:12 PM, Richard W.M. Jones wrote:
On Mon, Mar 05, 2012 at 11:21:54PM +0800, Wanlong Gao wrote:
Hi Rich,
If have time, please give a comment ;)
It needs documentation (in clone/virt-sysprep.pod) :-)
Yes, I'll do, any comments for my concept of the ipconfig? Thanks, Wanlong Gao
Rich.
On Tue, Mar 06, 2012 at 05:15:20PM +0800, Wanlong Gao wrote:
On 03/06/2012 05:12 PM, Richard W.M. Jones wrote:
On Mon, Mar 05, 2012 at 11:21:54PM +0800, Wanlong Gao wrote:
Hi Rich,
If have time, please give a comment ;)
It needs documentation (in clone/virt-sysprep.pod) :-)
Yes, I'll do, any comments for my concept of the ipconfig?
The concept looks OK. I wonder if this would work OK for IPv6? Most IPv6 machines won't have a static address as such though, so probably they would just not use this. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
participants (2)
-
Richard W.M. Jones -
Wanlong Gao