[Ovirt-devel] Rebased - [PATCH] get host networking configuration from ovirt server

Alan Pevec apevec at redhat.com
Tue May 6 21:54:11 UTC 2008


commit cddbecff92d0d1af74a281bfd353f9faac89e9c1
Author: Alan Pevec <apevec at redhat.com>
Date:   Tue May 6 23:15:41 2008 +0200

    get host networking configuration from oVirt server
    
    PXE-boot interface[1] is temporarily setup early in the boot sequence (init.d/ovirt-early) and configuration[2] is retrieved from oVirt server.
    hostname is put in the requested URL to allow per host configuration, but for now all hosts get the same config: eth0 bridged to ovirtbr0 bridge
    
    [1] IPAPPEND 2 in pxelinux config appends MAC of the PXE-booted NIC to the kernel cmdln e.g. BOOTIF=01-00-16-3e-12-34-57
    [2] current implementation is a list of augtool commands, see http://augeas.net/tour.html

diff --git a/ovirt-host-creator/common-pkgs.ks b/ovirt-host-creator/common-pkgs.ks
index 18db4ee..618a73a 100644
--- a/ovirt-host-creator/common-pkgs.ks
+++ b/ovirt-host-creator/common-pkgs.ks
@@ -22,6 +22,7 @@ cyrus-sasl-lib
 collectd
 collectd-virt
 tftp
+augeas
 nc
 bind-utils
 -policycoreutils
diff --git a/ovirt-host-creator/common-post.ks b/ovirt-host-creator/common-post.ks
index 17291b4..6c503b4 100644
--- a/ovirt-host-creator/common-post.ks
+++ b/ovirt-host-creator/common-post.ks
@@ -42,19 +42,60 @@ cat > /etc/init.d/ovirt-early << \EOF
 
 # Source functions library
 . /etc/init.d/functions
+. /etc/init.d/ovirt-functions
 
-start() {
+configure_from_network() {
+    DEVICE=$1
+    if [ $DEVICE ]; then
+        echo -n "."
+        # setup temporary interface to retrieve configuration
+        echo "network --device $DEVICE --bootproto dhcp" | nash
+        if [ $? -eq 0 ]; then
+            echo -n "."
+            # from network-scripts/ifup-post
+            IPADDR=$(LANG=C ip -o -4 addr ls dev ${DEVICE} | awk '{ print $4 ; exit }')
+            eval $(ipcalc --silent --hostname ${IPADDR} ; echo "status=$?")
+            if [ "$status" = "0" ]; then
+                hostname $HOSTNAME
+                # retrieve remote config
+                find_srv ovirt tcp
+                echo -n "."
+                if [ $SRV_HOST -a $SRV_PORT ]; then
+                    curl -s http://$SRV_HOST:$SRV_PORT/ovirt/cfgdb/$(hostname) \
+                        | augtool > /dev/null 2>&1
+                    if [ $? -eq 0 ]; then
+                        return
+                    fi
+                fi
+            fi
+        fi
+    fi
+    # default oVirt network configuration:
+    # bridge each ethernet device in the system
+    ETHDEVS=$(cd /sys/class/net && ls -d eth*)
+    for eth in $ETHDEVS; do
+        BRIDGE=ovirtbr`echo $eth | cut -b4-`
+        printf '%s\n' "DEVICE=$eth" ONBOOT=yes "BRIDGE=$BRIDGE" \
+          > /etc/sysconfig/network-scripts/ifcfg-$eth
+        printf '%s\n' "DEVICE=$BRIDGE" BOOTPROTO=dhcp \
+            ONBOOT=yes TYPE=Bridge PEERNTP=yes \
+          > /etc/sysconfig/network-scripts/ifcfg-$BRIDGE
+    done
+}
 
-        # find all of the ethernet devices in the system
-        ETHDEVS=$(cd /sys/class/net && ls -d eth*)
-        for eth in $ETHDEVS; do
-            BRIDGE=ovirtbr`echo $eth | cut -b4-`
-            printf '%s\n' "DEVICE=$eth" ONBOOT=yes "BRIDGE=$BRIDGE" \
-	      > /etc/sysconfig/network-scripts/ifcfg-$eth
-            printf '%s\n' "DEVICE=$BRIDGE" BOOTPROTO=dhcp \
-                ONBOOT=yes TYPE=Bridge PEERNTP=yes \
-              > /etc/sysconfig/network-scripts/ifcfg-$BRIDGE
+start() {
+        # find boot interface from cmdline
+        # IPAPPEND 2 in pxelinux.cfg appends e.g. BOOTIF=01-00-16-3e-12-34-57
+        BOOTIF=
+        for i in $(cat /proc/cmdline); do
+            case $i in
+                BOOTIF=*)
+                    BOOTMAC=$(echo $i | cut -d- -f2- | sed 's/-/:/g')
+                    BOOTIF=$(grep -l $BOOTMAC /sys/class/net/eth*/address|rev|cut -d/ -f2|rev)
+                    ;;
+            esac
         done
+        configure_from_network $BOOTIF
 
         # find all of the partitions on the system
 
diff --git a/ovirt-host-creator/ovirt-pxe.sh b/ovirt-host-creator/ovirt-pxe.sh
index 632ec5d..a586e87 100755
--- a/ovirt-host-creator/ovirt-pxe.sh
+++ b/ovirt-host-creator/ovirt-pxe.sh
@@ -31,3 +31,11 @@ fi
 ISO=`create_iso $ISO` || exit 1
 
 livecd-iso-to-pxeboot $ISO
+
+# append BOOTIF with PXE MAC info
+grep -q 'IPAPPEND 2' tftpboot/pxelinux.cfg/default
+found=$?
+if [ $found -ne 0 ]; then
+    sed -i -e '/KERNEL/a \ \tIPAPPEND 2' tftpboot/pxelinux.cfg/default
+fi
+
diff --git a/wui-appliance/common-post.ks b/wui-appliance/common-post.ks
index 3dee5bb..67a885b 100644
--- a/wui-appliance/common-post.ks
+++ b/wui-appliance/common-post.ks
@@ -69,3 +69,19 @@ baseurl=http://ovirt.et.redhat.com/repos/ovirt-management-repo/$basearch/
 enabled=1
 gpgcheck=0
 EOF
+
+# XXX default configuration db
+cat > /var/www/html/ovirt-cfgdb << \EOF
+rm /files/etc/sysconfig/network-scripts/ifcfg-eth0
+set /files/etc/sysconfig/network-scripts/ifcfg-eth0/DEVICE eth0
+set /files/etc/sysconfig/network-scripts/ifcfg-eth0/ONBOOT yes
+set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BRIDGE ovirtbr0
+rm /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0
+set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/DEVICE ovirtbr0
+set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/BOOTPROTO dhcp
+set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/ONBOOT y
+set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/TYPE Bridge
+set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/PEERNTP yes
+save
+EOF
+
diff --git a/wui/conf/ovirt-wui.conf b/wui/conf/ovirt-wui.conf
index 3e7115a..022e6e4 100644
--- a/wui/conf/ovirt-wui.conf
+++ b/wui/conf/ovirt-wui.conf
@@ -46,4 +46,6 @@ ProxyPassReverse /ovirt/images !
 ProxyPassReverse /ovirt/stylesheets !
 ProxyPassReverse /ovirt/errors !
 
+# XXX default configuration db, all hosts get the same config
+RewriteRule   ^/ovirt/cfgdb  /var/www/html/ovirt-cfgdb
 </VirtualHost>




More information about the ovirt-devel mailing list