[Ovirt-devel] [PATCH node] Adds automatic non-interactive configuration for the standalone node.

Darryl L. Pierce dpierce at redhat.com
Fri Nov 14 18:47:12 UTC 2008


If ovirt-config-network is called as follows:

ovirt-config-network AUTO  [NIC] [IP NETMASK GATEWAY BROADCAST]

where NIC is the management interface to be configured.

If the IP details are provided then they are used to configure the device.
Otherwise DHCP will be used.

The kernel arguments are:
 * OVIRT_MGMT_IFACE:   the management network interface name
 * OVIRT_IP_ADDRESS:   the IP address
 * OVIRT_IP_NETMASK:   the netmask
 * OVIRT_IP_GATEWAY:   the network gateway
 * OVIRT_IP_BROADCAST: the network broadcast address

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 scripts/ovirt-config-networking |   91 +++++++++++++++++++++++++--------------
 scripts/ovirt-firstboot         |   12 +++++-
 2 files changed, 69 insertions(+), 34 deletions(-)

diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
index 2f8363c..f8ff1a6 100755
--- a/scripts/ovirt-config-networking
+++ b/scripts/ovirt-config-networking
@@ -4,11 +4,17 @@
 # to configure each.
 
 CONFIG_FILE_ROOT="/file/etc/sysconfig/network-scripts/ifcfg"
-CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log"
+# CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log"
+CONFIG_LOG_FILE="ovirt-network-setup.log"
 
 function configure_interface
 {
     NIC=$1
+    AUTO=$2
+    IPADDR=$3
+    NETMASK=$4
+    GATEWAY=$5
+    BROADCAST=$6
     BRIDGE=ovirtbr`echo $NIC | cut -b4-`
     IF_FILENAME="/var/tmp/augtool-$NIC"
     BR_FILENAME="/var/tmp/augtool-$BRIDGE"
@@ -27,21 +33,33 @@ function configure_interface
 
     # how do you want to configure this device? (dhcp, static IP)
     while true; do
-        printf "Will $BRIDGE use dynamic addressing? (Y/N) "
-        read
+        if [ -z "$AUTO" ]; then
+            read -p "Will $BRIDGE use dynamic addressing? (Y/N) "
+        else
+            if [ -z "$IPADDR" ]; then
+                REPLY="Y"
+            else
+                REPLY="N"
+            fi
+        fi
+
         case $REPLY in
             Y|y) BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp"; break ;;
             N|n)
-                printf "\nPlease enter the network details for $BRIDGE:\n"
-                printf "\tIP Address: "; read; IPADDR=$REPLY
-                printf "\t   Netmask: "; read; NETMASK=$REPLY
-                printf "\t Broadcast: "; read; BROADCAST=$REPLY
-                printf "\t   Gateway: "; read; GATEWAY=$REPLY
-
-                printf "\nPlease review the details for $BRIDGE:\n"
-                printf "\tIP Address: $IPADDR\n \t   Netmask: $NETMASK\n\t Broadcast: $BROADCAST\n\t   Gateway: $GATEWAY\n"
-                printf "Is this correct? (Y/N) "
-                read
+                if [ -z "$IPADDR" ]; then
+                    printf "\nPlease enter the network details for $BRIDGE:\n"
+                    printf "\tIP Address: "; read; IPADDR=$REPLY
+                    printf "\t   Netmask: "; read; NETMASK=$REPLY
+                    printf "\t Broadcast: "; read; BROADCAST=$REPLY
+                    printf "\t   Gateway: "; read; GATEWAY=$REPLY
+
+                    printf "\nPlease review the details for $BRIDGE:\n"
+                    printf "\tIP Address: $IPADDR\n \t   Netmask: $NETMASK\n\t Broadcast: $BROADCAST\n\t   Gateway: $GATEWAY\n"
+                    read -p "Is this correct? (Y/N) "
+                else
+                    REPLY="Y"
+                fi
+
                 case $REPLY in
                     Y|y)
                         BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPADDR $IPADDR"
@@ -70,28 +88,35 @@ function setup_menu
     PS3="Please select a network interface to configure:"
 }
 
-# clean up any left over configurations
-rm -f /var/tmp/config-augtool
-rm -f /var/tmp/augtool-*
+if [ "$1" == "AUTO" ]; then
+    configure_interface $2 AUTO $3 $4 $5 $6
+    RESTART="Y"
+else
 
-setup_menu
+    # clean up any left over configurations
+    rm -f /var/tmp/config-augtool
+    rm -f /var/tmp/augtool-*
 
-select NIC in $NICS
-do
-    printf "\n"
-    case "$NIC" in
-        "Quit") break ;;
-        *) configure_interface $NIC $IFACE_NUMBER ;;
-    esac
     setup_menu
-done
-
-# Merge together all generated files and run augtool
 
-cat /var/tmp/augtool-* > /var/tmp/config-augtool
-printf "save\n" >> /var/tmp/config-augtool
-{
-augtool < /var/tmp/config-augtool
-service network restart
-} > $CONFIG_LOG_FILE 2>> $CONFIG_LOG_FILE
+    select NIC in $NICS
+    do
+        printf "\n"
+        case "$NIC" in
+            "Quit") RESTART="Y"; break ;;
+            *) configure_interface $NIC $IFACE_NUMBER ;;
+        esac
+        setup_menu
+    done
 
+fi
+
+if [ "$RESTART" == "Y" ]; then
+    # Merge together all generated files and run augtool
+    cat /var/tmp/augtool-* > /var/tmp/config-augtool
+    printf "save\n" >> /var/tmp/config-augtool
+    {
+    augtool < /var/tmp/config-augtool
+    service network restart
+    } > $CONFIG_LOG_FILE 2>> $CONFIG_LOG_FILE
+fi
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index 82d9e48..6eaf8b6 100755
--- a/scripts/ovirt-firstboot
+++ b/scripts/ovirt-firstboot
@@ -29,7 +29,17 @@
 
 start ()
 {
-    ovirt-config-setup
+    INTERACTIVE="Y"
+
+    if [ -n "$OVIRT_MGMT_IFACE" ]; then
+        INTERACTIVE="N"
+       ./ovirt-config-networking AUTO $OVIRT_MGMT_IFACE\
+             $OVIRT_IP_ADDRESS $OVIRT_IP_NETMASK $OVIRT_IP_GATEWAY $OVIRT_IP_BROADCAST
+    fi
+
+    if [ "$INTERACTIVE" == "Y" ]; then
+        ovirt-config-setup
+    fi
 }
 
 case "$1" in
-- 
1.5.6.5




More information about the ovirt-devel mailing list