Darryl L. Pierce
2008-Nov-18 16:12 UTC
[Ovirt-devel] [PATCH node] Enabled automated network configuration via kernel arguments.
PUSH CANDIDATE: This patch has reworked so that it handles both automated and interactive scenarios. It also contains a fix for a weird situation where, during interactive mode, the user could get into a state where they couldn't configure a device even after selecting it. To invoke automatic network configuration, the user must specify the interface to configure using the OVIRT_MGMT_IFACE kernel argument. The value for this argument is the interface name for the network device to be configured. 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 | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 4ad8af0..bfe35f2 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,16 @@ 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" && + -n "$OVIRT_IP_NETMASK" && + -n "$OVIRT_IP_GATEWAY" ]]; then + IPADDR=$OVIRT_IP_ADDRESS + NETMASK=$OVIRT_IP_NETMASK + GATEWAY=$OVIRT_IP_GATEWAY + fi + + BRIDGE=ovirtbr$NIC IF_FILENAME="$WORKDIR/augtool-$NIC" BR_FILENAME="$WORKDIR/augtool-$BRIDGE" @@ -40,6 +49,9 @@ function configure_interface # how do you want to configure this device? (dhcp, static IP) while true; do if [ -z "$AUTO" ]; then + IPADDR+ NETMASK+ GATEWAY read -p "Will $BRIDGE use dynamic addressing? (Y/N) " else if [ -z "$IPADDR" ]; then @@ -59,8 +71,11 @@ function configure_interface 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) " + printf '\t%s\n'\ + "IP Address: $IPADDR"\ + " Netmask: $NETMASK"\ + " Gateway: $GATEWAY" + read -p "Is this correct? (Y/N/A) " else REPLY="Y" fi @@ -71,6 +86,7 @@ function configure_interface BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/NETMASK $NETMASK" break ;; + A|a) return ;; esac ;; esac @@ -118,5 +134,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 -- 1.5.6.5
Darryl L. Pierce
2008-Nov-18 18:02 UTC
[Ovirt-devel] [PATCH node] Enabled automated network configuration via kernel arguments.
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
Darryl L. Pierce
2008-Nov-19 18:29 UTC
[Ovirt-devel] [PATCH node] Enabled automated network configuration via kernel arguments.
To configure IPv4 the user passes the kernel argument OVIRT_IPV4 with one of the following values: dhcp or static. If another value is passed then the script shows an error an exits. If static is passed, then the following kernel arguments are expected: OVIRT_IPV4_ADDRESS, OVIRT_IPV4_NETMASK and OVIRT_IPV4_GATEWAY. To configure IPv6 the user passes the kernel argument OVIRT_IPV6 with one of the following values: auto, dhcp or manual. If another value is passed then the script shows an error and exits. If manual was passwd then the following kernel argument must be passed with a valid value: OVIRT_IPV6_ADDRESS. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-config-networking | 235 +++++++++++++++++++++++++++----------- 1 files changed, 167 insertions(+), 68 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 2f8363c..2f8c5df 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -3,95 +3,194 @@ # 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 +# 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 - BRIDGE=ovirtbr`echo $NIC | cut -b4-` - IF_FILENAME="/var/tmp/augtool-$NIC" - BR_FILENAME="/var/tmp/augtool-$BRIDGE" + local NIC=$1 + local AUTO=$2 + 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 + + local BRIDGE=ovirtbr$NIC + local IF_FILENAME="$WORKDIR/augtool-$NIC" + local BR_FILENAME="$WORKDIR/augtool-$BRIDGE" printf "\nConfigure $BRIDGE for use by $NIC..\n\n" - IF_ROOT="$CONFIG_FILE_ROOT-$NIC" - IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" + local IF_ROOT="$CONFIG_FILE_ROOT-$NIC" + local IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" - BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" - BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" + local BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" + local BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/TYPE bridge" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/PEERNTP yes" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DELAY 0" IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/BRIDGE $BRIDGE" - # how do you want to configure this device? (dhcp, static IP) - while true; do - printf "Will $BRIDGE use dynamic addressing? (Y/N) " - read - 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 - 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" + local BR_CONFIG_BASE=BR_CONFIG + + if [ -z "$AUTO" ]; then + while true; do + printf "\n" + read -p "Enable IPv4 support ([S]tatic IP, [D]HCP, [N]o or [A]bort)? " + case $REPLY in + D|d) + use_ipv4_dhcp + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp" + ;; + S|s) + printf "\n" + read -p "IP Address: "; IPADDR=$REPLY + read -p " Netmask: "; NETMASK=$REPLY + read -p " Gateway: "; GATEWAY=$REPLY + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/BOOTPROTO none" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPADDR $IPADDR" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/NETMASK $NETMASK" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/GATEWAY $GATEWAY" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Enable IPv6 supprt ([S]tatic, [D]HCPv6, A[u]to, [N]o)? " + case $REPLY in + S|s) + read -p "IPv6 Address: "; IPADDR=$REPLY + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IP6ADDR $IPADDR" + ;; + D|d) + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6AUTCONF no" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/DHCPV6C yes" + ;; + U|u) + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6AUTOCONF yes" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Is this correct (Y/N/A)? " + case $REPLY in + Y|y) + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME break - ;; - esac - ;; - esac - done - - IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" - BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" - - printf "$IF_CONFIG\n" > $IF_FILENAME - printf "$BR_CONFIG\n" > $BR_FILENAME - - echo + ;; + N|n) BR_CONFIG=BR_CONFIG_BASE ;; + A|a) return ;; + esac + done + else + if [ -n "$OVIRT_IPV6" ]; then + case "$OVIRT_IPV6" in + "auto") + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6_AUTOCONF yes" + ;; + "dhcp") + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6_AUTCONF no" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/DHCPV6C yes" + ;; + "manual") + if [ -n "$OVIRT_IPV6_ADDRESS" ]; then + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IP6ADDR $OVIRT_IPV6_ADDRESS" + else + die "Missing required argument: OVIRT_IPV6_ADDRESS" + fi + ;; + *) die "Invalid OVIRT_IPV6 value: $OVIRT_IPV6" ;; + esac + fi + + if [ -n "$OVIRT_IPV4" ]; then + case "$OVIRT_IPV4" in + "static") + if [[ -n "$OVIRT_IPV4_ADDRESS" && + -n "$OVIRT_IPV4_NETMASK" && + -n "$OVIRT_IPV4_GATEWAY" ]]; then + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/IPADDR $OVIRT_IPV4_ADDRESS" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/NETMASK $OVIRT_IPV4_NETMASK" + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/GATEWAY $OVIRT_IPV4_GATEWAY" + else + die "Missing IPv4 static address details" + fi + ;; + "dhcp") + BR_CONFIG="$BR_CONFIG\n set $BR_ROOT/BOOTPROTO dhcp" + ;; + *) die "Invalid OVIRT_IPV4 value: $OVIRT_IPV4" ;; + esac + fi + + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME + fi } function setup_menu { NICS=$(hal-device | awk '/net.interface/ {match($0, "= '"'"'(.*)'"'"' ", nic); printf("%s ", nic[1]); }') - NICS="$NICS Quit" - PS3="Please select a network interface to configure:" + 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_BOOTIF 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 + { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \ + && augtool < $config \ + && service network restart + } >> $CONFIG_LOG_FILE 2>&1 +fi -- 1.5.6.5
Darryl L. Pierce
2008-Nov-20 15:41 UTC
[Ovirt-devel] [PATCH node] Enabled automated network configuration via kernel arguments.
To configure IPv6, the OVIRT_IPV6 variable will have one of three values: "dhcp" - Configure stateful automatic addressing, "auto" - Configure stateless automatic addressing, or it can contain an IPv6 address and manual configuration will be performed. If the argument is not present then IPv6 is disabled. IPv4 addressing is assumed, and DHCP will be used, unless the OVIRT_IP_ADDRESS variable contains the value "off". If it contains any other value, then that is assumed to be an IPv4 address. OVIRT_IP_NETMASK and OVIRT_IP_GATEWAY are option and will be used if present and a static IP address were being defined. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-config-networking | 230 +++++++++++++++++++++++++++------------ 1 files changed, 160 insertions(+), 70 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 2f8363c..34eb833 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -3,95 +3,185 @@ # Iterates over the list of network devices on the node and prompts the user # to configure each. -CONFIG_FILE_ROOT="/file/etc/sysconfig/network-scripts/ifcfg" -CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log" +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 +# 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="/files/etc/sysconfig/network-scripts/ifcfg" +#CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log" +CONFIG_LOG_FILE="ovirt-network-setup.log" function configure_interface { - NIC=$1 - BRIDGE=ovirtbr`echo $NIC | cut -b4-` - IF_FILENAME="/var/tmp/augtool-$NIC" - BR_FILENAME="/var/tmp/augtool-$BRIDGE" + local NIC=$1 + local AUTO=$2 + 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 + + local BRIDGE=ovirtbr$NIC + local IF_FILENAME="$WORKDIR/augtool-$NIC" + local BR_FILENAME="$WORKDIR/augtool-$BRIDGE" printf "\nConfigure $BRIDGE for use by $NIC..\n\n" - IF_ROOT="$CONFIG_FILE_ROOT-$NIC" - IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" + local IF_ROOT="$CONFIG_FILE_ROOT-$NIC" + local IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" - BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" - BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" + local BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" + local BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/TYPE bridge" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/PEERNTP yes" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DELAY 0" IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/BRIDGE $BRIDGE" - # how do you want to configure this device? (dhcp, static IP) - while true; do - printf "Will $BRIDGE use dynamic addressing? (Y/N) " - read - 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 - 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" + local BR_CONFIG_BASE=BR_CONFIG + + if [ -z "$AUTO" ]; then + while true; do + printf "\n" + read -p "Enable IPv4 support ([S]tatic IP, [D]HCP, [N]o or [A]bort)? " + case $REPLY in + D|d) + use_ipv4_dhcp + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp" + ;; + S|s) + printf "\n" + read -p "IP Address: "; IPADDR=$REPLY + read -p " Netmask: "; NETMASK=$REPLY + read -p " Gateway: "; GATEWAY=$REPLY + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO none" + 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" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Enable IPv6 supprt ([S]tatic, [D]HCPv6, A[u]to, [N]o)? " + case $REPLY in + S|s) + read -p "IPv6 Address: "; IPADDR=$REPLY + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IP6ADDR $IPADDR" + ;; + D|d) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6AUTCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes" + ;; + U|u) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6AUTOCONF yes" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Is this correct (Y/N/A)? " + case $REPLY in + Y|y) + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME break - ;; - esac - ;; - esac - done - - IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" - BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" - - printf "$IF_CONFIG\n" > $IF_FILENAME - printf "$BR_CONFIG\n" > $BR_FILENAME - - echo + ;; + N|n) BR_CONFIG=BR_CONFIG_BASE ;; + A|a) return ;; + esac + done + else + if [ -n "$OVIRT_IPV6" ]; then + case "$OVIRT_IPV6" in + "auto") + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF yes" + ;; + "dhcp") + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes" + ;; + *) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6ADDR $OVIRT_IPV6" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + esac + fi + + if [ -z "$OVIRT_IP_ADDRESS" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp" + else + if [ "$OVIRT_IP_ADDRESS" != "off" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPADDR $OVIRT_IP_ADDRESS" + if [ -n "$OVIRT_IP_NETMASK" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/NETMASK $OVIRT_IP_NETMASK" + fi + if [ -n "$OVIRT_IP_GATEWAY" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/GATEWAY $OVIRT_IP_GATEWAY" + fi + fi + fi + + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME + fi } function setup_menu { NICS=$(hal-device | awk '/net.interface/ {match($0, "= '"'"'(.*)'"'"' ", nic); printf("%s ", nic[1]); }') - NICS="$NICS Quit" - PS3="Please select a network interface to configure:" + 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_BOOTIF 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 + { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \ + && augtool < $config \ + && service network restart + } >> $CONFIG_LOG_FILE 2>&1 +fi -- 1.5.6.5
Darryl L. Pierce
2008-Nov-20 15:43 UTC
[Ovirt-devel] [PATCH node] Enabled automated network configuration via kernel arguments.
The last patch had debugging code in it. This overrides that. To configure IPv6, the OVIRT_IPV6 variable will have one of three values: "dhcp" - Configure stateful automatic addressing, "auto" - Configure stateless automatic addressing, or it can contain an IPv6 address and manual configuration will be performed. If the argument is not present then IPv6 is disabled. IPv4 addressing is assumed, and DHCP will be used, unless the OVIRT_IP_ADDRESS variable contains the value "off". If it contains any other value, then that is assumed to be an IPv4 address. OVIRT_IP_NETMASK and OVIRT_IP_GATEWAY are option and will be used if present and a static IP address were being defined. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-config-networking | 227 +++++++++++++++++++++++++++------------ 1 files changed, 158 insertions(+), 69 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 2f8363c..8a6a109 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -3,95 +3,184 @@ # Iterates over the list of network devices on the node and prompts the user # to configure each. -CONFIG_FILE_ROOT="/file/etc/sysconfig/network-scripts/ifcfg" +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 +# 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="/files/etc/sysconfig/network-scripts/ifcfg" CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log" function configure_interface { - NIC=$1 - BRIDGE=ovirtbr`echo $NIC | cut -b4-` - IF_FILENAME="/var/tmp/augtool-$NIC" - BR_FILENAME="/var/tmp/augtool-$BRIDGE" + local NIC=$1 + local AUTO=$2 + 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 + + local BRIDGE=ovirtbr$NIC + local IF_FILENAME="$WORKDIR/augtool-$NIC" + local BR_FILENAME="$WORKDIR/augtool-$BRIDGE" printf "\nConfigure $BRIDGE for use by $NIC..\n\n" - IF_ROOT="$CONFIG_FILE_ROOT-$NIC" - IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" + local IF_ROOT="$CONFIG_FILE_ROOT-$NIC" + local IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" - BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" - BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" + local BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" + local BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/TYPE bridge" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/PEERNTP yes" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DELAY 0" IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/BRIDGE $BRIDGE" - # how do you want to configure this device? (dhcp, static IP) - while true; do - printf "Will $BRIDGE use dynamic addressing? (Y/N) " - read - 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 - 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" + local BR_CONFIG_BASE=BR_CONFIG + + if [ -z "$AUTO" ]; then + while true; do + printf "\n" + read -p "Enable IPv4 support ([S]tatic IP, [D]HCP, [N]o or [A]bort)? " + case $REPLY in + D|d) + use_ipv4_dhcp + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp" + ;; + S|s) + printf "\n" + read -p "IP Address: "; IPADDR=$REPLY + read -p " Netmask: "; NETMASK=$REPLY + read -p " Gateway: "; GATEWAY=$REPLY + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO none" + 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" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Enable IPv6 supprt ([S]tatic, [D]HCPv6, A[u]to, [N]o)? " + case $REPLY in + S|s) + read -p "IPv6 Address: "; IPADDR=$REPLY + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IP6ADDR $IPADDR" + ;; + D|d) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6AUTCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes" + ;; + U|u) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6AUTOCONF yes" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Is this correct (Y/N/A)? " + case $REPLY in + Y|y) + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME break - ;; - esac - ;; - esac - done - - IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" - BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" - - printf "$IF_CONFIG\n" > $IF_FILENAME - printf "$BR_CONFIG\n" > $BR_FILENAME - - echo + ;; + N|n) BR_CONFIG=BR_CONFIG_BASE ;; + A|a) return ;; + esac + done + else + if [ -n "$OVIRT_IPV6" ]; then + case "$OVIRT_IPV6" in + "auto") + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF yes" + ;; + "dhcp") + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes" + ;; + *) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6ADDR $OVIRT_IPV6" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + esac + fi + + if [ -z "$OVIRT_IP_ADDRESS" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp" + else + if [ "$OVIRT_IP_ADDRESS" != "off" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPADDR $OVIRT_IP_ADDRESS" + if [ -n "$OVIRT_IP_NETMASK" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/NETMASK $OVIRT_IP_NETMASK" + fi + if [ -n "$OVIRT_IP_GATEWAY" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/GATEWAY $OVIRT_IP_GATEWAY" + fi + fi + fi + + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME + fi } function setup_menu { NICS=$(hal-device | awk '/net.interface/ {match($0, "= '"'"'(.*)'"'"' ", nic); printf("%s ", nic[1]); }') - NICS="$NICS Quit" - PS3="Please select a network interface to configure:" + 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_BOOTIF 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 + { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \ + && augtool < $config \ + && service network restart + } >> $CONFIG_LOG_FILE 2>&1 +fi -- 1.5.6.5
Darryl L. Pierce
2008-Nov-20 17:10 UTC
[Ovirt-devel] [PATCH node] Enabled automated network configuration via kernel arguments.
Removed a vestigial method call. To configure IPv6, the OVIRT_IPV6 variable will have one of three values: "dhcp" - Configure stateful automatic addressing, "auto" - Configure stateless automatic addressing, or it can contain an IPv6 address and manual configuration will be performed. If the argument is not present then IPv6 is disabled. IPv4 addressing is assumed, and DHCP will be used, unless the OVIRT_IP_ADDRESS variable contains the value "off". If it contains any other value, then that is assumed to be an IPv4 address. OVIRT_IP_NETMASK and OVIRT_IP_GATEWAY are option and will be used if present and a static IP address were being defined. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-config-networking | 226 +++++++++++++++++++++++++++------------ 1 files changed, 157 insertions(+), 69 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 2f8363c..e508181 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -3,95 +3,183 @@ # Iterates over the list of network devices on the node and prompts the user # to configure each. -CONFIG_FILE_ROOT="/file/etc/sysconfig/network-scripts/ifcfg" +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 +# 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="/files/etc/sysconfig/network-scripts/ifcfg" CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log" function configure_interface { - NIC=$1 - BRIDGE=ovirtbr`echo $NIC | cut -b4-` - IF_FILENAME="/var/tmp/augtool-$NIC" - BR_FILENAME="/var/tmp/augtool-$BRIDGE" + local NIC=$1 + local AUTO=$2 + 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 + + local BRIDGE=ovirtbr$NIC + local IF_FILENAME="$WORKDIR/augtool-$NIC" + local BR_FILENAME="$WORKDIR/augtool-$BRIDGE" printf "\nConfigure $BRIDGE for use by $NIC..\n\n" - IF_ROOT="$CONFIG_FILE_ROOT-$NIC" - IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" + local IF_ROOT="$CONFIG_FILE_ROOT-$NIC" + local IF_CONFIG="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC" - BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" - BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" + local BR_ROOT="$CONFIG_FILE_ROOT-$BRIDGE" + local BR_CONFIG="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/TYPE bridge" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/PEERNTP yes" BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DELAY 0" IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/BRIDGE $BRIDGE" - # how do you want to configure this device? (dhcp, static IP) - while true; do - printf "Will $BRIDGE use dynamic addressing? (Y/N) " - read - 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 - 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" + local BR_CONFIG_BASE=BR_CONFIG + + if [ -z "$AUTO" ]; then + while true; do + printf "\n" + read -p "Enable IPv4 support ([S]tatic IP, [D]HCP, [N]o or [A]bort)? " + case $REPLY in + D|d) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp" + ;; + S|s) + printf "\n" + read -p "IP Address: "; IPADDR=$REPLY + read -p " Netmask: "; NETMASK=$REPLY + read -p " Gateway: "; GATEWAY=$REPLY + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO none" + 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" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Enable IPv6 supprt ([S]tatic, [D]HCPv6, A[u]to, [N]o)? " + case $REPLY in + S|s) + read -p "IPv6 Address: "; IPADDR=$REPLY + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IP6ADDR $IPADDR" + ;; + D|d) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6AUTCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes" + ;; + U|u) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6AUTOCONF yes" + ;; + A|a) return ;; + esac + + printf "\n" + read -p "Is this correct (Y/N/A)? " + case $REPLY in + Y|y) + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME break - ;; - esac - ;; - esac - done - - IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" - BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" - - printf "$IF_CONFIG\n" > $IF_FILENAME - printf "$BR_CONFIG\n" > $BR_FILENAME - - echo + ;; + N|n) BR_CONFIG=BR_CONFIG_BASE ;; + A|a) return ;; + esac + done + else + if [ -n "$OVIRT_IPV6" ]; then + case "$OVIRT_IPV6" in + "auto") + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF yes" + ;; + "dhcp") + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes" + ;; + *) + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6ADDR $OVIRT_IPV6" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no" + esac + fi + + if [ -z "$OVIRT_IP_ADDRESS" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp" + else + if [ "$OVIRT_IP_ADDRESS" != "off" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPADDR $OVIRT_IP_ADDRESS" + if [ -n "$OVIRT_IP_NETMASK" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/NETMASK $OVIRT_IP_NETMASK" + fi + if [ -n "$OVIRT_IP_GATEWAY" ]; then + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/GATEWAY $OVIRT_IP_GATEWAY" + fi + fi + fi + + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME + fi } function setup_menu { NICS=$(hal-device | awk '/net.interface/ {match($0, "= '"'"'(.*)'"'"' ", nic); printf("%s ", nic[1]); }') - NICS="$NICS Quit" - PS3="Please select a network interface to configure:" + 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_BOOTIF 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 + { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \ + && augtool < $config \ + && service network restart + } >> $CONFIG_LOG_FILE 2>&1 +fi -- 1.5.6.5