Darryl L. Pierce
2008-Sep-18 17:47 UTC
[Ovirt-devel] [PATCH node] The node now passes in the mac address and iface names during identify.
From: Darryl Pierce <mcpierce at threshold.(none)> This works with the patch for the server the generates a configuration file for the node based on the interface names passed in with each mac address. Additionally, the node will pull down the configuration and process it as a script. Since the configuration will be composed of two separate parts: 1. a script to load one or more kernel modules 2. a configuration file to pass to augtool The script is downloaded to a temp directory and then passed to bash. If either of the two expected files is produced then it is further processed to configure the node. Signed-off-by: Darryl Pierce <dpierce at redhat.com> Signed-off-by: Darryl Pierce <mcpierce at mcpierce-laptop.(none)> --- ovirt-identify-node/gather.c | 1 + scripts/ovirt-early | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ovirt-identify-node/gather.c b/ovirt-identify-node/gather.c index 633d16e..9722e19 100644 --- a/ovirt-identify-node/gather.c +++ b/ovirt-identify-node/gather.c @@ -210,6 +210,7 @@ get_nic_data(char *nic, nic_info_ptr nic_info_p) libhal_device_get_property_string(hal_ctx, nic, "net.interface", &dbus_error); snprintf(nic_info_p->iface_name, BUFFER_LENGTH, "%s", interface); + bzero(&ifr, sizeof(struct ifreq)); sockfd = socket(AF_INET, SOCK_DGRAM, 0); diff --git a/scripts/ovirt-early b/scripts/ovirt-early index 8024b3b..0379946 100755 --- a/scripts/ovirt-early +++ b/scripts/ovirt-early @@ -13,6 +13,12 @@ # size of the oVirt partition in megabytes OVIRT_SIZE=64 +get_mac_addresses() { + macs=[`/sbin/ifconfig | awk '/HWaddr/ { print $5"="$1 }'`] + macs=`echo $macs | sed 's/ /%2C/g'` + macs=`echo $macs | sed 's/\:/%3A/g'` +} + configure_from_network() { DEVICE=$1 if [ -n "$DEVICE" ]; then @@ -31,12 +37,19 @@ configure_from_network() { if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then printf . cfgdb=$(mktemp) + get_mac_addresses wget -q -O $cfgdb \ - "http://$SRV_HOST:$SRV_PORT/ovirt/cfgdb/$(hostname)" + "http://$SRV_HOST:$SRV_PORT/ovirt/managed_node/config?host=$(hostname)&$macs" if [ $? -eq 0 ]; then printf . - echo "save" >> $cfgdb - augtool < $cfgdb > /dev/null 2>&1 + bash $cfgdb + if [ -f /var/tmp/pre-config-script ]; then + printf "loading kernel modules" + bash /var/tmp/pre-config-script > /dev/null 2>&1 + fi + if [ -f /var/tmp/node-augtool ]; then + augtool < /var/tmp/node-augtool > /dev/null 2>&1 + fi if [ $? -eq 0 ]; then printf "remote config applied." return -- 1.5.5.1
Jim Meyering
2008-Sep-18 21:32 UTC
[Ovirt-devel] [PATCH node] The node now passes in the mac address and iface names during identify.
"Darryl L. Pierce" <dpierce at redhat.com> wrote:> From: Darryl Pierce <mcpierce at threshold.(none)> > This works with the patch for the server the generates a configuration file > for the node based on the interface names passed in with each mac address.... Hi Darryl, Here are a couple of defensive fixes and two questions:> diff --git a/ovirt-identify-node/gather.c b/ovirt-identify-node/gather.c > index 633d16e..9722e19 100644 > --- a/ovirt-identify-node/gather.c > +++ b/ovirt-identify-node/gather.c > @@ -210,6 +210,7 @@ get_nic_data(char *nic, nic_info_ptr nic_info_p) > libhal_device_get_property_string(hal_ctx, nic, "net.interface", > &dbus_error); > snprintf(nic_info_p->iface_name, BUFFER_LENGTH, "%s", interface); > +It'd be good not to add the blank line, since that's the only change to this file.> bzero(&ifr, sizeof(struct ifreq)); > > sockfd = socket(AF_INET, SOCK_DGRAM, 0); > diff --git a/scripts/ovirt-early b/scripts/ovirt-early > index 8024b3b..0379946 100755 > --- a/scripts/ovirt-early > +++ b/scripts/ovirt-early > @@ -13,6 +13,12 @@ > # size of the oVirt partition in megabytes > OVIRT_SIZE=64 > > +get_mac_addresses() { > + macs=[`/sbin/ifconfig | awk '/HWaddr/ { print $5"="$1 }'`] > + macs=`echo $macs | sed 's/ /%2C/g'` > + macs=`echo $macs | sed 's/\:/%3A/g'`This is fragile, since if there exist matching single-byte file names like %, C, or hexadecimal numbers, then $macs will end up looking not like you want, but just "0 A", since the square brackets make the shell do filename globbing. This should be equivalent but not susceptible, and forks two fewer subshells (and no need to backslash-escape ":"): macs=$(ifconfig | awk '/HWaddr/ { print $5"="$1 }' \ | tr '\n' ' ' | sed 's/ /%2C/g;s/:/%3A/g') macs="[$macs]" Also, it's ok to omit /sbin/, since ovirt-early sources /etc/init.d/functions, which sets PATH.> +} > + > configure_from_network() { > DEVICE=$1 > if [ -n "$DEVICE" ]; then > @@ -31,12 +37,19 @@ configure_from_network() { > if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then > printf . > cfgdb=$(mktemp) > + get_mac_addresses > wget -q -O $cfgdb \ > - "http://$SRV_HOST:$SRV_PORT/ovirt/cfgdb/$(hostname)" > + "http://$SRV_HOST:$SRV_PORT/ovirt/managed_node/config?host=$(hostname)&$macs" > if [ $? -eq 0 ]; then > printf . > - echo "save" >> $cfgdb > - augtool < $cfgdb > /dev/null 2>&1 > + bash $cfgdbNot officially required, but good to be defensive and add double quotes, in case TMPDIR (from which mktemp derives its name) ever contains something bogus: bash "$cfgdb"> + if [ -f /var/tmp/pre-config-script ]; then > + printf "loading kernel modules" > + bash /var/tmp/pre-config-script > /dev/null 2>&1 > + fiWhat output and diagnostics does the script print that should always be ignored?> + if [ -f /var/tmp/node-augtool ]; then > + augtool < /var/tmp/node-augtool > /dev/null 2>&1Same question here, for augtool.> + fi > if [ $? -eq 0 ]; then > printf "remote config applied." > return
Darryl L. Pierce
2008-Sep-19 20:35 UTC
[Ovirt-devel] [PATCH node] The node now passes in the mac address and iface names during identify.
This works with the patch for the server the generates a configuration file for the node based on the interface names passed in with each mac address. Additionally, the node will pull down the configuration and process it as a script. Since the configuration will be composed of two separate parts: 1. a script to load one or more kernel modules 2. a configuration file to pass to augtool The script is downloaded to a temp directory and then passed to bash. If either of the two expected files is produced then it is further processed to configure the node. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-early | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/ovirt-early b/scripts/ovirt-early index 8024b3b..f890f9a 100755 --- a/scripts/ovirt-early +++ b/scripts/ovirt-early @@ -13,6 +13,11 @@ # size of the oVirt partition in megabytes OVIRT_SIZE=64 +get_mac_addresses() { + macs=$(ifconfig | awk '/HWaddr/ { print $5"="$1 }' \ + | tr '\n' ' ' | sed 's/ /%2C/g;s/:/%3A/g') +} + configure_from_network() { DEVICE=$1 if [ -n "$DEVICE" ]; then @@ -31,12 +36,19 @@ configure_from_network() { if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then printf . cfgdb=$(mktemp) + get_mac_addresses wget -q -O $cfgdb \ - "http://$SRV_HOST:$SRV_PORT/ovirt/cfgdb/$(hostname)" + "http://$SRV_HOST:$SRV_PORT/ovirt/managed_node/config?host=$(hostname)&macs=$macs" if [ $? -eq 0 ]; then printf . - echo "save" >> $cfgdb - augtool < $cfgdb > /dev/null 2>&1 + bash $cfgdb + if [ -f /var/tmp/pre-config-script ]; then + printf "loading kernel modules" + bash /var/tmp/pre-config-script + fi + if [ -f /var/tmp/node-augtool ]; then + augtool < /var/tmp/node-augtool + fi if [ $? -eq 0 ]; then printf "remote config applied." return -- 1.5.5.1