Alan Pevec
2008-Apr-24 23:34 UTC
[Ovirt-devel] [PATCH] get host networking configuration from ovirt server
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 4bd00e3..89a1796 100644 --- a/ovirt-host-creator/common-pkgs.ks +++ b/ovirt-host-creator/common-pkgs.ks @@ -21,6 +21,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 03ac4ae..a8f67d5 100644 --- a/ovirt-host-creator/common-post.ks +++ b/ovirt-host-creator/common-post.ks @@ -40,18 +40,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 $(/bin/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-` + echo -e "DEVICE=$eth\nONBOOT=yes\nBRIDGE=$BRIDGE" \ + > /etc/sysconfig/network-scripts/ifcfg-$eth + echo -e "DEVICE=$BRIDGE\nBOOTPROTO=dhcp\nONBOOT=yes\nTYPE=Bridge\nPEERNTP=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-` - echo -e "DEVICE=$eth\nONBOOT=yes\nBRIDGE=$BRIDGE" \ - > /etc/sysconfig/network-scripts/ifcfg-$eth - echo -e "DEVICE=$BRIDGE\nBOOTPROTO=dhcp\nONBOOT=yes\nTYPE=Bridge\nPEERNTP=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 2ed107a..43796aa 100755 --- a/ovirt-host-creator/ovirt-pxe.sh +++ b/ovirt-host-creator/ovirt-pxe.sh @@ -37,4 +37,10 @@ sed -i -e 's/\<console=[a-zA-Z0-9,]*//g' \ -e 's/\<APPEND.*/& console=tty console=ttyS0,115200/' \ -e 's/[ \t]\{2,\}/ /g' \ tftpboot/pxelinux.cfg/default +# 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 3bd6b4d..f3da6bd 100644 --- a/wui-appliance/common-post.ks +++ b/wui-appliance/common-post.ks @@ -66,3 +66,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>
Alan Pevec
2008-May-06 21:54 UTC
[Ovirt-devel] Rebased - [PATCH] get host networking configuration from ovirt server
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>
Jim Meyering
2008-May-08 13:40 UTC
[Ovirt-devel] Rebased - [PATCH] get host networking configuration from ovirt server
Alan Pevec <apevec at redhat.com> wrote:> 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.htmlHi Alan, Looks good. Though something (your mail client?) mangled the patch, removing leading spaces -- that makes it so it doesn't apply. Here are a few comments:> 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 ]; thenIf $DEVICE may somehow expand to a "test" option, like -z, -f, -lt, etc. then the above will malfunction. Add quotes and use -n to be safe: if [ -n "$DEVICE" ]; then> + echo -n "."No need for double quotes. Prefer printf (besides, it's one byte shorter ;-) printf .> + # 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 }')I suppose this sets LANG=C to avoid internationalized output from "ip"? LC_ALL=C is preferable for that, since it trumps LANG.> + 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) \Add double quotes and -n, just in case $SRV_HOST and $SRV_PORT might ever be bogus (so reviewers can be lazy and not have to ensure -- or assume -- that find_srv or whatever else sets those variables does the right thing: if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then curl -s "http://$SRV_HOST:$SRV_PORT/ovirt/cfgdb/$(hostname)" \> + | augtool > /dev/null 2>&1...> +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')this could be a little more strict on the input: BOOTIF=??-??-??-??-??-??-??) this can drop the use of cut (i.e. save a pipe): BOOTMAC=$(echo $i | sed 's/^BOOTIF=..-//;s/-/:/g') [actually, you could remove sed, too, and do it all in the shell, assuming you don't mind using a bash'ism (but this is too opaque, imho): i=${i/#BOOTIF=??-/} BOOTMAC=${i//-/:}> + 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 > +fiThis should be equivalent, and hopefully more readable: [dropped sed's -e, and removed the space-before-TAB] f=tftpboot/pxelinux.cfg/default grep -q 'IPAPPEND 2' $f || sed -i '/KERNEL/a \tIPAPPEND 2' $f