From 36f2756ae2e25f8d2c7a1dd2ca111ee00f1b7961 Mon Sep 17 00:00:00 2001 From: William Wernert Date: Fri, 21 Jun 2019 16:16:12 -0400 Subject: [PATCH 1/3] Added initial code to account for different nmcli versions --- so-setup-network.sh | 59 +++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/so-setup-network.sh b/so-setup-network.sh index 7830c4857..21c4c7c2f 100644 --- a/so-setup-network.sh +++ b/so-setup-network.sh @@ -254,27 +254,50 @@ create_bond_nmcli() { MTU=1500 fi - # Create the bond interface - nmcli con add type bond ifname bond0 con-name "bond0" \ - bond.options "mode=0" \ - 802-3-ethernet.mtu $MTU \ - ipv4.method "disabled" \ - ipv6.method "ignore" \ - connection.autoconnect "yes" \ - >> $SETUPLOG 2>&1 + NMCLI_VER=$(nmcli -v | sed 's/nmcli tool, version 1\.//g' | awk -F '\\.' '{print $1}') - for BNIC in ${BNICS[@]}; do - # Strip the quotes from the NIC names - BONDNIC="$(echo -e "${BNIC}" | tr -d '"')" - # Create the slave interface and assign it to the bond - nmcli con add type ethernet ifname $BONDNIC master bond0 \ - connection.autoconnect "yes" \ + if [[ $NMCLI_VER -lt 12 ]] + then # We are using an older version of nmcli + + # Create the bond interface + nmcli con add ifname bond0 con-name "bond0" type bond + nmcli con mod bond0 bond.options "mode=0" + nmcli con mod bond0 ethernet.mtu $MTU + nmcli con mod bond0 ipv4.method "disabled" + nmcli con mod bond0 ipv6.method "ignore" + nmcli con mod bond0 connection.autoconnect "yes" + + for BNIC in ${BNICS[@]}; do + # Strip the quotes from the NIC names + BONDNIC="$(echo -e "${BNIC}" | tr -d '"')" + # Create the slave interface and assign it to the bond + nmcli con add type ethernet ifname $BONDNIC con-name "bond0-slave-$BONDNIC" master bond0 + nmcli con mod bond0-slave-$BONDNIC ethernet.mtu $MTU + nmcli con mod bond0-slave-$BONDNIC connection.autoconnect "yes" + done + else + # Create the bond interface + nmcli con add type bond ifname bond0 con-name "bond0" \ + bond.options "mode=0" \ 802-3-ethernet.mtu $MTU \ - con-name "bond0-slave-$BONDNIC" \ + ipv4.method "disabled" \ + ipv6.method "ignore" \ + connection.autoconnect "yes" \ >> $SETUPLOG 2>&1 - # Bring the slave interface up - nmcli con up bond0-slave-$BONDNIC >> $SETUPLOG 2>&1 - done + + for BNIC in ${BNICS[@]}; do + # Strip the quotes from the NIC names + BONDNIC="$(echo -e "${BNIC}" | tr -d '"')" + # Create the slave interface and assign it to the bond + nmcli con add type ethernet ifname $BONDNIC master bond0 \ + connection.autoconnect "yes" \ + 802-3-ethernet.mtu $MTU \ + con-name "bond0-slave-$BONDNIC" \ + >> $SETUPLOG 2>&1 + # Bring the slave interface up + nmcli con up bond0-slave-$BONDNIC >> $SETUPLOG 2>&1 + done + fi } create_bond() { From 625668e2592d7613b0b88d67025046305efad06a Mon Sep 17 00:00:00 2001 From: William Wernert Date: Mon, 24 Jun 2019 10:21:14 -0400 Subject: [PATCH 2/3] Added logging syntax and fixed bond interface bring up We should bring the bond connections up after creating them --- so-setup-network.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/so-setup-network.sh b/so-setup-network.sh index 21c4c7c2f..93a57b386 100644 --- a/so-setup-network.sh +++ b/so-setup-network.sh @@ -260,20 +260,21 @@ create_bond_nmcli() { then # We are using an older version of nmcli # Create the bond interface - nmcli con add ifname bond0 con-name "bond0" type bond - nmcli con mod bond0 bond.options "mode=0" - nmcli con mod bond0 ethernet.mtu $MTU - nmcli con mod bond0 ipv4.method "disabled" - nmcli con mod bond0 ipv6.method "ignore" - nmcli con mod bond0 connection.autoconnect "yes" + nmcli con add ifname bond0 con-name "bond0" type bond >> $SETUPLOG 2>&1 + nmcli con mod bond0 bond.options "mode=0" >> $SETUPLOG 2>&1 + nmcli con mod bond0 ethernet.mtu $MTU >> $SETUPLOG 2>&1 + nmcli con mod bond0 ipv4.method "disabled" >> $SETUPLOG 2>&1 + nmcli con mod bond0 ipv6.method "ignore" >> $SETUPLOG 2>&1 + nmcli con mod bond0 connection.autoconnect "yes" >> $SETUPLOG 2>&1 for BNIC in ${BNICS[@]}; do # Strip the quotes from the NIC names BONDNIC="$(echo -e "${BNIC}" | tr -d '"')" # Create the slave interface and assign it to the bond - nmcli con add type ethernet ifname $BONDNIC con-name "bond0-slave-$BONDNIC" master bond0 - nmcli con mod bond0-slave-$BONDNIC ethernet.mtu $MTU - nmcli con mod bond0-slave-$BONDNIC connection.autoconnect "yes" + nmcli con add type ethernet ifname $BONDNIC con-name "bond0-slave-$BONDNIC" master bond0 >> $SETUPLOG 2>&1 + nmcli con mod bond0-slave-$BONDNIC ethernet.mtu $MTU >> $SETUPLOG 2>&1 + nmcli con mod bond0-slave-$BONDNIC connection.autoconnect "yes" >> $SETUPLOG 2>&1 + nmcli con up bond0-slave-$BONDNIC >> $SETUPLOG 2>&1 done else # Create the bond interface From 1b3c5f8b7923c36367d65f1bcc02ef058eacc92d Mon Sep 17 00:00:00 2001 From: William Wernert Date: Mon, 24 Jun 2019 12:14:07 -0400 Subject: [PATCH 3/3] Fixed slave -> bond issues and standardized syntax for nmcli so it works on any version --- so-setup-network.sh | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/so-setup-network.sh b/so-setup-network.sh index 93a57b386..55fff5e70 100644 --- a/so-setup-network.sh +++ b/so-setup-network.sh @@ -254,35 +254,11 @@ create_bond_nmcli() { MTU=1500 fi - NMCLI_VER=$(nmcli -v | sed 's/nmcli tool, version 1\.//g' | awk -F '\\.' '{print $1}') - - if [[ $NMCLI_VER -lt 12 ]] - then # We are using an older version of nmcli - - # Create the bond interface - nmcli con add ifname bond0 con-name "bond0" type bond >> $SETUPLOG 2>&1 - nmcli con mod bond0 bond.options "mode=0" >> $SETUPLOG 2>&1 - nmcli con mod bond0 ethernet.mtu $MTU >> $SETUPLOG 2>&1 - nmcli con mod bond0 ipv4.method "disabled" >> $SETUPLOG 2>&1 - nmcli con mod bond0 ipv6.method "ignore" >> $SETUPLOG 2>&1 - nmcli con mod bond0 connection.autoconnect "yes" >> $SETUPLOG 2>&1 - - for BNIC in ${BNICS[@]}; do - # Strip the quotes from the NIC names - BONDNIC="$(echo -e "${BNIC}" | tr -d '"')" - # Create the slave interface and assign it to the bond - nmcli con add type ethernet ifname $BONDNIC con-name "bond0-slave-$BONDNIC" master bond0 >> $SETUPLOG 2>&1 - nmcli con mod bond0-slave-$BONDNIC ethernet.mtu $MTU >> $SETUPLOG 2>&1 - nmcli con mod bond0-slave-$BONDNIC connection.autoconnect "yes" >> $SETUPLOG 2>&1 - nmcli con up bond0-slave-$BONDNIC >> $SETUPLOG 2>&1 - done - else - # Create the bond interface - nmcli con add type bond ifname bond0 con-name "bond0" \ - bond.options "mode=0" \ - 802-3-ethernet.mtu $MTU \ - ipv4.method "disabled" \ - ipv6.method "ignore" \ +# Create the bond interface + nmcli con add ifname bond0 con-name "bond0" type bond mode 0 -- \ + ipv4.method disabled \ + ipv6.method link-local \ + ethernet.mtu $MTU \ connection.autoconnect "yes" \ >> $SETUPLOG 2>&1 @@ -290,15 +266,13 @@ create_bond_nmcli() { # Strip the quotes from the NIC names BONDNIC="$(echo -e "${BNIC}" | tr -d '"')" # Create the slave interface and assign it to the bond - nmcli con add type ethernet ifname $BONDNIC master bond0 \ - connection.autoconnect "yes" \ - 802-3-ethernet.mtu $MTU \ - con-name "bond0-slave-$BONDNIC" \ - >> $SETUPLOG 2>&1 + nmcli con add type ethernet ifname $BONDNIC con-name "bond0-slave-$BONDNIC" master bond0 -- \ + ethernet.mtu $MTU \ + connection.autoconnect "yes" \ + >> $SETUPLOG 2>&1 # Bring the slave interface up nmcli con up bond0-slave-$BONDNIC >> $SETUPLOG 2>&1 done - fi } create_bond() {