Create list of network interface names at run-time
The list network interfaces used by osbash is currently a hard-coded list in distro-specific library files (e.g., lib/functions.ubuntu.sh). With Ubuntu 16.04 LTS, network interface names differ between VirtualBox and KVM as well (unless we reconfigure the operating system to use the traditional ethX naming scheme). This patch builds the list of network interfaces at run-time which should make it easier to support distros with differing network interface naming schemes. Change-Id: Id2cd684152911289821b165daf6b8fc002f42f2d
This commit is contained in:
@@ -2,13 +2,6 @@
|
||||
# Fedora /etc/sysconfig/network-scripts/ifcfg-* configuration
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function _ifnum_to_ifname {
|
||||
local if_num=$1
|
||||
local -a if_names=('p2p1' 'p7p1' 'p8p1' 'p9p1')
|
||||
|
||||
echo "${if_names[$if_num]}"
|
||||
}
|
||||
|
||||
function config_netif {
|
||||
local if_type=$1
|
||||
local if_num=${2:-""}
|
||||
@@ -21,7 +14,7 @@ function config_netif {
|
||||
template="template-fedora-ifcfg-static"
|
||||
fi
|
||||
|
||||
local if_name="$(_ifnum_to_ifname "$if_num")"
|
||||
local if_name="$(ifnum_to_ifname "$if_num")"
|
||||
|
||||
local if_file=/etc/sysconfig/network-scripts/ifcfg-$if_name
|
||||
|
||||
|
@@ -343,6 +343,27 @@ function service_to_user_password {
|
||||
# Network configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# Return the nth network interface name (not counting loopback; 0 -> eth0)
|
||||
function ifnum_to_ifname {
|
||||
local if_num=$1
|
||||
|
||||
# Skip loopback and start counting with next interface
|
||||
local iface=${IF_NAMES[$((if_num + 1))]}
|
||||
|
||||
echo >&2 "ifnum_to_ifname: interface $if_num is $iface"
|
||||
echo "$iface"
|
||||
}
|
||||
|
||||
# Get all network interfaces (e.g. eth0, p2p1, ens0, enp0s3) into an array
|
||||
function set_iface_list {
|
||||
unset IF_NAMES
|
||||
local iface
|
||||
for iface in $(ip -o link show|awk '/: / {print $2}'|tr -d ':'); do
|
||||
IF_NAMES+=($iface)
|
||||
done
|
||||
echo "Set IF_NAMES to ${IF_NAMES[*]}"
|
||||
}
|
||||
|
||||
function hostname_to_ip {
|
||||
local host_name=$1
|
||||
getent hosts "$host_name"|awk '{print $1}'
|
||||
|
@@ -4,13 +4,6 @@
|
||||
|
||||
readonly UBUNTU_IF_FILE=/etc/network/interfaces
|
||||
|
||||
function _ifnum_to_ifname {
|
||||
local if_num=$1
|
||||
local -a if_names=('eth0' 'eth1' 'eth2' 'eth3')
|
||||
|
||||
echo "${if_names[$if_num]}"
|
||||
}
|
||||
|
||||
function config_netif {
|
||||
local if_type=$1
|
||||
local if_num=${2:-""}
|
||||
@@ -25,7 +18,7 @@ function config_netif {
|
||||
template="template-ubuntu-interfaces-static"
|
||||
fi
|
||||
|
||||
local if_name="$(_ifnum_to_ifname "$if_num")"
|
||||
local if_name="$(ifnum_to_ifname "$if_num")"
|
||||
|
||||
# Empty line before this entry
|
||||
echo | sudo tee -a "$UBUNTU_IF_FILE"
|
||||
|
@@ -1,3 +1,3 @@
|
||||
# VirtualBox NAT -- for Internet access to VM
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
auto %IF_NAME%
|
||||
iface %IF_NAME% inet dhcp
|
||||
|
@@ -23,6 +23,8 @@ indicate_current_auto
|
||||
|
||||
exec_logfile
|
||||
|
||||
set_iface_list
|
||||
|
||||
# Set hostname for now and for rebooted system
|
||||
sudo hostname "$NODE_NAME" >/dev/null
|
||||
echo "$NODE_NAME" | sudo tee /etc/hostname > /dev/null
|
||||
@@ -31,6 +33,6 @@ echo "$NODE_NAME" | sudo tee /etc/hostname > /dev/null
|
||||
config_network
|
||||
netcfg_show
|
||||
|
||||
for iface in $(ip -o link show|grep -o "eth[[:digit:]]"); do
|
||||
for iface in ${IF_NAMES[@]}; do
|
||||
sudo ifup "$iface"
|
||||
done
|
||||
|
@@ -25,8 +25,9 @@ echo "Configuring the Linux bridge agent."
|
||||
conf=/etc/neutron/plugins/ml2/linuxbridge_agent.ini
|
||||
|
||||
# Edit the [linux_bridge] section.
|
||||
# TODO Better method of getting interface name
|
||||
PUBLIC_INTERFACE_NAME=eth2
|
||||
set_iface_list
|
||||
PUBLIC_INTERFACE_NAME=$(ifnum_to_ifname 2)
|
||||
echo "PUBLIC_INTERFACE_NAME=$PUBLIC_INTERFACE_NAME"
|
||||
iniset_sudo $conf linux_bridge physical_interface_mappings provider:$PUBLIC_INTERFACE_NAME
|
||||
|
||||
# Edit the [vxlan] section.
|
||||
|
@@ -120,8 +120,9 @@ echo "Configuring Linux Bridge agent."
|
||||
conf=/etc/neutron/plugins/ml2/linuxbridge_agent.ini
|
||||
|
||||
# Edit the [linux_bridge] section.
|
||||
# TODO Better method of getting interface name
|
||||
PUBLIC_INTERFACE_NAME=eth2
|
||||
set_iface_list
|
||||
PUBLIC_INTERFACE_NAME=$(ifnum_to_ifname 2)
|
||||
echo "PUBLIC_INTERFACE_NAME=$PUBLIC_INTERFACE_NAME"
|
||||
iniset_sudo $conf linux_bridge physical_interface_mappings provider:$PUBLIC_INTERFACE_NAME
|
||||
|
||||
# Edit the [vxlan] section.
|
||||
|
Reference in New Issue
Block a user