Merge lp:~cpe-sa/obinstall/next-network-mode-fix into lp:obinstall/next

Proposed by Craig Bender
Status: Needs review
Proposed branch: lp:~cpe-sa/obinstall/next-network-mode-fix
Merge into: lp:obinstall/next
Diff against target: 350 lines (+202/-110)
1 file modified
network/network-mode.sh (+202/-110)
To merge this branch: bzr merge lp:~cpe-sa/obinstall/next-network-mode-fix
Reviewer Review Type Date Requested Status
CPE SA Pending
Review via email: mp+319011@code.launchpad.net

Description of the change

Clean up and rewrite of network.sh.

-Sets both eth0 and eth1 to appropriate fabrics/subnets
-Handles errors
-New force mode to do a partial change if nodes aren't ready/broken.
-Output is color coded by nic/vlan/subnet
-Performs a single read of maas for all system ids vs calling maas admin node 10 x
-Performs a single read of maas to get both fabric and vlan id based on subnet
-Uses proper bash 4.x parameter substitution
-Maas queries use jq instead of the unholy trinity of echo+grep+cut

Output:

$ ./network-mode.sh

Usage: network-mode.sh <options>

Options:
  -s|--single-network Configure primary and secondary interfaces on nodes 1-10 on a single VLAN
  -d|--dual-network Configure secondary interfaces on ndoes 1-10 on a second VLAN
  -f|--force Run even if nodes are not in Ready state

$ ./network-mode.sh -s

Configuring OrangeBox20 for Single Network mode:

 Logging in as admin to maas server @ http://172.27.20.1/MAAS...OK!

 Getting state of nodes on OrangeBox20

  node01ob20 Ready
  node03ob20 Ready
  node04ob20 Ready
  node07ob20 Ready
  node08ob20 Ready
  node09ob20 Ready
  node02ob20 Ready
  node05ob20 Ready
  node06ob20 Ready
  node10ob20 Ready

 Mikrotik: Successfully configured router for Single Network Mode!

 MAAS: Successfully set eth0 on node01ob20 (4y3h8a) to use vlan 5002
 MAAS: Successfully linked eth0 on node01ob20 (4y3h8a) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node01ob20 (4y3h8a) to use vlan 5002
 MAAS: Successfully linked eth1 on node01ob20 (4y3h8a) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node02ob20 (kqyg3f) to use vlan 5002
 MAAS: Successfully linked eth0 on node02ob20 (kqyg3f) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node02ob20 (kqyg3f) to use vlan 5002
 MAAS: Successfully linked eth1 on node02ob20 (kqyg3f) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node03ob20 (4y3h8c) to use vlan 5002
 MAAS: Successfully linked eth0 on node03ob20 (4y3h8c) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node03ob20 (4y3h8c) to use vlan 5002
 MAAS: Successfully linked eth1 on node03ob20 (4y3h8c) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node04ob20 (4y3h8d) to use vlan 5002
 MAAS: Successfully linked eth0 on node04ob20 (4y3h8d) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node04ob20 (4y3h8d) to use vlan 5002
 MAAS: Successfully linked eth1 on node04ob20 (4y3h8d) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node05ob20 (erfb86) to use vlan 5002
 MAAS: Successfully linked eth0 on node05ob20 (erfb86) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node05ob20 (erfb86) to use vlan 5002
 MAAS: Successfully linked eth1 on node05ob20 (erfb86) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node06ob20 (4ewpx6) to use vlan 5002
 MAAS: Successfully linked eth0 on node06ob20 (4ewpx6) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node06ob20 (4ewpx6) to use vlan 5002
 MAAS: Successfully linked eth1 on node06ob20 (4ewpx6) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node07ob20 (4y3h8g) to use vlan 5002
 MAAS: Successfully linked eth0 on node07ob20 (4y3h8g) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node07ob20 (4y3h8g) to use vlan 5002
 MAAS: Successfully linked eth1 on node07ob20 (4y3h8g) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node08ob20 (4y3h8h) to use vlan 5002
 MAAS: Successfully linked eth0 on node08ob20 (4y3h8h) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node08ob20 (4y3h8h) to use vlan 5002
 MAAS: Successfully linked eth1 on node08ob20 (4y3h8h) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node09ob20 (4y3h8k) to use vlan 5002
 MAAS: Successfully linked eth0 on node09ob20 (4y3h8k) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node09ob20 (4y3h8k) to use vlan 5002
 MAAS: Successfully linked eth1 on node09ob20 (4y3h8k) to subnet 172.27.20.0/23
 MAAS: Successfully set eth0 on node10ob20 (tsq84y) to use vlan 5002
 MAAS: Successfully linked eth0 on node10ob20 (tsq84y) to subnet 172.27.20.0/23
 MAAS: Successfully set eth1 on node10ob20 (tsq84y) to use vlan 5002
 MAAS: Successfully linked eth1 on node10ob20 (tsq84y) to subnet 172.27.20.0/23

Successfully configured OrangeBox20 for Single Network Mode!

To post a comment you must log in.
Revision history for this message
Craig Bender (craig-bender) wrote :

Example of trying to run script when nodes aren't ready/broken:

$ ./network-mode.sh -d

Configuring OrangeBox20 for Dual Network mode:

 Logging in as admin to maas server @ http://172.27.20.1/MAAS...OK!

 Getting state of nodes on OrangeBox20

 ERROR: This script requires that all nodes are in a "Ready" or "Broken" state

  Please ensure the all nodes are "Ready" and try again.

  node01ob20 Deployed
  node03ob20 Deployed
  node04ob20 Deployed
  node07ob20 Deployed
  node08ob20 Deployed
  node09ob20 Deployed
  node02ob20 Deployed
  node05ob20 Deployed
  node06ob20 Deployed
  node10ob20 Ready

22. By Craig Bender

Check for existing links before updating link to subnet, otherwise an alias gets created

Revision history for this message
Craig Bender (craig-bender) wrote :
Download full text (4.5 KiB)

If link exists:
$ ./network-mode.sh -s

Configuring OrangeBox20 for Single Network mode:

 Logging in as admin to maas server @ http://172.27.20.1/MAAS...OK!

 Getting state of nodes on OrangeBox20

  node01ob20 Ready
  node03ob20 Ready
  node04ob20 Ready
  node07ob20 Ready
  node08ob20 Ready
  node09ob20 Ready
  node02ob20 Ready
  node05ob20 Ready
  node06ob20 Ready
  node10ob20 Ready

 Mikrotik: Successfully configured router for Single Network Mode!

 MAAS: Successfully set eth0 on node01ob20 (4y3h8a) to use vlan 5002
 MAAS: Successfully set eth1 on node01ob20 (4y3h8a) to use vlan 5002
 MAAS: Successfully set eth0 on node02ob20 (kqyg3f) to use vlan 5002
 MAAS: Successfully set eth1 on node02ob20 (kqyg3f) to use vlan 5002
 MAAS: Successfully set eth0 on node03ob20 (4y3h8c) to use vlan 5002
 MAAS: Successfully set eth1 on node03ob20 (4y3h8c) to use vlan 5002
 MAAS: Successfully set eth0 on node04ob20 (4y3h8d) to use vlan 5002
 MAAS: Successfully set eth1 on node04ob20 (4y3h8d) to use vlan 5002
 MAAS: Successfully set eth0 on node05ob20 (erfb86) to use vlan 5002
 MAAS: Successfully set eth1 on node05ob20 (erfb86) to use vlan 5002
 MAAS: Successfully set eth0 on node06ob20 (4ewpx6) to use vlan 5002
 MAAS: Successfully set eth1 on node06ob20 (4ewpx6) to use vlan 5002
 MAAS: Successfully set eth0 on node07ob20 (4y3h8g) to use vlan 5002
 MAAS: Successfully set eth1 on node07ob20 (4y3h8g) to use vlan 5002
 MAAS: Successfully set eth0 on node08ob20 (4y3h8h) to use vlan 5002
 MAAS: Successfully set eth1 on node08ob20 (4y3h8h) to use vlan 5002
 MAAS: Successfully set eth0 on node09ob20 (4y3h8k) to use vlan 5002
 MAAS: Successfully set eth1 on node09ob20 (4y3h8k) to use vlan 5002
 MAAS: Successfully set eth0 on node10ob20 (tsq84y) to use vlan 5002
 MAAS: Successfully set eth1 on node10ob20 (tsq84y) to use vlan 5002

Successfully configured OrangeBox20 for Single Network Mode!

If link does not exist:

$ ./network-mode.sh -s

Configuring OrangeBox20 for Single Network mode:

 Logging in as admin to maas server @ http://172.27.20.1/MAAS...OK!

 Getting state of nodes on OrangeBox20

  node01ob20 Ready
  node03ob20 Ready
  node04ob20 Ready
  node07ob20 Ready
  node08ob20 Ready
  node09ob20 Ready
  node02ob20 Ready
  node05ob20 Ready
  node06ob20 Ready
  node10ob20 Ready

 Mikrotik: Successfully configured router for Single Network Mode!

 MAAS: Successfully set eth0 on node01ob20 (4y3h8a) to use vlan 5002
 MAAS: Successfully set eth1 on node01ob20 (4y3h8a) to use vlan 5002
 MAAS: Successfully set eth0 on node02ob20 (kqyg3f) to use vlan 5002
 MAAS: Successfully set eth1 on node02ob20 (kqyg3f) to use vlan 5002
 MAAS: Successfully set eth0 on node03ob20 (4y3h8c) to use vlan 5002
 MAAS: Successfully set eth1 on node03ob20 (4y3h8c) to use vlan 5002
 MAAS: Successfully set eth0 on node04ob20 (4y3h8d) to use vlan 5002
 MAAS: Successfully set eth1 on node04ob20 (4y3h8d) to use vlan 5002
 MAAS: Successfully set eth0 on node05ob20 (erfb86) to use vlan 5002
 MAAS: Successfully set eth1 on node05ob20 (erfb86) to use vlan 5002
 MAAS: Successfully set eth0 on node06ob20 (4ewpx6) to use vlan 5002
 MAAS: Successfully set eth1 on node06ob20 (4...

Read more...

Unmerged revisions

22. By Craig Bender

Check for existing links before updating link to subnet, otherwise an alias gets created

21. By Craig Bender

Fixed network mode script

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'network/network-mode.sh'
2--- network/network-mode.sh 2016-08-04 05:00:27 +0000
3+++ network/network-mode.sh 2017-03-06 03:49:13 +0000
4@@ -1,10 +1,10 @@
5 #!/bin/bash
6-#version 0.1
7+#version 0.2
8 #
9 # Script to configure the switch to be a single or dual vlan
10 # Copyright (C) 2016 Canonical Ltd.
11 #
12-# Authors: Gary MacKenzie <gary.mackenzie@canonical.com>
13+# Authors: Gary MacKenzie <gary.mackenzie@canonical.com>, Craig Bender <craig.bender@canonical.com>
14 #
15 # This program is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17@@ -19,39 +19,49 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20
21-# Get OrangeBox number
22-#
23-
24-OB=`hostname | cut -c 10-`
25-BYTE1=$(echo $OB | cut -c 1)
26-BYTE2=$(echo $OB | cut -c 2-)
27+TRUE=true
28+FALSE=false
29+command -v jq > /dev/null 2>&1 || sudo apt install jq -y
30+command -v jq > /dev/null 2>&1 || { echo "This script requires jq";exit 1; }
31+export CO='\e[1;38;2;255;148;1m'
32+
33+OB_NUM=${HOSTNAME:9}
34+OB_LOG="/var/log/OrangeBox${OB_NUM}.log"
35+[[ -f ${OB_LOG} ]] && sudo chmod a+w+r ${OB_LOG} || { sudo touch ${OB_LOG};sudo chmod a+w+r ${OB_LOG}; }
36+
37+BYTE1=${OB_NUM:0:1}
38+BYTE2=${OB_NUM:1:2}
39
40 # Parse the variables for the OrangeBox number to eliminate any zero's at the beginning of the number.
41 #
42-if [ $BYTE1 -eq 0 ]
43-then
44- OB=$BYTE2
45-fi
46-
47-# Set the network subnet variables
48-#
49-
50-PLUS1=`expr $OB + 1`
51-PLUS2=`expr $OB + 2`
52-PLUS3=`expr $OB + 3`
53-
54-if (($# == 0)); then
55- echo "Usage: ./network_mode.sh mode
56-Mode:
57+[[ $BYTE1 -eq 0 ]] && OB_NUM=$BYTE2
58+
59+OB_ROUTER="172.27.$((${OB_NUM}+1)).254"
60+
61+# Set the MAAS URL for the admin login setup
62+MAAS_URL=http://172.27.${OB_NUM}.1/MAAS
63+[[ -z ${MAAS_PROFILE} ]] && MAAS_PROFILE=admin
64+
65+Usage() {
66+local help='
67+Usage: '${0##*/}' <options>
68+
69+Options:
70 -s|--single-network Configure primary and secondary interfaces on nodes 1-10 on a single VLAN
71- -d|--dual-network Configure secondary interfaces on ndoes 1-10 on a second VLAN"
72- exit 2
73-fi
74+ -d|--dual-network Configure secondary interfaces on ndoes 1-10 on a second VLAN
75+ -f|--force Run even if nodes are not in Ready state
76+
77+'
78+echo "${help}"
79+}
80
81 SINGLENETWORK=0
82 DUALNETWORK=0
83+FORCE=0
84+PARTIAL=0
85+[[ -z ${1} ]] && { Usage;exit 2; }
86
87-ARGS=`getopt -o sd --long single-network,dual-network -- "$@"`
88+ARGS=`getopt -o sdf --long single-network,dual-network,force -- "$@"`
89 eval set -- "$ARGS"
90
91 while true ; do
92@@ -64,93 +74,175 @@
93 DUALNETWORK=1
94 shift
95 ;;
96+ -f|--force)
97+ FORCE=1
98+ shift
99+ ;;
100 --)
101 shift
102 break
103 ;;
104- *) echo "Usage: ./network_mode.sh mode
105-Mode:
106- -s|--single-network Configure primary and secondary interfaces on nodes 1-10 on a single VLAN
107- -d|--dual-network Configure secondary interfaces on ndoes 1-10 on a second VLAN"
108- exit 2 ;;
109+ */?) Usage;exit 2 ;;
110 esac
111 done
112
113-if [ "$SINGLENETWORK" -eq 1 ];
114-then
115- echo "Configuring for 1 Network mode..."
116-ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /interface ethernet set master-port=ether2-master-local 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
117-
118-echo
119-echo "All ports configured for 1 network mode"
120- ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /beep
121-#Get Orangebox number from the hostname and place into the configuration file
122-ob_number=`hostname | cut -c 10- -`
123-
124-# Set the MAAS URL for the admin login setup
125-MAAS_URL=http://172.27.${ob_number}.1/MAAS
126-
127-apikey=`sudo maas-region apikey --username admin | tail -n1`
128-maas login admin $MAAS_URL $apikey
129-
130-declare maas_fabric=()
131-for fab_ric in $(maas admin fabrics read |grep name|grep fabric|awk -F\" '{print $4}')
132-do
133- echo "Fabric $fab_ric"
134- maas_fabric=("${maas_fabric[@]}" "$fab_ric")
135-done
136-
137-vlanid=$(maas admin vlans read "${maas_fabric[1]}" |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
138-sub_net="172.27.${ob_number}.0/23"
139-
140-for nodenum in {01..10}
141-do
142- system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
143- maas admin interface update $system_id eth1 vlan=$vlanid
144- maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
145-done
146- exit
147-fi
148-
149-if [ "$DUALNETWORK" -eq 1 ];
150-then
151- echo "Configuring for 2 Network mode..."
152-ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /interface ethernet set master-port=ether1-master-local 4,6,8,10,12,14,16,18,20,22
153-
154-ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /interface ethernet set master-port=ether2-master-local 5,7,9,11,13,15,17,19,21,23
155-
156-echo
157-echo "All ports configured for 2 network mode"
158- ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /beep
159-#Get Orangebox number from the hostname and place into the configuration file
160-ob_number=`hostname | cut -c 10- -`
161-
162-# Set the MAAS URL for the admin login setup
163-MAAS_URL=http://172.27.${ob_number}.1/MAAS
164-
165-apikey=`sudo maas-region apikey --username admin | tail -n1`
166-maas login admin $MAAS_URL $apikey
167-
168-declare maas_fabric=()
169-for fab_ric in $(maas admin fabrics read |grep name|grep fabric|awk -F\" '{print $4}')
170-do
171- echo "Fabric $fab_ric"
172- maas_fabric=("${maas_fabric[@]}" "$fab_ric")
173-done
174-
175-vlanid=$(maas admin vlans read "${maas_fabric[2]}" |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
176-sub_net="172.27.((ob_number+2)).0/23"
177-
178-# Configure second usb interface for second fabric and proper subnet
179-#
180-
181-for nodenum in {01..10}
182-do
183- system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
184- maas admin interface update $system_id eth1 vlan=$vlanid
185- maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net"
186-done
187-echo "MAAS re-adjusted the nodes to work with dual vlan"
188-sleep 5
189- exit
190-fi
191+[[ ${SINGLENETWORK} = 0 && ${DUALNETWORK} = 0 ]] && { printf "\nPlease select either -s or -d\n\n";Usage;exit 2; }
192+[[ ${SINGLENETWORK} = 1 && ${DUALNETWORK} = 1 ]] && { printf "\nPlease select either -s or -d\n\n";Usage;exit 2; }
193+
194+MAAS_APIKEY=$(sudo maas apikey --username=${MAAS_PROFILE})
195+[[ $? -eq 0 ]] || { echo "Failed to apikey for maas profile @ ${MAAS_PROFILE}";exit 1; }
196+
197+
198+[[ $SINGLENETWORK -eq 1 ]] && printf "\n\e[1mConfiguring ${CO}OrangeBox${OB_NUM}\e[0m\e[1m for \e[4m\e[1;36mSingle\e[0m\e[1m Network mode:\e[0m\n"
199+[[ $DUALNETWORK -eq 1 ]] && printf "\n\e[1mConfiguring OrangeBox${OB_NUM} for \e[4m\e[1;35mDual\e[0m\e[1m Network mode:\e[0m\n"
200+[[ ${FORCE} -eq 0 ]] || printf "\n\t\e[1;33mForce mode selected\e[0m\n"
201+#Login to maas
202+printf "\n\tLogging in as ${MAAS_PROFILE} to maas server @ ${MAAS_URL}..."
203+maas login ${MAAS_PROFILE} ${MAAS_URL} ${MAAS_APIKEY} >> ${OB_LOG} 2>&1
204+[[ $? -eq 0 ]] && printf '\e[1;32mOK!\e[0m\n\n' || { printf "\e[1;31mFAILED!\e[0m\n\n\e[1mFailed to login in to maas server @ ${MAAS_URL}\e[0m\n\n";exit 1; }
205+printf "\n\t\e[1mGetting state of nodes on ${CO}OrangeBox${OB_NUM}\e[0m\n\n"
206+MAAS_MACHINE_STATES=$(maas admin machines read)
207+[[ $? -eq 0 ]] || { printf "\e[1;31mFAILED!\e[0m\n\n\e[1mFailed to get state of nodes from maas server @ ${MAAS_URL}\e[0m\n\n";exit 1; }
208+
209+if [[ ${FORCE} -eq 0 ]];then
210+
211+
212+ if [[ -n $(echo $MAAS_MACHINE_STATES|jq -r '.[]|.hostname+"\t"+.status_name'|sed -E -e '/vm|Ready/d') ]];then
213+ printf '\n\t\e[1;31mERROR:\e[0m\e[1m This script requires that all nodes are in a "Ready" or "Broken" state\e[0m\n\n'
214+ printf '\t\tPlease ensure the all nodes are "Ready" and try again.\n\n'
215+ echo $MAAS_MACHINE_STATES|jq -r '.[]|"\t\t"+.hostname+" \t"+.status_name'|sed -E -e '/vm/d' -e '/Ready|Broken/! s/ \t.*$/'$(printf '\e[1;33m')'&'$(printf '\e[0m')'/g' -e 's/Ready|Broken/'$(printf '\e[1;32m')'&'$(printf '\e[0m')'/g'
216+ printf '\n'
217+ exit 3
218+ else
219+ echo $MAAS_MACHINE_STATES|jq -r '.[]|"\t\t"+.hostname+" \t"+.status_name'|sed -E -e '/vm/d' -e '/Ready|Broken/! s/ \t.*$/'$(printf '\e[1;33m')'&'$(printf '\e[0m')'/g' -e 's/Ready|Broken/'$(printf '\e[1;32m')'&'$(printf '\e[0m')'/g'
220+ printf '\n'
221+ fi
222+fi
223+
224+if [[ $SINGLENETWORK -eq 1 ]];then
225+ ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /interface ethernet set master-port=ether2-master-local 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
226+ [[ $? -eq 0 ]] && { printf "\t\e[1;32mMikrotik: \e[0m\e[1mSuccessfully configured router for \e[1;36mSingle\e[0m\e[1m Network Mode!\e[0m\n"; ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /beep; } || { printf "\n\e[1;31mMikrotik: \e[0m\e[1m Failed to set the master-port as ether2-master-local for all ports on the Mikrotik router\e[0m\n\n";exit 1; }
227+
228+
229+elif [[ $DUALNETWORK -eq 1 ]];then
230+ ETHER_1_OK=${FALSE}
231+ ETHER_2_OK=${FALSE}
232+ ETH1_PORTS="$(seq 4 2 22)"
233+ ETH2_PORTS="$(seq 5 2 23)"
234+
235+ ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /interface ethernet set master-port=ether1-master-local 4,6,8,10,12,14,16,18,20,22
236+ [[ $? -eq 0 ]] && ETHER_1_OK=${TRUE} || ETHER_1_OK=${FALSE}
237+
238+ ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /interface ethernet set master-port=ether2-master-local 5,7,9,11,13,15,17,19,21,23
239+ [[ $? -eq 0 ]] && ETHER_2_OK=${TRUE} || ETHER_2_OK=${FALSE}
240+
241+ [[ ${ETHER_1_OK} = ${FALSE} ]] && { echo -e "\n\t\e[1;31mMikrotik:\e[0m\e[1m Failed to set master port to ether1-master-local for for ports:\e[0m "${ETH1_PORTS};exit 1; }
242+ [[ ${ETHER_2_OK} = ${FALSE} ]] && { echo -e "\n\t\e[1;31mMikrotik:\e[0m\e[1m Failed to set master port to ether2-master-local for for ports:\e[0m "${ETH2_PORTS};exit 1; }
243+ [[ ${ETHER_1_OK} = ${TRUE} && ${ETHER_2_OK} = ${TRUE} ]] && { printf "\n\t\e[1;32mMikrotik:\e[0m\e[1m Successfully configured router for \e[1;35mDual\e[0m\e[1m Network Mode!\e[0m\n"; ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /beep; }
244+
245+fi
246+
247+MAAS_SUB_NET_1="172.27.${OB_NUM}.0/23"
248+MAAS_SUB_NET_2="172.27.$(($OB_NUM+2)).0/23"
249+
250+eval $(maas admin subnets read |jq -r '.[]|select(.cidr=="'${MAAS_SUB_NET_1}'")|.vlan|"MAAS_VLAN_ID_1="+(.id|tostring),"MAAS_FABRIC_ID_1="+(.fabric_id|tostring)')
251+[[ -z ${MAAS_FABRIC_ID_1} ]] && { echo "Failed to fetch fabric id 1 from maas server @ ${MAAS_URL}";exit 1; }
252+[[ -z ${MAAS_VLAN_ID_1} ]] && { echo "Failed to fetch vlan id 1 from maas server @ ${MAAS_URL}";exit 1; }
253+
254+eval $(maas admin subnets read |jq -r '.[]|select(.cidr=="'${MAAS_SUB_NET_2}'")|.vlan|"MAAS_VLAN_ID_2="+(.id|tostring),"MAAS_FABRIC_ID_2="+(.fabric_id|tostring)')
255+[[ -z ${MAAS_FABRIC_ID_2} ]] && { echo "Failed to fetch fabric id 2 from maas server @ ${MAAS_URL}";exit 1; }
256+[[ -z ${MAAS_VLAN_ID_2} ]] && { echo "Failed to fetch vlan id 2 from maas server @ ${MAAS_URL}";exit 1; }
257+
258+for node in {01..10};do
259+ MAAS_NODE_NAME="node${node}ob${OB_NUM}"
260+ eval $(echo $MAAS_MACHINE_STATES |jq -r '.[]|select(.hostname=="'${MAAS_NODE_NAME}'")|"MAAS_SYSID="+.system_id,"MAAS_STATUS="+.status_name')
261+ maas admin interface update ${MAAS_SYSID} eth0 vlan=${MAAS_VLAN_ID_1} subnet=${MAAS_SUB_NET_1} mode=auto>> ${OB_LOG} 2>&1
262+ if [[ $? -eq 0 ]];then
263+ printf "\t\e[1;32mMAAS: \e[0mSuccessfully set \e[1;36meth0\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to use vlan \e[1;36m${MAAS_VLAN_ID_1}\e[0m\n"
264+ else
265+ printf "\t\e1;31mMAAS: \e[0mFailed to set \e[1;36meth0\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to vlan \e[1;36m${MAAS_VLAN_ID_1}\e[0m (${MAAS_SUB_NET_1})\e[0m\n\n"
266+ [[ ${FORCE} -eq 0 ]] && exit 2
267+ fi
268+
269+ if [[ $SINGLENETWORK -eq 1 ]];then
270+ maas admin interface update ${MAAS_SYSID} eth1 vlan=${MAAS_VLAN_ID_1} >> ${OB_LOG} 2>&1
271+ if [[ $? -eq 0 ]];then
272+ printf "\t\e[1;32mMAAS: \e[0mSuccessfully set \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to use vlan \e[1;36m${MAAS_VLAN_ID_1}\e[0m\n"
273+ else
274+ printf "\t\e1;31mMAAS: \e[0mFailed to set \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to vlan \e[1;36m${MAAS_VLAN_ID_1}\e[0m (${MAAS_SUB_NET_1})\e[0m\n\n"
275+ [[ ${FORCE} -eq 0 ]] && exit 2
276+ fi
277+ elif [[ $DUALNETWORK -eq 1 ]];then
278+ maas admin interface update ${MAAS_SYSID} eth1 vlan=${MAAS_VLAN_ID_2} >> ${OB_LOG} 2>&1
279+ if [[ $? -eq 0 ]];then
280+ printf "\t\e[1;32mMAAS: \e[0mSuccessfully set \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to use vlan \e[1;35m${MAAS_VLAN_ID_2}\e[0m\n"
281+ else
282+ printf "\t\e1;31mMAAS: \e[0mFailed to set \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to vlan \e[1;35m${MAAS_VLAN_ID_2}\e[0m (${MAAS_SUB_NET_2})\e[0m\n\n"
283+ [[ ${FORCE} -eq 0 ]] && exit 2
284+ fi
285+ fi
286+done
287+ #update machine states
288+ MAAS_MACHINE_STATES=$(maas admin machines read)
289+for node in {01..10};do
290+ MAAS_NODE_NAME="node${node}ob${OB_NUM}"
291+ eval $(echo $MAAS_MACHINE_STATES |jq -r '.[]|select(.hostname=="'${MAAS_NODE_NAME}'")|"MAAS_SYSID="+.system_id,"MAAS_STATUS="+.status_name')
292+ if [[ -z $(echo $MAAS_MACHINE_STATES|jq -r '.[]|select(.system_id=="'${MAAS_SYSID}'")|.interface_set[]|select(.name=="eth0")|.links[]') ]];then
293+ if [[ ${MAAS_STATUS} = Ready || ${MAAS_STATUS} = Broken ]];then
294+ maas admin interface link-subnet ${MAAS_SYSID} eth0 mode=auto subnet="${MAAS_SUB_NET_1}" >> ${OB_LOG} 2>&1
295+ if [[ $? -eq 0 ]];then
296+ printf "\t\e[1;32mMAAS: \e[0mSuccessfully linked \e[1;36meth0\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to subnet \e[1;36m${MAAS_SUB_NET_1}\e[0m\e[0m\n"
297+ else
298+ printf "\t\t\e[1;31mMAAS: \e[0mFailed to link \e[1;36meth0\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to subnet \e[1;36m${MAAS_SUB_NET_1}\e[0m\e[0m\n\n"
299+ [[ ${FORCE} -eq 0 ]] && exit 2
300+ fi
301+ else
302+ export PARTIAL=1
303+ printf '\t\e[1;33mMAAS:\e[0m Cannot link \e[1;36meth0\e[0m on '${CO}${MAAS_NODE_NAME}'\e[0m ('${MAAS_SYSID}') to subnet \e[1;36m'${MAAS_SUB_NET_1}'\e[0m because node is in a \e[1;33m'${MAAS_STATUS}'\e[0m state\n'
304+ printf '\n'
305+
306+ fi
307+ fi
308+
309+
310+ if [[ $SINGLENETWORK -eq 1 ]] && [[ -z $(echo $MAAS_MACHINE_STATES|jq -r '.[]|select(.system_id=="'${MAAS_SYSID}'")|.interface_set[]|select(.name=="eth1")|.links[]') ]];then
311+ if [[ ${MAAS_STATUS} = Ready || ${MAAS_STATUS} = Broken ]];then
312+ maas admin interface link-subnet ${MAAS_SYSID} eth1 mode=auto subnet="${MAAS_SUB_NET_1}" >> ${OB_LOG} 2>&1
313+ if [[ $? -eq 0 ]];then
314+ printf "\t\e[1;32mMAAS: \e[0mSuccessfully linked \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to subnet \e[1;36m${MAAS_SUB_NET_1}\e[0m\e[0m\n"
315+ else
316+ printf "\t\t\e[1;31mMAAS: \e[0mFailed to link \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to subnet \e[1;36m${MAAS_SUB_NET_1}\e[0m\e[0m\n\n"
317+ [[ ${FORCE} -eq 0 ]] && exit 2
318+ fi
319+ else
320+ export PARTIAL=1
321+ printf '\t\e[1;33mMAAS:\e[0m Cannot link \e[1;35meth1\e[0m on '${CO}${MAAS_NODE_NAME}'\e[0m ('${MAAS_SYSID}') to subnet \e[1;36m'${MAAS_SUB_NET_1}'\e[0m because node is in a \e[1;33m'${MAAS_STATUS}'\e[0m state\n'
322+ printf '\n'
323+
324+ fi
325+ elif [[ $DUALNETWORK -eq 1 ]] && [[ -z $(echo $MAAS_MACHINE_STATES|jq -r '.[]|select(.system_id=="'${MAAS_SYSID}'")|.interface_set[]|select(.name=="eth1")|.links[]') ]];then
326+ if [[ ${MAAS_STATUS} = Ready || ${MAAS_STATUS} = Broken ]];then
327+ maas admin interface link-subnet ${MAAS_SYSID} eth1 mode=auto subnet="${MAAS_SUB_NET_2}" >> ${OB_LOG} 2>&1
328+ if [[ $? -eq 0 ]];then
329+ printf "\t\e[1;32mMAAS: \e[0mSuccessfully linked \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to subnet \e[1;35m${MAAS_SUB_NET_2}\e[0m\e[0m\n"
330+ else
331+ printf "\t\t\e[1;31mMAAS: \e[0mFailed to link \e[1;35meth1\e[0m on ${CO}${MAAS_NODE_NAME}\e[0m (${MAAS_SYSID}) to subnet \e[1;35m${MAAS_SUB_NET_2}\e[0m\e[0m\n\n"
332+ [[ ${FORCE} -eq 0 ]] && exit 2
333+ fi
334+ else
335+ export PARTIAL=1
336+ printf '\t\e[1;33mMAAS:\e[0m Cannot link \e[1;35meth1\e[0m on '${CO}${MAAS_NODE_NAME}'\e[0m ('${MAAS_SYSID}') to subnet \e[1;35m'${MAAS_SUB_NET_2}'\e[0m because node is in a \e[1;33m'${MAAS_STATUS}'\e[0m state\n'
337+ printf '\n'
338+
339+ fi
340+ fi
341+
342+done
343+[[ $SINGLENETWORK -eq 1 && PARTIAL -eq 0 ]] && printf "\n\e[1;32mSuccessfully\e[0m\e[1m configured ${CO}OrangeBox${OB_NUM}\e[0m\e[1m for \e[1;36mSingle\e[0m\e[1m Network Mode!\e[0m\n\n"
344+[[ $DUALNETWORK -eq 1 && PARTIAL -eq 0 ]] && printf "\n\e[1;32mSuccessfully\e[0m\e[1m configured ${CO}OrangeBox${OB_NUM}\e[0m\e[1m for \e[1;35mDual\e[0m\e[1m Network Mode!\e[0m\n\n"
345+[[ $SINGLENETWORK -eq 1 && PARTIAL -eq 1 ]] && printf "\n\e[1;33mPartially\e[0m\e[1m configured ${CO}OrangeBox${OB_NUM}\e[0m\e[1m for \e[1;36mSingle\e[0m\e[1m Network Mode.\e[0m\n\n"
346+[[ $DUALNETWORK -eq 1 && PARTIAL -eq 1 ]] && printf "\n\e[1;33mPartially\e[0m\e[1m configured ${CO}OrangeBox${OB_NUM}\e[0m\e[1m for \e[1;35mDual\e[0m\e[1m Network Mode.\e[0m\n\n"
347+
348+
349+unset PLUS1 PLUS2 PLUS3 BYTE1 BYTE2 MAAS_SYSID MAAS_FABRIC_ID_1 MAAS_VLAN_ID_1 MAAS_SUB_NET_1 MAAS_FABRIC_ID_2 MAAS_VLAN_ID_2 MAAS_SUB_NET_2 MAAS_NODE_NAME MAAS_STATUS ETHER_1_OK ETHER_2_OK ETH1_PORTS ETH2_PORTS FORCE SINGLENETWORK DUALNETWORK PARTIAL MAAS_MACHINE_STATES OB_ROUTER
350+

Subscribers

People subscribed via source and target branches

to all changes: