[Ovirt-devel] [PATCH node] Enabled automated network configuration via kernel arguments.

Darryl L. Pierce dpierce at redhat.com
Tue Nov 18 18:02:20 UTC 2008


This patch removes unnecessary kernel argument dependencies and adds support for IPv6.

If supplied, the user can set the IP address, netmask and gateway for
this interface using the OVIRT_IP_ADDRESS, OVIRT_IP_NETMASK and
OVIRT_IP_GATEWAY respectively. If all of these options are not provided
then DHCP is assumed.

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

diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
index 4ad8af0..15c09de 100755
--- a/scripts/ovirt-config-networking
+++ b/scripts/ovirt-config-networking
@@ -3,6 +3,10 @@
 # Iterates over the list of network devices on the node and prompts the user
 # to configure each.
 
+ME=$(basename "$0")
+warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
+die() { warn "$*"; exit 1; }
+
 WORKDIR=$(mktemp -d) || exit 1
 
 # Remove $WORKDIR upon interrupt (and HUP, PIPE, TERM) and upon normal
@@ -17,11 +21,15 @@ 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 [[   "$AUTO" == "AUTO"    &&
+         -n "$OVIRT_IP_ADDRESS" ]]; then
+        IPADDR=$OVIRT_IP_ADDRESS
+        NETMASK=$OVIRT_IP_NETMASK
+        GATEWAY=$OVIRT_IP_GATEWAY
+        PREFIX=$OVIRT_IP_PREFIX
+    fi
+
+    BRIDGE=ovirtbr$NIC
     IF_FILENAME="$WORKDIR/augtool-$NIC"
     BR_FILENAME="$WORKDIR/augtool-$BRIDGE"
 
@@ -40,6 +48,21 @@ function configure_interface
     # how do you want to configure this device? (dhcp, static IP)
     while true; do
         if [ -z "$AUTO" ]; then
+            IPADDR=
+            NETMASK=
+            GATEWAY=
+            IPTYPE=
+
+            IPTYPES="IPv4 IPv6 Abort"
+            PS3="What type of network will be used? "
+            select TYPE in $IPTYPES
+            do
+                case "$TYPE" in
+                    "Abort") return ;;
+                    *) IPTYPE=$TYPE; break ;;
+                esac
+            done
+
             read -p "Will $BRIDGE use dynamic addressing? (Y/N) "
         else
             if [ -z "$IPADDR" ]; then
@@ -50,27 +73,65 @@ function configure_interface
         fi
 
         case $REPLY in
-            Y|y) BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp"; break ;;
+            Y|y)
+                if [ "$IPTYPE" == "IPv4" ]; then
+                    BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp"
+                else
+                    BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF yes"
+                    BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_FORWARDING no"
+                    BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_INIT yes"
+                fi
+
+                break ;;
             N|n)
                 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
+
+                    if [ "$IPTYPE" == "IPv4" ]; then
+                        printf "\tIP Address: "; read; IPADDR=$REPLY
+                        printf "\t   Netmask: "; read; NETMASK=$REPLY
+                        printf "\t   Gateway: "; read; GATEWAY=$REPLY
+                    else
+                        printf "\tIP Address: "; read; IPADDR=$REPLY
+                    fi
 
                     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) "
+                    if [ "$IPTYPE" == "IPv4" ]; then
+                        printf '\t%s\n'\
+                               "IP Address: $IPADDR"\
+                               "   Netmask: $NETMASK"\
+                               "   Gateway: $GATEWAY"
+                    else
+                        printf '\t%s\n'\
+                               "IP Address: $IPADDR"
+                    fi
+                    read -p "Is this correct? (Y/N/A) "
                 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/NETMASK $NETMASK"
+                        BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO none"
+                        case "$IPTYPE" in
+                            "IPv4")
+                                BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPADDR $IPADDR"
+                                BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/NETMASK $NETMASK"
+                                BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/GATEWAY $GATEWAY"
+                                break
+                                ;;
+
+                            "IPv6")
+                                BR_CONFIG="$BR_COFNIG\nset $BR_ROOT/IPV6INIT=yes"
+                                BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6ADDR $IPADDR"
+                                BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTCONF=no"
+                                BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_FORWARDING=no"
+                                break
+                                ;;
+                        esac
                         break
                         ;;
+                    A|a) return ;;
                 esac
                 ;;
         esac
@@ -89,11 +150,12 @@ function setup_menu
 {
     NICS=$(hal-device | awk '/net.interface/ {match($0, "= '"'"'(.*)'"'"' ", nic); printf("%s ", nic[1]); }')
     NICS="$NICS Save Quit"
-    PS3="Please select a network interface to configure:"
+    PS3="Please select a network interface to configure: "
 }
 
 if [ "$1" == "AUTO" ]; then
-    configure_interface $OVIRT_MGMT_IFACE AUTO
+    if [ -n "$OVIRT_IPV6" ]; then IPTYPE="IPv6"; else IPTYPE="IPv4"; fi
+    configure_interface $OVIRT_BOOTIF AUTO
     RESTART="Y"
 else
     setup_menu
@@ -118,5 +180,5 @@ if [ "$RESTART" == "Y" ]; then
     { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \
     && augtool < $config  \
     && service network restart
-    } >> $CONFIG_LOG_FILE 2>> $CONFIG_LOG_FILE
+    } >> $CONFIG_LOG_FILE 2>&1
 fi
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index ed4ad2d..82d9e48 100755
--- a/scripts/ovirt-firstboot
+++ b/scripts/ovirt-firstboot
@@ -29,16 +29,7 @@
 
 start ()
 {
-    INTERACTIVE="Y"
-
-    if [ -n "$OVIRT_MGMT_IFACE" ]; then
-        INTERACTIVE="N"
-        ovirt-config-networking AUTO
-    fi
-
-    if [ "$INTERACTIVE" == "Y" ]; then
-        ovirt-config-setup
-    fi
+    ovirt-config-setup
 }
 
 case "$1" in
-- 
1.5.6.5




More information about the ovirt-devel mailing list