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

Darryl L. Pierce dpierce at redhat.com
Mon Nov 17 15:28:39 UTC 2008


If ovirt-config-network is called as follows:

ovirt-config-network AUTO

where NIC is the management interface to be configured.

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

This patch also incorporates changes to move configuration files into
a temporary folder and to ensure that directory is deleted.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 scripts/ovirt-config-networking |  103 ++++++++++++++++++++++++---------------
 scripts/ovirt-firstboot         |   11 ++++-
 2 files changed, 74 insertions(+), 40 deletions(-)

diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
index 2f8363c..4ad8af0 100755
--- a/scripts/ovirt-config-networking
+++ b/scripts/ovirt-config-networking
@@ -3,15 +3,27 @@
 # Iterates over the list of network devices on the node and prompts the user
 # to configure each.
 
+WORKDIR=$(mktemp -d) || exit 1
+
+# Remove $WORKDIR upon interrupt (and HUP, PIPE, TERM) and upon normal
+# termination, being careful not to change the exit status.
+trap '__st=$?; rm -rf "$WORKDIR"; exit $__st' 0
+trap 'exit $?' 1 2 13 15
+
 CONFIG_FILE_ROOT="/file/etc/sysconfig/network-scripts/ifcfg"
 CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log"
 
 function configure_interface
 {
     NIC=$1
+    AUTO=$2
+    IPADDR=$OVIRT_IP_ADDRESS
+    NETMASK=$OVIRT_IP_NETMASK
+    GATEWAY=$OVIRT_IP_GATEWAY
+
     BRIDGE=ovirtbr`echo $NIC | cut -b4-`
-    IF_FILENAME="/var/tmp/augtool-$NIC"
-    BR_FILENAME="/var/tmp/augtool-$BRIDGE"
+    IF_FILENAME="$WORKDIR/augtool-$NIC"
+    BR_FILENAME="$WORKDIR/augtool-$BRIDGE"
 
     printf "\nConfigure $BRIDGE for use by $NIC..\n\n"
 
@@ -27,25 +39,35 @@ 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   Gateway: "; read; GATEWAY=$REPLY
+
+                    printf "\nPlease review the details for $BRIDGE:\n"
+                    printf "\tIP Address: $IPADDR\n \t   Netmask: $NETMASK\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"
-                        BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BROADCAST $BROADCAST"
                         BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/NETMASK $NETMASK"
                         break
                         ;;
@@ -66,32 +88,35 @@ function configure_interface
 function setup_menu
 {
     NICS=$(hal-device | awk '/net.interface/ {match($0, "= '"'"'(.*)'"'"' ", nic); printf("%s ", nic[1]); }')
-    NICS="$NICS Quit"
+    NICS="$NICS Save Quit"
     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-*
-
-setup_menu
-
-select NIC in $NICS
-do
-    printf "\n"
-    case "$NIC" in
-        "Quit") break ;;
-        *) configure_interface $NIC $IFACE_NUMBER ;;
-    esac
+if [ "$1" == "AUTO" ]; then
+    configure_interface $OVIRT_MGMT_IFACE AUTO
+    RESTART="Y"
+else
     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
+            "Save") RESTART="Y"; break ;;
+            "Quit") exit 0; break ;;
+            *) configure_interface $NIC $IFACE_NUMBER ;;
+        esac
+        setup_menu
+    done
+fi
+
+if [ "$RESTART" == "Y" ]; then
+    {
+    printf "Configuring network.\n"
+    config="$WORKDIR"/config-augtool
+    printf "config=$config\n"
+    { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \
+    && augtool < $config  \
+    && service network restart
+    } >> $CONFIG_LOG_FILE 2>> $CONFIG_LOG_FILE
+fi
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index 82d9e48..ed4ad2d 100755
--- a/scripts/ovirt-firstboot
+++ b/scripts/ovirt-firstboot
@@ -29,7 +29,16 @@
 
 start ()
 {
-    ovirt-config-setup
+    INTERACTIVE="Y"
+
+    if [ -n "$OVIRT_MGMT_IFACE" ]; then
+        INTERACTIVE="N"
+        ovirt-config-networking AUTO
+    fi
+
+    if [ "$INTERACTIVE" == "Y" ]; then
+        ovirt-config-setup
+    fi
 }
 
 case "$1" in
-- 
1.5.6.5




More information about the ovirt-devel mailing list