Darryl L. Pierce
2008-Nov-14 16:20 UTC
[Ovirt-devel] [PATCH node] Adds automatic non-interactive configuration for the standalone node.
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. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-config-networking | 82 +++++++++++++++++++++++++++------------ scripts/ovirt-firstboot | 6 ++- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 2f8363c..583ee5e 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,21 +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 we're in autoconfig mode, then iterate over all network interfaces and +# set them use DHCP -setup_menu +if [ "$1" == "AUTO" ]; then + if [ -n "$2" ]; then + configure_interface $2 AUTO $3 $4 $5 $6 + else + printf "No network interface specified to auto-configure. Exiting...\n" + exit 1 + fi +else + + # 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 + + select NIC in $NICS + do + printf "\n" + case "$NIC" in + "Quit") break ;; + *) configure_interface $NIC $IFACE_NUMBER ;; + esac + setup_menu + done + +fi # Merge together all generated files and run augtool diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot index 82d9e48..f93ba1b 100755 --- a/scripts/ovirt-firstboot +++ b/scripts/ovirt-firstboot @@ -29,7 +29,11 @@ start () { - ovirt-config-setup + if is_interactive_firstboot; then + ovirt-config-setup + else + ovirt-config-network AUTO + fi } case "$1" in -- 1.5.6.5
Darryl L. Pierce
2008-Nov-14 16:22 UTC
[Ovirt-devel] [PATCH node] Adds automatic non-interactive configuration for the standalone node.
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. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-config-networking | 79 +++++++++++++++++++++++++++------------ scripts/ovirt-firstboot | 6 ++- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 2f8363c..5f4fc84 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -9,6 +9,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="/var/tmp/augtool-$NIC" BR_FILENAME="/var/tmp/augtool-$BRIDGE" @@ -27,21 +32,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,21 +87,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 we're in autoconfig mode, then iterate over all network interfaces and +# set them use DHCP -setup_menu +if [ "$1" == "AUTO" ]; then + if [ -n "$2" ]; then + configure_interface $2 AUTO $3 $4 $5 $6 + else + printf "No network interface specified to auto-configure. Exiting...\n" + exit 1 + fi +else + + # 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 + + select NIC in $NICS + do + printf "\n" + case "$NIC" in + "Quit") break ;; + *) configure_interface $NIC $IFACE_NUMBER ;; + esac + setup_menu + done + +fi # Merge together all generated files and run augtool diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot index 82d9e48..f93ba1b 100755 --- a/scripts/ovirt-firstboot +++ b/scripts/ovirt-firstboot @@ -29,7 +29,11 @@ start () { - ovirt-config-setup + if is_interactive_firstboot; then + ovirt-config-setup + else + ovirt-config-network AUTO + fi } case "$1" in -- 1.5.6.5
Darryl Pierce
2008-Nov-14 16:22 UTC
[Ovirt-devel] Re: [PATCH node] Adds automatic non-interactive configuration for the standalone node.
On Friday 14 November 2008 11:20:19 am Darryl L. Pierce wrote:> 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. > > Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> > --- > scripts/ovirt-config-networking | 82 > +++++++++++++++++++++++++++------------ scripts/ovirt-firstboot | > 6 ++- > 2 files changed, 62 insertions(+), 26 deletions(-) > > diff --git a/scripts/ovirt-config-networking > b/scripts/ovirt-config-networking index 2f8363c..583ee5e 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"Missed this when I sent this patch. A followup patch removes this debugging bit. -- Darryl L. Pierce, Sr. Software Engineer Red Hat, Inc. - http://www.redhat.com/ oVirt - Virtual Machine Management - http://www.ovirt.org/ "What do you care what other people think, Mr. Feynman?" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20081114/95648f22/attachment.sig>
Darryl L. Pierce
2008-Nov-14 18:47 UTC
[Ovirt-devel] [PATCH node] Adds automatic non-interactive configuration for the standalone node.
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
Darryl L. Pierce
2008-Nov-14 18:48 UTC
[Ovirt-devel] [PATCH node] Adds automatic non-interactive configuration for the standalone node.
NOTE: Sorry, again sent out a patch that had debugging code in it. :-/ 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 | 88 +++++++++++++++++++++++++-------------- scripts/ovirt-firstboot | 12 +++++- 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 2f8363c..45d7cf8 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -9,6 +9,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="/var/tmp/augtool-$NIC" BR_FILENAME="/var/tmp/augtool-$BRIDGE" @@ -27,21 +32,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 +87,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
Darryl L. Pierce
2008-Nov-17 15:24 UTC
[Ovirt-devel] [PATCH node] Adds automatic non-interactive configuration for the standalone node.
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..2a47f7a 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
Darryl L. Pierce
2008-Nov-17 15:28 UTC
[Ovirt-devel] [PATCH node] Adds automatic non-interactive configuration for the standalone node.
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