[xen-tools-dev] [PATCH] Add new nameserver config option

Stéphane Jourdois sjourdois at gmail.com
Sat Jul 10 12:52:17 CEST 2010


This optional config value is used in hooks to create domU resolv.conf.
If unset, domU's resolv.conf is created by the guest distrib install.
---
 bin/xen-create-image                    |   34 +++++++++++++++++++-----------
 bin/xen-create-nfs                      |   18 +++++++++-------
 etc/xen-tools.conf                      |    7 +++--
 hooks/centos-4/40-setup-networking      |   11 ++++++++++
 hooks/centos-5/40-setup-networking      |   11 ++++++++++
 hooks/dapper/40-setup-networking        |   12 +++++++++++
 hooks/debian/40-setup-networking        |   12 +++++++++++
 hooks/edgy/40-setup-networking          |   12 +++++++++++
 hooks/fedora-core-6/40-setup-networking |   11 ++++++++++
 hooks/gentoo/40-setup-networking        |   12 +++++++++++
 hooks/intrepid/40-setup-networking      |   12 +++++++++++
 hooks/karmic/40-setup-networking        |   12 +++++++++++
 12 files changed, 140 insertions(+), 24 deletions(-)

diff --git a/bin/xen-create-image b/bin/xen-create-image
index 3f651fe..38783f7 100755
--- a/bin/xen-create-image
+++ b/bin/xen-create-image
@@ -234,6 +234,10 @@ xen-create-image - Easily create new Xen instances with networking and OpenSSH.
    --broadcast=123.456.789.ABC
                 Setup the broadcast address for the new instance.
 
+   --nameserver=123.456.789.ABC
+                Setup the nameserver of the machine, multiple nameservers
+		are allowed.
+
    --bridge=brname
                 Optionally, set a specific bridge for the new instance.
                 This can be especially useful when running multiple
@@ -367,9 +371,10 @@ Create a Xen configuration file in so that xm can start the new domain.
   #
   # Networking options.
   #
-  gateway   = 192.168.1.1
-  broadcast = 192.168.1.255
-  netmask   = 255.255.255.0
+  gateway    = 192.168.1.1
+  broadcast  = 192.168.1.255
+  netmask    = 255.255.255.0
+  nameserver = 192.168.1.1
 
 
   #
@@ -479,6 +484,7 @@ Create a Xen configuration file in so that xm can start the new domain.
           --ip=192.168.1.200 \
           --netmask=255.255.255.0
           --gateway=192.168.1.1 \
+          --nameserver=192.168.1.1 \
           --dir=/home/xen --hostname=vm02.my.flat
 
   The directory specified for the output will be used to store the volumes
@@ -1545,16 +1551,17 @@ sub parseCommandLineArguments
             "copy-hosts", \$CONFIG{ 'copyhosts' },
 
             # Networking options
-            "dhcp",        \$CONFIG{ 'dhcp' },
-            "bridge=s",    \$CONFIG{ 'bridge' },
-            "gateway=s",   \$CONFIG{ 'gateway' },
-            "hostname=s",  \$CONFIG{ 'hostname' },
-            "ip=s@",       \$CONFIG{ 'ip' },
-            "mac=s",       \$CONFIG{ 'mac' },
-            "netmask=s",   \$CONFIG{ 'netmask' },
-            "broadcast=s", \$CONFIG{ 'broadcast' },
-            "vifname=s",   \$CONFIG{ 'vifname' },
-            "p2p=s",       \$CONFIG{ 'p2p' },
+            "dhcp",         \$CONFIG{ 'dhcp' },
+            "bridge=s",     \$CONFIG{ 'bridge' },
+            "gateway=s",    \$CONFIG{ 'gateway' },
+            "hostname=s",   \$CONFIG{ 'hostname' },
+            "ip=s@",        \$CONFIG{ 'ip' },
+            "mac=s",        \$CONFIG{ 'mac' },
+            "netmask=s",    \$CONFIG{ 'netmask' },
+            "broadcast=s",  \$CONFIG{ 'broadcast' },
+            "nameserver=s", \$CONFIG{ 'nameserver' },
+            "vifname=s",    \$CONFIG{ 'vifname' },
+            "p2p=s",        \$CONFIG{ 'p2p' },
 
             # Exclusive
             #
@@ -2691,6 +2698,7 @@ EOF
     $CONFIG{ 'broadcast' } &&
       logprint("Broadcast      : $CONFIG{'broadcast'}\n");
     $CONFIG{ 'gateway' } && logprint("Gateway        : $CONFIG{'gateway'}\n");
+    $CONFIG{ 'nameserver' } && logprint("Nameserver     : $CONFIG{'nameserver'}\n");
     $CONFIG{ 'p2p' }     && logprint("Point to Point : $CONFIG{'p2p'}\n");
     print "\n";
 
diff --git a/bin/xen-create-nfs b/bin/xen-create-nfs
index 1bd6ee7..a033234 100755
--- a/bin/xen-create-nfs
+++ b/bin/xen-create-nfs
@@ -20,6 +20,7 @@ xen-create-nfs - Create a Xen configuration file for an NFS-root guest.
    --gateway    The gateway address to use when configured with a static IP.
    --hostname   The hostname to configure for the guest.
    --netmask    The netmask to use when configured with a static IP.
+   --nameserver The nameserver to use when configured with a static IP.
    --ip         The IP address to use when configured with a static IP.
 
   General options:
@@ -288,14 +289,15 @@ sub parseCommandLineArguments
     GetOptions(
 
         # Networking options
-        "dhcp",        \$CONFIG{ 'dhcp' },
-        "gateway=s",   \$CONFIG{ 'gateway' },
-        "broadcast=s", \$CONFIG{ 'broadcast' },
-        "ip=s",        \$CONFIG{ 'ip' },
-        "netmask=s",   \$CONFIG{ 'netmask' },
-        "hostname=s",  \$CONFIG{ 'hostname' },
-        "memory=s",    \$CONFIG{ 'memory' },
-        "mac=s",       \$CONFIG{ 'mac' },
+        "dhcp",         \$CONFIG{ 'dhcp' },
+        "gateway=s",    \$CONFIG{ 'gateway' },
+        "broadcast=s",  \$CONFIG{ 'broadcast' },
+        "ip=s",         \$CONFIG{ 'ip' },
+        "netmask=s",    \$CONFIG{ 'netmask' },
+        "nameserver=s", \$CONFIG{ 'nameserver' },
+        "hostname=s",   \$CONFIG{ 'hostname' },
+        "memory=s",     \$CONFIG{ 'memory' },
+        "mac=s",        \$CONFIG{ 'mac' },
 
         # NFS options.
         "nfs_server=s", \$CONFIG{ 'nfs_server' },
diff --git a/etc/xen-tools.conf b/etc/xen-tools.conf
index 7567038..84eea00 100644
--- a/etc/xen-tools.conf
+++ b/etc/xen-tools.conf
@@ -160,9 +160,10 @@ image  = sparse   # Specify sparse vs. full disk images.
 # Uncomment and adjust these network settings if you wish to give your
 # new instances static IP addresses.
 #
-# gateway   = 192.168.1.1
-# netmask   = 255.255.255.0
-# broadcast = 192.168.1.255
+# gateway    = 192.168.1.1
+# netmask    = 255.255.255.0
+# broadcast  = 192.168.1.255
+# nameserver = 192.168.1.1
 #
 # Uncomment this if you wish the images to use DHCP
 #
diff --git a/hooks/centos-4/40-setup-networking b/hooks/centos-4/40-setup-networking
index d91b844..584d65f 100755
--- a/hooks/centos-4/40-setup-networking
+++ b/hooks/centos-4/40-setup-networking
@@ -73,6 +73,17 @@ E_O_STATIC
          interface=`expr $interface + 1`
      done
 
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 else
     cat <<E_O_DHCP >${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE=eth0
diff --git a/hooks/centos-5/40-setup-networking b/hooks/centos-5/40-setup-networking
index d91b844..584d65f 100755
--- a/hooks/centos-5/40-setup-networking
+++ b/hooks/centos-5/40-setup-networking
@@ -73,6 +73,17 @@ E_O_STATIC
          interface=`expr $interface + 1`
      done
 
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 else
     cat <<E_O_DHCP >${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE=eth0
diff --git a/hooks/dapper/40-setup-networking b/hooks/dapper/40-setup-networking
index eb51a40..5992b15 100755
--- a/hooks/dapper/40-setup-networking
+++ b/hooks/dapper/40-setup-networking
@@ -112,6 +112,18 @@ E_O_STATIC
         count=`expr $count + 1`
         interface=`expr $interface + 1`
     done
+
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 }
 
 
diff --git a/hooks/debian/40-setup-networking b/hooks/debian/40-setup-networking
index e1e7a60..f3dfb8b 100755
--- a/hooks/debian/40-setup-networking
+++ b/hooks/debian/40-setup-networking
@@ -132,6 +132,18 @@ E_O_STATIC
         count=`expr $count + 1`
         interface=`expr $interface + 1`
     done
+
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 }
 
 
diff --git a/hooks/edgy/40-setup-networking b/hooks/edgy/40-setup-networking
index f46c38c..74dd790 100755
--- a/hooks/edgy/40-setup-networking
+++ b/hooks/edgy/40-setup-networking
@@ -121,6 +121,18 @@ E_O_STATIC
         count=`expr $count + 1`
         interface=`expr $interface + 1`
     done
+
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 }
 
 
diff --git a/hooks/fedora-core-6/40-setup-networking b/hooks/fedora-core-6/40-setup-networking
index d91b844..584d65f 100755
--- a/hooks/fedora-core-6/40-setup-networking
+++ b/hooks/fedora-core-6/40-setup-networking
@@ -73,6 +73,17 @@ E_O_STATIC
          interface=`expr $interface + 1`
      done
 
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 else
     cat <<E_O_DHCP >${prefix}/etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE=eth0
diff --git a/hooks/gentoo/40-setup-networking b/hooks/gentoo/40-setup-networking
index 4711d9a..3035de3 100755
--- a/hooks/gentoo/40-setup-networking
+++ b/hooks/gentoo/40-setup-networking
@@ -96,6 +96,18 @@ E_O_STATIC
         count=`expr $count + 1`
         interface=`expr $interface + 1`
     done
+
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 }
 
 
diff --git a/hooks/intrepid/40-setup-networking b/hooks/intrepid/40-setup-networking
index f46c38c..74dd790 100755
--- a/hooks/intrepid/40-setup-networking
+++ b/hooks/intrepid/40-setup-networking
@@ -121,6 +121,18 @@ E_O_STATIC
         count=`expr $count + 1`
         interface=`expr $interface + 1`
     done
+
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 }
 
 
diff --git a/hooks/karmic/40-setup-networking b/hooks/karmic/40-setup-networking
index f46c38c..74dd790 100755
--- a/hooks/karmic/40-setup-networking
+++ b/hooks/karmic/40-setup-networking
@@ -121,6 +121,18 @@ E_O_STATIC
         count=`expr $count + 1`
         interface=`expr $interface + 1`
     done
+
+    #
+    # Hooks are run chrooted, hence the resolv.conf is moved
+    # temporarily to /etc/resolv.conf.old. Use that file, it
+    # will be restored after hooks are run.
+    #
+    if [ '*' != "*$nameserver" ]; then
+	rm -f ${prefix}/etc/resolv.conf.old
+	for ns in $nameserver; do 
+	    echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
+	done
+    fi
 }
 
 
-- 
1.5.6.5



More information about the xen-tools-dev mailing list