3 # Iterates over the list of network devices on the node and prompts the user
6 .
/etc
/init.d
/ovirt-functions
9 warn
() { printf '%s: %s\n' "$ME" "$*" >&2; }
10 die
() { warn
"$*"; exit 1; }
12 WORKDIR
=$
(mktemp
-d) ||
exit 1
14 # Remove $WORKDIR upon interrupt (and HUP, PIPE, TERM) and upon normal
15 # termination, being careful not to change the exit status.
16 trap '__st=$?; rm -rf "$WORKDIR"; stop_log; exit $__st' 0
17 trap 'exit $?' 1 2 13 15
19 IFCONFIG_FILE_ROOT
="/files/etc/sysconfig/network-scripts/ifcfg"
20 NTPCONF_FILE_ROOT
="/files/etc/ntp"
21 NTP_CONFIG_FILE
="/etc/ntp.conf"
27 # if local storage is not configured, then exit the script
28 if ! is_local_storage_configured
; then
29 printf "Local storage must be configured prior to configuring the management interface.\n\n"
33 # Checks that a network interface was already configured.
34 function has_configured_interface
36 local show_message
=${1-false}
38 if [[ -n "${CONFIGURED_NIC}" ]]; then
41 if $show_message; then
42 printf "\nYou must configure a network interface first.\n\n"
48 # Configures vlan for the node.
50 # $2 - the network bridge name
52 # $4 - the VL_ROOT variable
53 # $5 - the VL_CONFIG variable
54 # $6 - the IF_ROOT value
55 # $7 - the vlan config filename variable
56 # $8 - the NIC config filename
68 eval $vlroot="${ifroot}.${vlan_id}"
69 eval $vlconfig=\"rm \$
${vlroot}\\nset \$${vlroot}/DEVICE ${nic}.${vlan_id}\"
70 eval $vlconfig=\"\$
${vlconfig}\\nset \$${vlroot}/BRIDGE ${bridge}\"
71 eval $vlconfig=\"\$
${vlconfig}\\nset \$
${vlroot}/VLAN
yes\"
72 eval $vlfilename="${iffilename}.${vlan_id}"
75 function configure_interface
79 if [[ "$AUTO" == "AUTO" &&
80 -n "$OVIRT_IP_ADDRESS" ]]; then
81 IPADDR
=$OVIRT_IP_ADDRESS
82 NETMASK
=$OVIRT_IP_NETMASK
83 GATEWAY
=$OVIRT_IP_GATEWAY
84 PREFIX
=$OVIRT_IP_PREFIX
87 if has_configured_interface
; then
88 printf "This will delete the current configuration for ${CONFIGURED_NIC}.\n"
89 if ask_yes_or_no
"Do you wish to continue ([Y]es/[N]o)?"; then
90 printf "\nDeleting existing network configuration...\n"
91 cp -a /etc
/sysconfig
/network-scripts
/ifcfg-lo
/etc
/sysconfig
/network-scripts
/backup.lo
92 remove_config
/etc
/sysconfig
/network-scripts
/ifcfg-
*
93 rm -rf /etc
/sysconfig
/network-scripts
/ifcfg-
*
94 cp -a /etc
/sysconfig
/network-scripts
/backup.lo
/etc
/sysconfig
/network-scripts
/ifcfg-lo
96 printf "\nAborting...\n"
105 local IF_FILENAME
="$WORKDIR/augtool-$NIC"
106 local BR_FILENAME
="$WORKDIR/augtool-$BRIDGE"
108 printf "\nConfigure $BRIDGE for use by $NIC..\n\n"
110 local IF_ROOT
="$IFCONFIG_FILE_ROOT-$NIC"
111 local IF_CONFIG
="rm $IF_ROOT\nset $IF_ROOT/DEVICE $NIC"
113 local BR_ROOT
="$IFCONFIG_FILE_ROOT-$BRIDGE"
114 local BR_CONFIG
="rm $BR_ROOT\nset $BR_ROOT/DEVICE $BRIDGE"
116 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/TYPE Bridge"
117 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/PEERNTP yes"
118 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/DELAY 0"
119 local BR_CONFIG_BASE
=$BR_CONFIG
121 if [ -z "$AUTO" ]; then
126 LINK
=`ethtool $NIC| grep "Link detected"`:u
127 [ -z "$LINK" ] && return
128 if echo $LINK |
grep -q "Link detected: yes" ; then
133 echo "NIC is: $NICSTATUS"
135 if ask_yes_or_no
"Help identify ${NIC} by blinking lights for 10 seconds ([Y]es/[N]o)?"; then
136 ethtool
--identify $NIC 10
139 ask_yes_or_no
"Include VLAN support ([Y]es/[N]o/[A]bort)? " true true
143 read -ep "What is the VLAN ID for this device (a=abort) "
145 A|a
) CONFIGURED_NIC
=""; return;;
147 if [[ -n "$REPLY" ]] && [[ "$REPLY" =~
"^[0-9]{1,}$" ]]; then
149 setup_vlan
$NIC $BRIDGE $VLAN_ID VL_ROOT VL_CONFIG
$IF_ROOT VL_FILENAME
$IF_FILENAME
156 1) IF_CONFIG
="${IF_CONFIG}\nset ${IF_ROOT}/BRIDGE ${BRIDGE}" ;;
164 read -ep "Enable IPv4 support ([S]tatic IP, [D]HCP, [N]o or [A]bort)? "
167 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp"
172 read -ep "IP Address: "; IPADDR
=$REPLY
173 read -ep " Netmask: "; NETMASK
=$REPLY
174 read -ep " Gateway: "; GATEWAY
=$REPLY
176 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO none"
177 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPADDR $IPADDR"
178 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/NETMASK $NETMASK"
179 if [ -n "${GATEWAY}" ]; then
180 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/GATEWAY $GATEWAY"
195 read -ep "Enable IPv6 support ([S]tatic, [D]HCPv6, A[u]to, [N]o or [A]bort)? "
198 read -ep "IPv6 Address: "; IPADDR
=$REPLY
199 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes"
200 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IP6ADDR $IPADDR"
204 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes"
205 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6AUTCONF no"
206 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no"
207 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes"
211 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes"
212 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no"
213 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6AUTOCONF yes"
225 ask_yes_or_no
"Is this correct ([Y]es/[N]o/[A]bort)?" true true
228 IF_CONFIG
="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes"
229 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes"
230 if [[ -n "$VLAN_ID" ]]; then
231 VL_CONFIG
="$VL_CONFIG\nset $VL_ROOT/ONBOOT yes"
233 printf "$IF_CONFIG\n" > $IF_FILENAME
234 printf "$BR_CONFIG\n" > $BR_FILENAME
235 if [[ -n "$VLAN_ID" ]]; then
236 printf "$VL_CONFIG\n" > $VL_FILENAME
241 BR_CONFIG
=$BR_CONFIG_BASE
251 if [ -n "$OVIRT_IPV6" ]; then
252 case "$OVIRT_IPV6" in
254 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes"
255 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no"
256 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF yes"
259 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes"
260 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no"
261 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no"
262 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/DHCPV6C yes"
265 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6INIT yes"
266 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6ADDR $OVIRT_IPV6"
267 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6_AUTOCONF no"
268 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPV6FORWARDING no"
272 if [ -n "$OVIRT_VLAN" ]; then
274 setup_vlan
$NIC $BRIDGE $VLAN_ID VL_ROOT VL_CONFIG
$IF_ROOT VL_FILENAME
$IF_FILENAME
277 if [ -z "$OVIRT_IP_ADDRESS" ]; then
278 if [ -z "$VL_CONFIG" ]; then
279 IF_CONFIG
="${IF_CONFIG}\nset ${IF_ROOT}/BRIDGE ${BRIDGE}"
281 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO dhcp"
283 if [ "$OVIRT_IP_ADDRESS" != "off" ]; then
284 if [ -z "$VL_CONFIG" ]; then
285 IF_CONFIG
="${IF_CONFIG}\nset ${IF_ROOT}/BRIDGE ${BRIDGE}"
287 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/IPADDR $OVIRT_IP_ADDRESS"
288 if [ -n "$OVIRT_IP_NETMASK" ]; then
289 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/NETMASK $OVIRT_IP_NETMASK"
291 if [ -n "$OVIRT_IP_GATEWAY" ]; then
292 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/GATEWAY $OVIRT_IP_GATEWAY"
297 IF_CONFIG
="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes"
298 BR_CONFIG
="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes"
299 if [ -n "${VL_CONFIG}" ]; then
300 VL_CONFIG
="$VL_CONFIG\nset $VL_ROOT/ONBOOT yes"
303 printf "$IF_CONFIG\n" > $IF_FILENAME
304 printf "$BR_CONFIG\n" > $BR_FILENAME
305 if [ -n "$VL_CONFIG" ]; then
306 printf "$VL_CONFIG\n" > $VL_FILENAME
311 function configure_dns
315 if [[ "$AUTO" == "AUTO" &&
316 -n "$OVIRT_DNS" ]]; then
320 local IF_FILENAME
="$WORKDIR/augtool-br${CONFIGURED_NIC}"
321 local IF_ROOT
="$IFCONFIG_FILE_ROOT-br${CONFIGURED_NIC}"
324 if [ -z "$AUTO" ]; then
325 if has_configured_interface true
; then
327 for dns
in first second
; do
330 read -ep "Please enter the ${dns} DNS server (or ENTER to exit): "
331 if [[ -z "${REPLY}" ]]; then
332 if [[ -z "${DNS}" ]]; then
333 printf "\nAborted...\n"
339 if is_valid_ipv4
$REPLY; then
340 if [[ -z "${DNS}" ]]; then
342 elif [[ -n "${REPLY}" ]]; then
343 DNS
="${DNS}:${REPLY}"
347 printf "${REPLY} is an invalid address.\n"
353 ask_yes_or_no
"Is this correct ([Y]es/[N]o/[A]bort)?" true true
363 if [ -n "$DNS" ]; then
364 DNS1
=$
(echo "$DNS" |
awk -F\
: '{print $1}')
365 DNS2
=$
(echo "$DNS" |
awk -F\
: '{print $2}')
367 test -n "$DNS1" && printf "set $IF_ROOT/DNS1 $DNS1\n" >> $IF_FILENAME
368 test -n "$DNS2" && printf "set $IF_ROOT/DNS2 $DNS2\n" >> $IF_FILENAME
372 function configure_ntp
375 if [[ "$AUTO" == "AUTO" && -n "$OVIRT_NTP" ]]; then
376 NTPSERVERS
=$OVIRT_NTP
381 if [ -z "$AUTO" ]; then
382 if has_configured_interface true
; then
384 read -ep "Enter an NTP server (hit return when finished): "
386 if [ -z "$REPLY" ]; then break; fi
388 if is_valid_ipv4
$REPLY; then
389 NTPSERVERS
="${NTPSERVERS}:${REPLY}"
391 printf "${REPLY} is an invalid address.\n"
398 function save_ntp_configuration
400 local ntpconf
="$WORKDIR/augtool-ntp"
401 local ntproot
="/files/etc/ntp.conf"
405 set ${ntproot}/driftfile /var/lib/ntp/drift\n\
406 set ${ntproot}/includefile /etc/ntp/crypto/pw\n\
407 set ${ntproot}/keys /etc/ntp/keys\n\
410 if [ -n "$NTPSERVERS" ]; then
412 SERVERS
=$
(echo $NTPSERVERS |
awk 'BEGIN{FS=":"}{for (i=1; i<=NF; i++) print $i}')
413 for server
in $SERVERS; do
414 printf "set /files/etc/ntp.conf/server[${offset}] ${server}\n" >> $ntpconf
415 offset
=$
(echo "$offset+1" |
bc)
423 udi_list
=$
(hal-find-by-capability
--capability net
.80203)
424 if [ -n "$udi_list" ]; then
425 for d
in $udi_list; do
426 if [[ ! "$(hal-get-property --udi $d --key net.physical_device)" =~ computer
]]; then
427 NICS
="$NICS $(hal-get-property --udi "$d" --key net.interface)"
432 # Add virtio NICs that were possibly not detected by hal
433 NICS
="$NICS $(ifconfig -a | awk '/Ethernet/ {print $1}' | grep -v -E "^br|^bond|^vnet|^virbr|\.
" | xargs)"
434 NICS
=$
(echo $NICS |
tr ' ' '\n' |
sort -u |
xargs)
436 PS3
="Please select an interface or configuration option: "
439 if [ "$1" == "AUTO" ]; then
440 if [ -n "$OVIRT_BOOTIF" ]; then
441 configure_interface
"$OVIRT_BOOTIF" AUTO
442 configure_dns
"$OVIRT_DNS" AUTO
443 configure_ntp
"$OVIRT_NTP" AUTO
445 printf "No network interface specified. Unable to configure networking."
452 printf "\n\nManagement Network Configuration\n\n" >&2
453 printf "***** WARNING *****\n"
454 printf "Configuring the network will destroy any existing networking\n"
455 printf "configuration on this system.\n"
456 printf "***** WARNING *****\n"
457 printf "\nPhysical Networking Devices (*=PXE boot interface)\n"
458 printf " %-10s %-12s %-18s\n" "Name" "Driver" "MAC"
460 driver
=$
(basename $
(readlink
/sys
/class
/net
/$nic/device
/driver
) 2>/dev
/null
)
461 mac
=$
(cat /sys
/class
/net
/$nic/address
)
462 if [ "$nic" = "$OVIRT_BOOTIF" ]; then
467 printf "%s%-10s %-12s %-18s\n" "$pxe" "$nic" "$driver" "$mac"
473 Save
="Save And Return To Menu"
474 select NIC
in $NICS "$DNS" "$NTP" "$Abort" "$Save"
478 "$DNS") configure_dns
"$OVIRT_DNS"; break ;;
479 "$NTP") configure_ntp
"$OVIRT_NTP"; break ;;
480 "$Abort") rm -f "${WORKDIR}"/augtool-
*; exit 99;;
482 save_ntp_configuration
485 if [[ -n "${NIC}" ]] && [[ "${NICS}" =~ "${NIC}" ]]; then
486 configure_interface
$NIC $IFACE_NUMBER
488 printf "\nInvalid option selected.\n"
499 if ls "$WORKDIR"/augtool-
* > /dev
/null
2>&1 ; then
500 log
"Configuring network"
502 # delete existing scripts
503 for script in /etc
/sysconfig
/network-scripts
/ifcfg-
*; do
504 if [[ ! "${script}" =~ ifcfg-lo
]]; then
505 ovirt_safe_delete_config
$script
509 config
="$WORKDIR"/config-augtool
510 cat "$WORKDIR"/augtool-
* > $config \
513 log
"Network configured successfully"
516 /etc
/sysconfig
/network-scripts
/ifcfg
* \
519 log
"Error configuring network, see $OVIRT_LOGFILE"
526 if [ "$net_configured" = 1 ]; then
527 service network stop
> /dev
/null
2>&1
528 for i
in `brctl show | grep breth | awk '{print $1}'`
533 service network start