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

Alan Pevec apevec at redhat.com
Mon Nov 17 12:08:50 UTC 2008


From: Darryl L. Pierce <dpierce at redhat.com>

NOTE: rebased to apply after:
    Moved network configuration work files to a temporary directory.
    Adds a "Save" option to save the configuration.

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 |   84 +++++++++++++++++++++++++--------------
 scripts/ovirt-firstboot         |   12 +++++-
 2 files changed, 65 insertions(+), 31 deletions(-)

diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
index 2ac3970..0d359a6 100755
--- a/scripts/ovirt-config-networking
+++ b/scripts/ovirt-config-networking
@@ -16,6 +16,11 @@ CONFIG_LOG_FILE="/var/log/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="$WORKDIR/augtool-$NIC"
     BR_FILENAME="$WORKDIR/augtool-$BRIDGE"
@@ -34,21 +39,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"
@@ -77,25 +94,32 @@ function setup_menu
     PS3="Please select a network interface to configure:"
 }
 
-setup_menu
+if [ "$1" == "AUTO" ]; then
+    configure_interface $2 AUTO $3 $4 $5 $6
+    RESTART="Y"
+else
 
-select NIC in $NICS
-do
-    printf "\n"
-    case "$NIC" in
-        "Save") break ;;
-        "Quit") exit 0 ;;
-        *) configure_interface $NIC $IFACE_NUMBER ;;
-    esac
     setup_menu
-done
-
-# Merge together all generated files and run augtool
 
-{
-config="$WORKDIR"/config-augtool
-{ cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \
-&& augtool < "$WORKDIR"/config-augtool
+    select NIC in $NICS
+    do
+        printf "\n"
+        case "$NIC" in
+            "Save") RESTART="Y"; break ;;
+            "Quit") break ;;
+            *) configure_interface $NIC $IFACE_NUMBER ;;
+        esac
+        setup_menu
+    done
 
-service network restart
-} > $CONFIG_LOG_FILE 2>> $CONFIG_LOG_FILE
+fi
+
+if [ "$RESTART" == "Y" ]; then
+    # Merge together all generated files and run augtool
+    {
+    config="$WORKDIR"/config-augtool
+    { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \
+    && augtool < "$WORKDIR"/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