Merge lp:~cpe-sa/obinstall/misc-next-fixes into lp:obinstall/next
- misc-next-fixes
- Merge into next
Status: | Needs review |
---|---|
Proposed branch: | lp:~cpe-sa/obinstall/misc-next-fixes |
Merge into: | lp:obinstall/next |
Diff against target: |
695 lines (+347/-215) 7 files modified
03-maas_setup_environment.sh (+11/-9) 04-add_virtual_nodes.sh (+16/-9) 04a-mod_virtual_nodes.sh (+1/-1) 05-add_physical_nodes.sh (+50/-51) 05a-mod_physical_nodes.sh (+24/-24) PACKAGES.list (+1/-0) network/network-mode.sh (+244/-121) |
To merge this branch: | bzr merge lp:~cpe-sa/obinstall/misc-next-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Iatrou | Needs Fixing | ||
Fatih Nar (community) | Approve | ||
Review via email: mp+319374@code.launchpad.net |
Commit message
Description of the change
Fix grep errors where multiple macs or system ids were returned
Enlist VMs by using chassis vs machine
Commission all VMs at once
Create three zones so things like sharding swift work better
Add jq to OB Package list
- 25. By Craig Bender
-
Fix a couple errors with 04 script
- 26. By Craig Bender
-
Add sleep after adding chassis so machines show up before attempting other operations
- 27. By Craig Bender
-
Juju 2.1 seems to have a problem bootstraping with the current obvm disk config (20+2). Removing 2 GB disk and also setting disk controller to scsi
Fatih Nar (fenar-e) wrote : | # |
Thanks for Hard Work!
Craig Bender (craig-bender) wrote : | # |
True for the 04-add script, but that's when I was trying to figure out when
juju wouldn't bootstrap. There is some code changes in 04, that if left
unchanged, breaks the ability to add vms. Mainly around grep returning
multiple mac and system ids.
On Thu, Mar 9, 2017 at 6:04 AM, Michael Iatrou <<email address hidden>
> wrote:
> This patch mixes whitespace adjustments with actual code changes, which is
> problematic to the review. Consider one patchset for fixes/enhancements,
> and a separate one for trivial whitespace changes.
> --
> https:/
> Your team CPE SA is requested to review the proposed merge of
> lp:~cpe-sa/obinstall/misc-next-fixes into lp:obinstall/next.
>
--
*Craig Bender*
Solutions Architect
*Canonical*
Direct Dial: +1 702-595-5899
Ubuntu - Linux for Human Beings
www.canonical.com - www.ubuntu.com
Michael Iatrou (michael.iatrou) wrote : | # |
Running 05-add_
+ [[ 08 -lt 4 ]]
./05-add_
+ [[ 08 -ge 4 ]]
./05-add_
+ [[ 08 -ge 7 ]]
./05-add_
./05-add_
This happens because of the conversion in line 58.
Please also consider splitting the patch in two, separating functional changes from white space changes (ideally in that order).
- 28. By Craig Bender
-
Fixed hasty zone decision stanza, removed unholy trinity of echo+grep+cut
Michael Iatrou (michael.iatrou) wrote : | # |
Just attempted to review network/
Color-coding the script output makes it pretty, but it makes reading the script itself very painful.
Highly recommended to revert it!
Craig Bender (craig-bender) wrote : | # |
Really? Color coding is only in the printf statements, nothing that
actually runs code.
I don't get why we seem to like set -x and no error handling as
opposed to making things look presentable and gives easy to understand
feedback. I have a source file that I can change the escape sequences
to variables which can make things easier to read since it's less
characters.
On Thu, Mar 16, 2017 at 5:22 AM, Michael Iatrou
<email address hidden> wrote:
> Just attempted to review network/
> Color-coding the script output makes it pretty, but it makes reading the script itself very painful.
> Highly recommended to revert it!
> --
> https:/
> Your team CPE SA is subscribed to branch lp:obinstall/next.
--
Craig Bender
Solutions Architect
Canonical
Direct Dial: +1 702-595-5899
Ubuntu - Linux for Human Beings
www.canonical.com - www.ubuntu.com
Matt Jarvis (matt-jarvis) wrote : | # |
Totally agree with you re error handling and set -x, thats definitely on
the list of things to fix through our working group. Ideally I'd also like
to standardise on output formatting so perhaps that piece might be best
left until we decide as a group what our direction of travel should be. If
non-functional changes make code harder to review and maintain, then I'd
suggest Michael makes a valid point.
On 16 Mar 2017 17:03, "Craig Bender" <email address hidden> wrote:
Really? Color coding is only in the printf statements, nothing that
actually runs code.
I don't get why we seem to like set -x and no error handling as
opposed to making things look presentable and gives easy to understand
feedback. I have a source file that I can change the escape sequences
to variables which can make things easier to read since it's less
characters.
On Thu, Mar 16, 2017 at 5:22 AM, Michael Iatrou
<email address hidden> wrote:
> Just attempted to review network/
> Color-coding the script output makes it pretty, but it makes reading the
script itself very painful.
> Highly recommended to revert it!
> --
> https:/
> Your team CPE SA is subscribed to branch lp:obinstall/next.
--
Craig Bender
Solutions Architect
Canonical
Direct Dial: +1 702-595-5899
Ubuntu - Linux for Human Beings
www.canonical.com - www.ubuntu.com
https:/
You are subscribed to branch lp:obinstall/next.
Craig Bender (craig-bender) wrote : | # |
So if someone doesn't understand jq, does that mean the code is harder
to review if it spawns three processes, like awk + sed + grep, to get
the same info?
I thought the point here was to make the scripts better. Better in my
mind means it's easier for the end user to determine what is
happening.
Better will definitely mean that reviewers have to learn something
new. Where some see \e[1m I see "bold", or green, or underline.
At any rate, I'll resubmit, but formatting after the fact is messy and
most likely will never get done.
On Thu, Mar 16, 2017 at 9:45 AM, Matt Jarvis <email address hidden> wrote:
> Totally agree with you re error handling and set -x, thats definitely on
> the list of things to fix through our working group. Ideally I'd also like
> to standardise on output formatting so perhaps that piece might be best
> left until we decide as a group what our direction of travel should be. If
> non-functional changes make code harder to review and maintain, then I'd
> suggest Michael makes a valid point.
>
> On 16 Mar 2017 17:03, "Craig Bender" <email address hidden> wrote:
>
> Really? Color coding is only in the printf statements, nothing that
> actually runs code.
>
> I don't get why we seem to like set -x and no error handling as
> opposed to making things look presentable and gives easy to understand
> feedback. I have a source file that I can change the escape sequences
> to variables which can make things easier to read since it's less
> characters.
>
> On Thu, Mar 16, 2017 at 5:22 AM, Michael Iatrou
> <email address hidden> wrote:
>> Just attempted to review network/
>> Color-coding the script output makes it pretty, but it makes reading the
> script itself very painful.
>> Highly recommended to revert it!
>> --
>> https:/
>> Your team CPE SA is subscribed to branch lp:obinstall/next.
>
>
>
> --
> Craig Bender
> Solutions Architect
> Canonical
> Direct Dial: +1 702-595-5899
> Ubuntu - Linux for Human Beings
> www.canonical.com - www.ubuntu.com
>
> https:/
> You are subscribed to branch lp:obinstall/next.
>
> --
> https:/
> Your team CPE SA is subscribed to branch lp:obinstall/next.
--
Craig Bender
Solutions Architect
Canonical
Direct Dial: +1 702-595-5899
Ubuntu - Linux for Human Beings
www.canonical.com - www.ubuntu.com
- 29. By Craig Bender
-
Remove color coding
- 30. By Craig Bender
-
Remove stray ctrl character
Michael Iatrou (michael.iatrou) wrote : | # |
The scripts should have two goals:
1. Make it easy to use them and diagnose problems.
2. Make it easy to read, debug and expand.
The suggestion is that we clearly report issues during the execution of a script without the use of -x and without color coding.
In terms of readability, ${0##*/} is an unnecessary obfuscation, 'basename' offers the same functionality, it's less typo prone and less esoteric.
On the other hand, jq has an advantage over grep + awk + ... both in terms of readability *and* correctness, thumbs up!
Craig Bender (craig-bender) wrote : | # |
We can debate the esoteric nature and correctness of built-in bash
parameter expansion/
over beers. ;)
On Thu, Mar 16, 2017 at 10:47 AM, Michael Iatrou
<email address hidden> wrote:
> The scripts should have two goals:
> 1. Make it easy to use them and diagnose problems.
> 2. Make it easy to read, debug and expand.
>
> The suggestion is that we clearly report issues during the execution of a script without the use of -x and without color coding.
> In terms of readability, ${0##*/} is an unnecessary obfuscation, 'basename' offers the same functionality, it's less typo prone and less esoteric.
> On the other hand, jq has an advantage over grep + awk + ... both in terms of readability *and* correctness, thumbs up!
>
> --
> https:/
> Your team CPE SA is subscribed to branch lp:obinstall/next.
--
Craig Bender
Solutions Architect
Canonical
Direct Dial: +1 702-595-5899
Ubuntu - Linux for Human Beings
www.canonical.com - www.ubuntu.com
Matt Jarvis (matt-jarvis) wrote : | # |
Great thread :) One of our goals should also definitely be to engender a
culture amongst this group where we can strongly debate all of these
positions whilst maintaining focus on what our end goals are. I think its
worth defining amongst ourselves exactly what our end goals are for
starting to do this work, so we can refer back to that wherever we have
conflicting positions.
On 16 Mar 2017 18:57, "Craig Bender" <email address hidden> wrote:
We can debate the esoteric nature and correctness of built-in bash
parameter expansion/
over beers. ;)
On Thu, Mar 16, 2017 at 10:47 AM, Michael Iatrou
<email address hidden> wrote:
> The scripts should have two goals:
> 1. Make it easy to use them and diagnose problems.
> 2. Make it easy to read, debug and expand.
>
> The suggestion is that we clearly report issues during the execution of a
script without the use of -x and without color coding.
> In terms of readability, ${0##*/} is an unnecessary obfuscation,
'basename' offers the same functionality, it's less typo prone and less
esoteric.
> On the other hand, jq has an advantage over grep + awk + ... both in
terms of readability *and* correctness, thumbs up!
>
> --
> https:/
> Your team CPE SA is subscribed to branch lp:obinstall/next.
--
Craig Bender
Solutions Architect
Canonical
Direct Dial: +1 702-595-5899
Ubuntu - Linux for Human Beings
www.canonical.com - www.ubuntu.com
https:/
You are subscribed to branch lp:obinstall/next.
Unmerged revisions
- 30. By Craig Bender
-
Remove stray ctrl character
- 29. By Craig Bender
-
Remove color coding
- 28. By Craig Bender
-
Fixed hasty zone decision stanza, removed unholy trinity of echo+grep+cut
- 27. By Craig Bender
-
Juju 2.1 seems to have a problem bootstraping with the current obvm disk config (20+2). Removing 2 GB disk and also setting disk controller to scsi
- 26. By Craig Bender
-
Add sleep after adding chassis so machines show up before attempting other operations
- 25. By Craig Bender
-
Fix a couple errors with 04 script
- 24. By Craig Bender
-
Fix several grep errors that were returning multiple macs,system ids, etc, add vms via chassis vs machines, add jq to package list
- 23. By Craig Bender
-
Add changing mikrotik /ip address vlans as appropriate for single or dual mode
- 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
1 | === modified file '03-maas_setup_environment.sh' |
2 | --- 03-maas_setup_environment.sh 2016-09-20 09:23:07 +0000 |
3 | +++ 03-maas_setup_environment.sh 2017-03-16 17:32:27 +0000 |
4 | @@ -48,7 +48,7 @@ |
5 | #Create the MAAS credentials |
6 | if [[ $(maas-region apikey --username admin 1>/dev/null 2>&1;echo $?) -eq 1 ]] |
7 | then |
8 | - maas-region createadmin --username admin --email maas-admin@example.com --password="admin" || true |
9 | + maas-region createadmin --username admin --email maas-admin@example.com --password="admin" || true |
10 | fi |
11 | |
12 | #get apikey variable |
13 | @@ -64,12 +64,12 @@ |
14 | maas admin ipranges create type=dynamic start_ip=${dhcp_low} end_ip=${dhcp_high} |
15 | maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id |
16 | do |
17 | - maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null |
18 | - if [[ $? -eq 0 ]] |
19 | - then |
20 | - maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g') |
21 | - maas admin vlan update ${maas_fabric} untagged dhcp_on=True primary_rack="OrangeBox${ob_number}" |
22 | - fi |
23 | + maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null |
24 | + if [[ $? -eq 0 ]] |
25 | + then |
26 | + maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g') |
27 | + maas admin vlan update ${maas_fabric} untagged dhcp_on=True primary_rack="OrangeBox${ob_number}" |
28 | + fi |
29 | done |
30 | maas admin subnet update ${sub_net} gateway_ip=${gateway_ip} dns_servers=${dns_servers} |
31 | |
32 | @@ -96,5 +96,7 @@ |
33 | sleep 5 |
34 | |
35 | #Add zones to MAAS for NUC's |
36 | -maas admin zone read zone1 || maas admin zones create name=zone1 description="Physical machines 1-5" |
37 | -maas admin zone read zone2 || maas admin zones create name=zone2 description="Physical machines 6-10" |
38 | +maas admin zone read zone0 || maas admin zones create name=zone0 description="Virtual Machines" |
39 | +maas admin zone read zone1 || maas admin zones create name=zone1 description="Physical machines 1-3" |
40 | +maas admin zone read zone2 || maas admin zones create name=zone2 description="Physical machines 4-6" |
41 | +maas admin zone read zone3 || maas admin zones create name=zone3 description="Physical machines 7-10" |
42 | |
43 | === modified file '04-add_virtual_nodes.sh' |
44 | --- 04-add_virtual_nodes.sh 2016-09-20 09:23:07 +0000 |
45 | +++ 04-add_virtual_nodes.sh 2017-03-16 17:32:27 +0000 |
46 | @@ -100,22 +100,26 @@ |
47 | maas admin zone read zone0 || maas admin zones create name=zone0 description="Virtual machines on node0" |
48 | |
49 | for i in {0..2}; do |
50 | - hostname="node00vm${i}ob${orangebox_number}.maas" |
51 | + hostname="node00vm${i}ob${orangebox_number}" |
52 | virsh destroy $hostname || true |
53 | virsh undefine $hostname || true |
54 | echo "INFO: Installing virtual machine" |
55 | if [ $i = 0 ]; then |
56 | - virt-install --debug --name $hostname --ram 6144 --disk=path=/srv/obvms/${hostname}-1.img,size=20 --disk=path=/srv/obvms/${hostname}-2.img,size=2 --vcpus=2 --os-type=linux --pxe --network=bridge=br0 --network=bridge=br0 --boot network --video=cirrus --graphics vnc|| true |
57 | + virt-install --noautoconsole --print-xml --name=$hostname --controller=scsi --ram=8192 --disk=path=/srv/obvms/${hostname}-1.img,bus=scsi,size=20 --vcpus=2 --network=bridge=br0 --network=bridge=br1 --boot=network --video=cirrus --graphics=vnc > /srv/obvms/${hostname}.xml|| true |
58 | else |
59 | - virt-install --debug --name $hostname --ram 4096 --disk=path=/srv/obvms/${hostname}-1.img,size=20 --disk=path=/srv/obvms/${hostname}-2.img,size=2 --vcpus=2 --os-type=linux --pxe --network=bridge=br0 --network=bridge=br0 --boot network --video=cirrus --graphics vnc|| true |
60 | + virt-install --noautoconsole --print-xml --name=$hostname --controller=scsi --ram 4096 --disk=path=/srv/obvms/${hostname}-1.img,bus=scsi,size=20 --vcpus=2 --network=bridge=br0 --network=bridge=br1 --boot=network --video=cirrus --graphics=vnc > /srv/obvms/${hostname}.xml|| true |
61 | fi |
62 | - virsh console $hostname || true |
63 | + virsh define /srv/obvms/${hostname}.xml |
64 | virsh autostart $hostname |
65 | - mac=$(virsh dumpxml $hostname | python -c 'import sys, lxml.etree; print list(lxml.etree.parse(sys.stdin).iter("mac"))[0].get("address")') |
66 | - system_id=$(maas admin nodes read mac_address=$mac | grep system_id | cut -d'"' -f4) |
67 | - |
68 | +done |
69 | +unset i |
70 | +printf "\nAdding virsh power chassis to MaaS...\n" |
71 | +maas admin machines add-chassis hostname=qemu+ssh://ubuntu@172.27.${orangebox_number}.1/system chassis_type=virsh prefix_filter='node00vm' |
72 | +sleep 3 |
73 | +for i in {0..2}; do |
74 | + hostname="node00vm${i}ob${orangebox_number}" |
75 | + system_id=$(maas admin machines read | jq -r '.[]|select(.hostname=="'${hostname}'")|.system_id') |
76 | if [ -n "$system_id" ]; then |
77 | - maas admin machine update $system_id hostname=$hostname power_type=virsh power_parameters_power_address=qemu+ssh://ubuntu@${internal_ip}/system power_parameters_power_id=$hostname |
78 | maas admin tag update-nodes "virtual" add=$system_id |
79 | case $i in |
80 | 0) |
81 | @@ -126,10 +130,13 @@ |
82 | ;; |
83 | esac |
84 | maas admin tag update-nodes use-fastpath-installer add=$system_id |
85 | - maas admin machine commission $system_id || true |
86 | maas admin nodes set-zone zone=zone0 nodes=$system_id |
87 | else |
88 | echo "ERROR: Could not find virtual machine in MAAS" 1>&2 |
89 | exit 1 |
90 | fi |
91 | done |
92 | +unset i |
93 | +printf '\nCommissioning virtual nodes...\n' |
94 | +maas admin machines accept-all |
95 | + |
96 | |
97 | === modified file '04a-mod_virtual_nodes.sh' |
98 | --- 04a-mod_virtual_nodes.sh 2016-09-20 09:23:07 +0000 |
99 | +++ 04a-mod_virtual_nodes.sh 2017-03-16 17:32:27 +0000 |
100 | @@ -40,7 +40,7 @@ |
101 | |
102 | for i in {0..2}; do |
103 | hostname="node00vm${i}ob${orangebox_number}" |
104 | - system_id=$(maas admin nodes read hostname=${hostname} |grep system_id | cut -d'"' -f4) |
105 | + system_id=$(maas admin nodes read hostname=${hostname} |grep -m1 system_id | cut -d'"' -f4) |
106 | sub_net="172.27.$(expr ${orangebox_number} + 2).0/23" |
107 | eth1_set=$(maas admin interface read $system_id eth1|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null 2>&1; echo $?) #0=already set, 1=needs setting |
108 | maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id |
109 | |
110 | === modified file '05-add_physical_nodes.sh' |
111 | --- 05-add_physical_nodes.sh 2016-12-07 17:37:21 +0000 |
112 | +++ 05-add_physical_nodes.sh 2017-03-16 17:32:27 +0000 |
113 | @@ -21,68 +21,67 @@ |
114 | set -aux |
115 | |
116 | # If user is not root then exit |
117 | -if [ "$(id -u)" != "0" ]; then |
118 | - echo "Must be run with sudo or by root" |
119 | - exit 77 |
120 | -fi |
121 | +[[ "$(id -u)" != "0" ]] && { echo "Must be run with sudo or by root";exit 77; } |
122 | |
123 | +[[ -f /var/log/${0##*/}.log ]] && { touch /var/log/${0##*/}.log;chmod a+rw /var/log/${0##*/}.log; } |
124 | +printf "Running ${0##*/}...\n" >> /var/log/${0##*/}.log 2>&1 |
125 | +command -v jq >> /var/log/${0##*/}.log 2>&1 || apt install jq -y >> /var/log/${0##*/}.log 2>&1 |
126 | # Get ob number |
127 | # |
128 | -ob_number=`hostname | cut -c 10- -` |
129 | +OB_NUM=${HOSTNAME:9} |
130 | |
131 | # Ensure the MAAS URL and CLUSTER UUID are set correctly |
132 | -MAAS_URL=http://172.27.${ob_number}.1/MAAS |
133 | -CLUSTER_UUID=`grep cluster_uuid /etc/maas/rackd.conf |awk '{print $2}'` |
134 | +MAAS_URL=http://172.27.${OB_NUM}.1/MAAS |
135 | +CLUSTER_UUID=$(awk '/cluster_uuid/{print $2}' /etc/maas/rackd.conf) |
136 | |
137 | # AMT Password set |
138 | AMT_PASSWORD=Password1+ |
139 | |
140 | -# set apikey variable |
141 | -apikey=`maas-region apikey --username admin | tail -n1` |
142 | +# set MAAS_APIKEY variable |
143 | +MAAS_APIKEY=$(maas apikey --username admin) |
144 | |
145 | # login to MAAS |
146 | -maas login admin $MAAS_URL $apikey |
147 | +maas login admin $MAAS_URL $MAAS_APIKEY >> /var/log/${0##*/}.log 2>&1 |
148 | + |
149 | +#Add tags to MAAS if not already there |
150 | +maas admin tags create name=physical >> /var/log/${0##*/}.log 2>&1 |
151 | +maas admin tags create name=use-fastpath-installer >> /var/log/${0##*/}.log 2>&1 |
152 | |
153 | # Add nodes to MAAS by accessing their amt interfaces |
154 | -for amtnum in {11..20} |
155 | -do |
156 | -ping -c 2 172.27.${ob_number}.${amtnum} |
157 | - |
158 | -# Get mac address for the corresponding amt ip address |
159 | -mac=`arp -n | grep 172.27.${ob_number}.$amtnum |awk '{print $3}'` |
160 | -echo "$mac belongs to node${amtnum}ob${ob_number} with ip 172.27.${ob_number}.${amtnum}" |
161 | - |
162 | -# Get the node number for the name out of the amt ip address |
163 | -nodenum=`expr ${amtnum} - 10` |
164 | -if [ ${nodenum} -lt 10 ]; then |
165 | - nodenum="0${nodenum}" |
166 | -fi |
167 | -echo "The name of the node is node${nodenum}ob${ob_number}" |
168 | - |
169 | -# Add each node to MAAS and commission it |
170 | -maas admin machines create architecture=amd64 power_type=amt power_parameters_power_address=172.27.${ob_number}.${amtnum} power_parameters_power_pass=Password1+ mac_addresses=${mac} hostname=node${nodenum}ob${ob_number} |
171 | - |
172 | -#Add tags to MAAS if not already there |
173 | -maas admin tags create name=physical || true |
174 | -maas admin tags create name=use-fastpath-installer || true |
175 | - |
176 | -#Get the system id of each node |
177 | -system_id=$(maas admin nodes read mac_address=$mac | grep system_id | cut -d'"' -f4) |
178 | -echo $system_id |
179 | - |
180 | -#Assign tags to each node |
181 | -maas admin tag update-nodes "physical" add=$system_id |
182 | -maas admin tag update-nodes "use-fastpath-installer" add=$system_id |
183 | - |
184 | -#Determine which zone a node will be in |
185 | -if [ ${nodenum} -lt 6 ]; then |
186 | - zone="zone1" |
187 | - else |
188 | - zone="zone2" |
189 | -fi |
190 | -echo "Node node${nodenum}ob${ob_number} is in $zone" |
191 | - |
192 | -#Add the nodes to their respective zone |
193 | -maas admin nodes set-zone zone=$zone nodes=$system_id |
194 | - |
195 | +for AMT_NUM in {11..20};do |
196 | + ping -c2 172.27.${OB_NUM}.${AMT_NUM} >> /var/log/${0##*/}.log 2>&1 |
197 | + |
198 | + # Get MAC address for the corresponding amt ip address |
199 | + MAC=$(arp -n |awk '/\<172.27.'${OB_NUM}.${AMT_NUM}'\>/{print $3;exit}') |
200 | + echo "${MAC} belongs to node${AMT_NUM}ob${OB_NUM} with ip 172.27.${OB_NUM}.${AMT_NUM}" |
201 | + |
202 | + # Get the node number for the name out of the amt ip address |
203 | + NODE_NUM=$((${AMT_NUM}-10)) |
204 | + [[ ${NODE_NUM} -lt 10 ]] && NODE_NUM="0${NODE_NUM}" |
205 | + NODE_NAME="node${NODE_NUM}ob${OB_NUM}" |
206 | + echo "The name of the node is ${NODE_NAME}" |
207 | + |
208 | + # Add each node to MAAS and commission it |
209 | + maas admin machines create architecture=amd64 power_type=amt power_parameters_power_address=172.27.${OB_NUM}.${AMT_NUM} power_parameters_power_pass=Password1+ mac_addresses=${MAC} hostname=${NODE_NAME} >> /var/log/${0##*/}.log 2>&1 |
210 | + |
211 | + |
212 | + |
213 | + #Get the system id of each node |
214 | + SYS_ID=$(maas admin nodes read mac_address=${MAC}|jq -r '.[]|.system_id') |
215 | + echo ${SYS_ID} |
216 | + |
217 | + #Assign tags to each node |
218 | + maas admin tag update-nodes "physical" add=${SYS_ID} >> /var/log/${0##*/}.log 2>&1 |
219 | + maas admin tag update-nodes "use-fastpath-installer" add=${SYS_ID} >> /var/log/${0##*/}.log 2>&1 |
220 | + |
221 | + #Determine which zone a node will be in |
222 | + [[ $((10#${NODE_NUM})) -le 3 ]] && export ZONE=zone1 |
223 | + [[ $((10#${NODE_NUM})) -gt 3 ]] && [[ $((10#${NODE_NUM})) -le 6 ]] && export ZONE=zone2 |
224 | + [[ $((10#${NODE_NUM})) -gt 6 ]] && [[ $((10#${NODE_NUM})) -le 10 ]] && export ZONE=zone3 |
225 | + echo "Node ${NODE_NAME} is in ${ZONE}" |
226 | + |
227 | + #Add the nodes to their respective zone |
228 | + maas admin nodes set-zone zone=${ZONE} nodes=${SYS_ID} >> /var/log/${0##*/}.log 2>&1 |
229 | + unset MAC SYS_ID ZONE NODE_NAME |
230 | done |
231 | +unset AMT_NUM AMT_PASSWORD CLUSTER_UUID |
232 | |
233 | === modified file '05a-mod_physical_nodes.sh' |
234 | --- 05a-mod_physical_nodes.sh 2016-09-20 09:23:07 +0000 |
235 | +++ 05a-mod_physical_nodes.sh 2017-03-16 17:32:27 +0000 |
236 | @@ -47,28 +47,28 @@ |
237 | sub_net="172.27.$(expr ${ob_number} + 2).0/23" |
238 | for nodenum in {01..10} |
239 | do |
240 | - interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx | cut -d '"' -f4) |
241 | - system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4) |
242 | - maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id |
243 | - do |
244 | - maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null |
245 | - if [[ $? -eq 0 ]] |
246 | - then |
247 | - maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g') |
248 | - vlanid=$(maas admin vlans read ${maas_fabric} |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}') |
249 | - if [[ -n ${interface} ]] |
250 | - then |
251 | - maas admin interface update $system_id $interface name=eth1 |
252 | - maas admin interface update $system_id eth1 vlan=$vlanid |
253 | - maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net" |
254 | - else |
255 | - eth1_set=$(maas admin interface read $system_id eth1|grep cidr 1>/dev/null 2>&1; echo $?) #0=already set, 1=needs setting |
256 | - if [[ ${eth1_set} -eq 1 ]] |
257 | - then |
258 | - maas admin interface update $system_id eth1 vlan=$vlanid |
259 | - maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net" |
260 | - fi |
261 | - fi |
262 | - fi |
263 | - done |
264 | + interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx | cut -d '"' -f4) |
265 | + system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep -m1 system_id | cut -d'"' -f4) |
266 | + maas admin subnets read|grep "\"id\""|awk '{print $2}'|sed 's/,//'|egrep -x '.{1,2}'|while read subnet_id |
267 | + do |
268 | + maas admin subnet read $subnet_id|grep "\"cidr\": \"${sub_net}\"" 1>/dev/null |
269 | + if [[ $? -eq 0 ]] |
270 | + then |
271 | + maas_fabric=$(maas admin subnet read ${subnet_id}|grep fabric|awk '{print $2}'|sed 's/,//'|sed 's/\"//g') |
272 | + vlanid=$(maas admin vlans read ${maas_fabric} |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}') |
273 | + if [[ -n ${interface} ]] |
274 | + then |
275 | + maas admin interface update $system_id $interface name=eth1 |
276 | + maas admin interface update $system_id eth1 vlan=$vlanid |
277 | + maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net" |
278 | + else |
279 | + eth1_set=$(maas admin interface read $system_id eth1|grep cidr 1>/dev/null 2>&1; echo $?) #0=already set, 1=needs setting |
280 | + if [[ ${eth1_set} -eq 1 ]] |
281 | + then |
282 | + maas admin interface update $system_id eth1 vlan=$vlanid |
283 | + maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net" |
284 | + fi |
285 | + fi |
286 | + fi |
287 | + done |
288 | done |
289 | |
290 | === modified file 'PACKAGES.list' |
291 | --- PACKAGES.list 2016-05-19 22:40:57 +0000 |
292 | +++ PACKAGES.list 2017-03-16 17:32:27 +0000 |
293 | @@ -1,3 +1,4 @@ |
294 | +jq |
295 | nmap |
296 | bridge-utils |
297 | amtterm |
298 | |
299 | === modified file 'network/network-mode.sh' |
300 | --- network/network-mode.sh 2016-08-04 05:00:27 +0000 |
301 | +++ network/network-mode.sh 2017-03-16 17:32:27 +0000 |
302 | @@ -1,10 +1,10 @@ |
303 | #!/bin/bash |
304 | -#version 0.1 |
305 | +#version 0.2 |
306 | # |
307 | # Script to configure the switch to be a single or dual vlan |
308 | # Copyright (C) 2016 Canonical Ltd. |
309 | # |
310 | -# Authors: Gary MacKenzie <gary.mackenzie@canonical.com> |
311 | +# Authors: Gary MacKenzie <gary.mackenzie@canonical.com>, Craig Bender <craig.bender@canonical.com> |
312 | # |
313 | # This program is free software: you can redistribute it and/or modify |
314 | # it under the terms of the GNU General Public License as published by |
315 | @@ -19,138 +19,261 @@ |
316 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
317 | # |
318 | |
319 | -# Get OrangeBox number |
320 | -# |
321 | - |
322 | -OB=`hostname | cut -c 10-` |
323 | -BYTE1=$(echo $OB | cut -c 1) |
324 | -BYTE2=$(echo $OB | cut -c 2-) |
325 | +TRUE=true |
326 | +FALSE=false |
327 | +command -v jq > /dev/null 2>&1 || sudo apt install jq -y |
328 | +command -v jq > /dev/null 2>&1 || { echo "This script requires jq";exit 1; } |
329 | + |
330 | + |
331 | +OB_NUM=${HOSTNAME:9} |
332 | +OB_LOG="/var/log/OrangeBox${OB_NUM}.log" |
333 | +[[ -f ${OB_LOG} ]] && sudo chmod a+w+r ${OB_LOG} || { sudo touch ${OB_LOG};sudo chmod a+w+r ${OB_LOG}; } |
334 | + |
335 | +BYTE1=${OB_NUM:0:1} |
336 | +BYTE2=${OB_NUM:1:2} |
337 | |
338 | # Parse the variables for the OrangeBox number to eliminate any zero's at the beginning of the number. |
339 | # |
340 | -if [ $BYTE1 -eq 0 ] |
341 | -then |
342 | - OB=$BYTE2 |
343 | -fi |
344 | - |
345 | -# Set the network subnet variables |
346 | -# |
347 | - |
348 | -PLUS1=`expr $OB + 1` |
349 | -PLUS2=`expr $OB + 2` |
350 | -PLUS3=`expr $OB + 3` |
351 | - |
352 | -if (($# == 0)); then |
353 | - echo "Usage: ./network_mode.sh mode |
354 | -Mode: |
355 | - -s|--single-network Configure primary and secondary interfaces on nodes 1-10 on a single VLAN |
356 | - -d|--dual-network Configure secondary interfaces on ndoes 1-10 on a second VLAN" |
357 | - exit 2 |
358 | -fi |
359 | +[[ $BYTE1 -eq 0 ]] && OB_NUM=$BYTE2 |
360 | + |
361 | +OB_ROUTER="172.27.$((${OB_NUM}+1)).254" |
362 | +MTEK_IP_ID_1=$(ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /ip address print|awk '/172.27.'${OB_NUM}'.0/{print $1}') |
363 | +MTEK_IP_ID_2=$(ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /ip address print|awk '/172.27.'$((${OB_NUM}+2))'.0/{print $1}') |
364 | + |
365 | +# Set the MAAS URL for the admin login setup |
366 | +MAAS_URL=http://172.27.${OB_NUM}.1/MAAS |
367 | +[[ -z ${MAAS_PROFILE} ]] && MAAS_PROFILE=admin |
368 | + |
369 | +Usage() { |
370 | +local help=' |
371 | +Usage: '${0##*/}' <options> |
372 | + |
373 | +Options: |
374 | + -s|--single-network Configure primary and secondary interfaces on nodes 1-10 on a single VLAN |
375 | + -d|--dual-network Configure secondary interfaces on ndoes 1-10 on a second VLAN |
376 | + -f|--force Run even if nodes are not in Ready state |
377 | + |
378 | +' |
379 | +echo "${help}" |
380 | +} |
381 | |
382 | SINGLENETWORK=0 |
383 | DUALNETWORK=0 |
384 | +FORCE=0 |
385 | +PARTIAL=0 |
386 | +[[ -z ${1} ]] && { Usage;exit 2; } |
387 | |
388 | -ARGS=`getopt -o sd --long single-network,dual-network -- "$@"` |
389 | +ARGS=`getopt -o sdf --long single-network,dual-network,force -- "$@"` |
390 | eval set -- "$ARGS" |
391 | |
392 | while true ; do |
393 | case "$1" in |
394 | -s|--single-network) |
395 | - SINGLENETWORK=1 |
396 | - shift |
397 | - ;; |
398 | + SINGLENETWORK=1 |
399 | + shift |
400 | + ;; |
401 | -d|--dual-network) |
402 | - DUALNETWORK=1 |
403 | - shift |
404 | - ;; |
405 | - --) |
406 | - shift |
407 | - break |
408 | - ;; |
409 | - *) echo "Usage: ./network_mode.sh mode |
410 | -Mode: |
411 | - -s|--single-network Configure primary and secondary interfaces on nodes 1-10 on a single VLAN |
412 | - -d|--dual-network Configure secondary interfaces on ndoes 1-10 on a second VLAN" |
413 | - exit 2 ;; |
414 | + DUALNETWORK=1 |
415 | + shift |
416 | + ;; |
417 | + -f|--force) |
418 | + FORCE=1 |
419 | + shift |
420 | + ;; |
421 | + --) |
422 | + shift |
423 | + break |
424 | + ;; |
425 | + */?) Usage;exit 2 ;; |
426 | esac |
427 | done |
428 | |
429 | -if [ "$SINGLENETWORK" -eq 1 ]; |
430 | -then |
431 | - echo "Configuring for 1 Network mode..." |
432 | -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 |
433 | - |
434 | -echo |
435 | -echo "All ports configured for 1 network mode" |
436 | - ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /beep |
437 | -#Get Orangebox number from the hostname and place into the configuration file |
438 | -ob_number=`hostname | cut -c 10- -` |
439 | - |
440 | -# Set the MAAS URL for the admin login setup |
441 | -MAAS_URL=http://172.27.${ob_number}.1/MAAS |
442 | - |
443 | -apikey=`sudo maas-region apikey --username admin | tail -n1` |
444 | -maas login admin $MAAS_URL $apikey |
445 | - |
446 | -declare maas_fabric=() |
447 | -for fab_ric in $(maas admin fabrics read |grep name|grep fabric|awk -F\" '{print $4}') |
448 | -do |
449 | - echo "Fabric $fab_ric" |
450 | - maas_fabric=("${maas_fabric[@]}" "$fab_ric") |
451 | -done |
452 | - |
453 | -vlanid=$(maas admin vlans read "${maas_fabric[1]}" |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}') |
454 | -sub_net="172.27.${ob_number}.0/23" |
455 | - |
456 | -for nodenum in {01..10} |
457 | -do |
458 | - system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4) |
459 | - maas admin interface update $system_id eth1 vlan=$vlanid |
460 | - maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net" |
461 | -done |
462 | - exit |
463 | -fi |
464 | - |
465 | -if [ "$DUALNETWORK" -eq 1 ]; |
466 | -then |
467 | - echo "Configuring for 2 Network mode..." |
468 | -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 |
469 | - |
470 | -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 |
471 | - |
472 | -echo |
473 | -echo "All ports configured for 2 network mode" |
474 | - ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /beep |
475 | -#Get Orangebox number from the hostname and place into the configuration file |
476 | -ob_number=`hostname | cut -c 10- -` |
477 | - |
478 | -# Set the MAAS URL for the admin login setup |
479 | -MAAS_URL=http://172.27.${ob_number}.1/MAAS |
480 | - |
481 | -apikey=`sudo maas-region apikey --username admin | tail -n1` |
482 | -maas login admin $MAAS_URL $apikey |
483 | - |
484 | -declare maas_fabric=() |
485 | -for fab_ric in $(maas admin fabrics read |grep name|grep fabric|awk -F\" '{print $4}') |
486 | -do |
487 | - echo "Fabric $fab_ric" |
488 | - maas_fabric=("${maas_fabric[@]}" "$fab_ric") |
489 | -done |
490 | - |
491 | -vlanid=$(maas admin vlans read "${maas_fabric[2]}" |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}') |
492 | -sub_net="172.27.((ob_number+2)).0/23" |
493 | - |
494 | -# Configure second usb interface for second fabric and proper subnet |
495 | -# |
496 | - |
497 | -for nodenum in {01..10} |
498 | -do |
499 | - system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4) |
500 | - maas admin interface update $system_id eth1 vlan=$vlanid |
501 | - maas admin interface link-subnet $system_id eth1 mode=auto subnet="$sub_net" |
502 | -done |
503 | -echo "MAAS re-adjusted the nodes to work with dual vlan" |
504 | -sleep 5 |
505 | - exit |
506 | -fi |
507 | +[[ ${SINGLENETWORK} = 0 && ${DUALNETWORK} = 0 ]] && { printf "\nPlease select either -s or -d\n\n";Usage;exit 2; } |
508 | +[[ ${SINGLENETWORK} = 1 && ${DUALNETWORK} = 1 ]] && { printf "\nPlease select either -s or -d\n\n";Usage;exit 2; } |
509 | + |
510 | +MAAS_APIKEY=$(sudo maas apikey --username=${MAAS_PROFILE}) |
511 | +[[ $? -eq 0 ]] || { echo "Failed to apikey for maas profile @ ${MAAS_PROFILE}";exit 1; } |
512 | + |
513 | + |
514 | +[[ $SINGLENETWORK -eq 1 ]] && printf "\nConfiguring OrangeBox${OB_NUM} for Single Network mode:\n" |
515 | +[[ $DUALNETWORK -eq 1 ]] && printf "\nConfiguring OrangeBox${OB_NUM} for Dual Network mode:\n" |
516 | +[[ ${FORCE} -eq 0 ]] || printf "\n\tForce mode selected\n" |
517 | +#Login to maas |
518 | +printf "\n\tLogging in as ${MAAS_PROFILE} to maas server @ ${MAAS_URL}..." |
519 | +maas login ${MAAS_PROFILE} ${MAAS_URL} ${MAAS_APIKEY} >> ${OB_LOG} 2>&1 |
520 | +[[ $? -eq 0 ]] && printf " OK!\n\n" || { printf " FAILED!\n\nFailed to login in to maas server @ ${MAAS_URL}\n\n";exit 1; } |
521 | +printf "\n\tGetting state of nodes on OrangeBox${OB_NUM}\n\n" |
522 | +MAAS_MACHINE_STATES=$(maas admin machines read) |
523 | +[[ $? -eq 0 ]] || { printf " FAILED!\n\nFailed to get state of nodes from maas server @ ${MAAS_URL}\n\n";exit 1; } |
524 | + |
525 | +if [[ ${FORCE} -eq 0 ]];then |
526 | + |
527 | + |
528 | + if [[ -n $(echo $MAAS_MACHINE_STATES|jq -r '.[]|.hostname+"\t"+.status_name'|sed -E -e '/vm|Ready/d') ]];then |
529 | + printf "\n\tERROR: Interfaces cannot be changed unless nodes are in a \"Ready\" or \"Broken\" state\n\n" |
530 | + printf "\t\tPlease ensure the all nodes are \"Ready\" and try again.\n\n" |
531 | + echo $MAAS_MACHINE_STATES|jq -r '.[]|"\t\t"+.hostname+" \t"+.status_name'|sed '/node00vm/d' |
532 | + printf "\n" |
533 | + exit 3 |
534 | + else |
535 | + echo $MAAS_MACHINE_STATES|jq -r '.[]|"\t\t"+.hostname+" \t"+.status_name'|sed '/node00vm/d' |
536 | + printf "\n" |
537 | + fi |
538 | +fi |
539 | + |
540 | +MAAS_SUB_NET_1="172.27.${OB_NUM}.0/23" |
541 | +MAAS_SUB_NET_2="172.27.$(($OB_NUM+2)).0/23" |
542 | +ETHER_1_OK=${FALSE} |
543 | +ETHER_2_OK=${FALSE} |
544 | +IP_1_VLAN_OK=${FALSE} |
545 | +IP_2_VLAN_OK==${FALSE} |
546 | +ETH1_PORTS="$(seq 4 2 22)" |
547 | +ETH2_PORTS="$(seq 5 2 23)" |
548 | + |
549 | +if [[ $SINGLENETWORK -eq 1 ]];then |
550 | + |
551 | + 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 |
552 | + [[ $? -eq 0 ]] && { printf "\tMikrotik: Successfully set master port to ether2-master-local for all ports\n"; } || { printf "\n Mikrotik: Failed to set the master-port as ether2-master-local for all ports on the Mikrotik router\n\n";exit 1; } |
553 | + |
554 | + ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /ip address set ${MTEK_IP_ID_1} interface=vlan1 |
555 | + [[ $? -eq 0 ]] && IP_1_VLAN_OK=${TRUE} || IP_1_VLAN_OK=${FALSE} |
556 | + |
557 | + ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /ip address set ${MTEK_IP_ID_2} interface=vlan1 |
558 | + [[ $? -eq 0 ]] && IP_2_VLAN_OK=${TRUE} || IP_1_VLAN_OK=${FALSE} |
559 | + |
560 | + [[ ${IP_1_VLAN_OK} = ${TRUE} ]] && { echo -e "\n\tMikrotik: Successfully set subnet ${MAAS_SUB_NET_1} to vlan1"; } |
561 | + [[ ${IP_2_VLAN_OK} = ${TRUE} ]] && { echo -e "\n\tMikrotik: Successfully set subnet ${MAAS_SUB_NET_2} to vlan1"; } |
562 | + [[ ${IP_1_VLAN_OK} = ${FALSE} ]] && { echo -e "\n\tMikrotik: Failed to set subnet ${MAAS_SUB_NET_1} to vlan1";exit 1; } |
563 | + [[ ${IP_2_VLAN_OK} = ${FALSE} ]] && { echo -e "\n\tMikrotik: Failed to set subnet ${MAAS_SUB_NET_2} to vlan1";exit 1; } |
564 | + printf "\n\tMikrotik: Successfully configured Mikrotek router @ ${OB_ROUTER} for Single Network Mode!\n\n" |
565 | + |
566 | +elif [[ $DUALNETWORK -eq 1 ]];then |
567 | + |
568 | + |
569 | + 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 |
570 | + [[ $? -eq 0 ]] && ETHER_1_OK=${TRUE} || ETHER_1_OK=${FALSE} |
571 | + |
572 | + 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 |
573 | + [[ $? -eq 0 ]] && ETHER_2_OK=${TRUE} || ETHER_2_OK=${FALSE} |
574 | + |
575 | + ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /ip address set ${MTEK_IP_ID_1} interface=vlan1 |
576 | + [[ $? -eq 0 ]] && IP_1_VLAN_OK=${TRUE} || IP_1_VLAN_OK=${FALSE} |
577 | + |
578 | + ssh -o "StrictHostKeyChecking no" admin@${OB_ROUTER} /ip address set ${MTEK_IP_ID_2} interface=vlan2 |
579 | + [[ $? -eq 0 ]] && IP_2_VLAN_OK=${TRUE} || IP_2_VLAN_OK=${FALSE} |
580 | + |
581 | + [[ ${ETHER_1_OK} = ${FALSE} ]] && { echo -e "\n\tMikrotik: Failed to set master port to ether1-master-local for ports: "${ETH1_PORTS};exit 1; } |
582 | + [[ ${ETHER_2_OK} = ${FALSE} ]] && { echo -e "\n\tMikrotik: Failed to set master port to ether2-master-local for ports: "${ETH2_PORTS};exit 1; } |
583 | + [[ ${ETHER_1_OK} = ${TRUE} ]] && { echo -e "\n\tMikrotik: Successfully set master port to ether1-master-local for ports: "${ETH1_PORTS}; } |
584 | + [[ ${ETHER_2_OK} = ${TRUE} ]] && { echo -e "\n\tMikrotik: Successfully set master port to ether2-master-local for ports: "${ETH2_PORTS}; } |
585 | + [[ ${IP_1_VLAN_OK} = ${TRUE} ]] && { echo -e "\n\tMikrotik: Successfully set subnet ${MAAS_SUB_NET_1} to vlan1"; } |
586 | + [[ ${IP_2_VLAN_OK} = ${TRUE} ]] && { echo -e "\n\tMikrotik: Successfully set subnet ${MAAS_SUB_NET_2} to vlan2"; } |
587 | + [[ ${IP_1_VLAN_OK} = ${FALSE} ]] && { echo -e "\n\tMikrotik: Failed to set subnet ${MAAS_SUB_NET_1} to vlan1";exit 1; } |
588 | + [[ ${IP_2_VLAN_OK} = ${FALSE} ]] && { echo -e "\n\tMikrotik: Failed to set subnet ${MAAS_SUB_NET_2} to vlan2";exit 1; } |
589 | + printf "\n\tMikrotik: Successfully configured Mikrotek router @ ${OB_ROUTER} for Dual Network Mode!\n\n" |
590 | + |
591 | +fi |
592 | + |
593 | + |
594 | + |
595 | +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)') |
596 | +[[ -z ${MAAS_FABRIC_ID_1} ]] && { echo "Failed to fetch fabric id 1 from maas server @ ${MAAS_URL}";exit 1; } |
597 | +[[ -z ${MAAS_VLAN_ID_1} ]] && { echo "Failed to fetch vlan id 1 from maas server @ ${MAAS_URL}";exit 1; } |
598 | + |
599 | +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)') |
600 | +[[ -z ${MAAS_FABRIC_ID_2} ]] && { echo "Failed to fetch fabric id 2 from maas server @ ${MAAS_URL}";exit 1; } |
601 | +[[ -z ${MAAS_VLAN_ID_2} ]] && { echo "Failed to fetch vlan id 2 from maas server @ ${MAAS_URL}";exit 1; } |
602 | + |
603 | +for node in {01..10};do |
604 | + MAAS_NODE_NAME="node${node}ob${OB_NUM}" |
605 | + eval $(echo $MAAS_MACHINE_STATES |jq -r '.[]|select(.hostname=="'${MAAS_NODE_NAME}'")|"MAAS_SYSID="+.system_id,"MAAS_STATUS="+.status_name') |
606 | + maas admin interface update ${MAAS_SYSID} eth0 vlan=${MAAS_VLAN_ID_1} subnet=${MAAS_SUB_NET_1} mode=auto>> ${OB_LOG} 2>&1 |
607 | + if [[ $? -eq 0 ]];then |
608 | + printf "\tMAAS: Successfully set eth0 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to use vlan ${MAAS_VLAN_ID_1}\n" |
609 | + else |
610 | + printf "\tMAAS: Failed to set eth0 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to vlan ${MAAS_VLAN_ID_1} (${MAAS_SUB_NET_1})\n\n" |
611 | + [[ ${FORCE} -eq 0 ]] && exit 2 |
612 | + fi |
613 | + |
614 | + if [[ $SINGLENETWORK -eq 1 ]];then |
615 | + maas admin interface update ${MAAS_SYSID} eth1 vlan=${MAAS_VLAN_ID_1} >> ${OB_LOG} 2>&1 |
616 | + if [[ $? -eq 0 ]];then |
617 | + printf "\tMAAS: Successfully set eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to use vlan ${MAAS_VLAN_ID_1}\n" |
618 | + else |
619 | + printf "\tMAAS: Failed to set eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to vlan ${MAAS_VLAN_ID_1} (${MAAS_SUB_NET_1})\n\n" |
620 | + [[ ${FORCE} -eq 0 ]] && exit 2 |
621 | + fi |
622 | + elif [[ $DUALNETWORK -eq 1 ]];then |
623 | + maas admin interface update ${MAAS_SYSID} eth1 vlan=${MAAS_VLAN_ID_2} >> ${OB_LOG} 2>&1 |
624 | + if [[ $? -eq 0 ]];then |
625 | + printf "\tMAAS: Successfully set eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to use vlan ${MAAS_VLAN_ID_2}\n" |
626 | + else |
627 | + printf "\tMAAS: Failed to set eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to vlan ${MAAS_VLAN_ID_2} (${MAAS_SUB_NET_2})\n\n" |
628 | + [[ ${FORCE} -eq 0 ]] && exit 2 |
629 | + fi |
630 | + fi |
631 | +done |
632 | + #update machine states |
633 | + MAAS_MACHINE_STATES=$(maas admin machines read) |
634 | +for node in {01..10};do |
635 | + MAAS_NODE_NAME="node${node}ob${OB_NUM}" |
636 | + eval $(echo $MAAS_MACHINE_STATES |jq -r '.[]|select(.hostname=="'${MAAS_NODE_NAME}'")|"MAAS_SYSID="+.system_id,"MAAS_STATUS="+.status_name') |
637 | + if [[ -z $(echo $MAAS_MACHINE_STATES|jq -r '.[]|select(.system_id=="'${MAAS_SYSID}'")|.interface_set[]|select(.name=="eth0")|.links[]') ]];then |
638 | + if [[ ${MAAS_STATUS} = Ready || ${MAAS_STATUS} = Broken ]];then |
639 | + maas admin interface link-subnet ${MAAS_SYSID} eth0 mode=auto subnet="${MAAS_SUB_NET_1}" >> ${OB_LOG} 2>&1 |
640 | + if [[ $? -eq 0 ]];then |
641 | + printf "\tMAAS: Successfully linked eth0 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_1}\n" |
642 | + else |
643 | + printf "\t\tMAAS: Failed to link eth0 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_1}\n\n" |
644 | + [[ ${FORCE} -eq 0 ]] && exit 2 |
645 | + fi |
646 | + else |
647 | + export PARTIAL=1 |
648 | + printf "\tMAAS: Cannot link eth0 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_1} because node is in a ${MAAS_STATUS} state\n" |
649 | + printf "\n" |
650 | + |
651 | + fi |
652 | + fi |
653 | + |
654 | + |
655 | + if [[ $SINGLENETWORK -eq 1 ]] && [[ -z $(echo $MAAS_MACHINE_STATES|jq -r '.[]|select(.system_id=="'${MAAS_SYSID}'")|.interface_set[]|select(.name=="eth1")|.links[]') ]];then |
656 | + if [[ ${MAAS_STATUS} = Ready || ${MAAS_STATUS} = Broken ]];then |
657 | + maas admin interface link-subnet ${MAAS_SYSID} eth1 mode=auto subnet="${MAAS_SUB_NET_1}" >> ${OB_LOG} 2>&1 |
658 | + if [[ $? -eq 0 ]];then |
659 | + printf "\tMAAS: Successfully linked eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_1}\n" |
660 | + else |
661 | + printf "\t\tMAAS: Failed to link eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_1}\n\n" |
662 | + [[ ${FORCE} -eq 0 ]] && exit 2 |
663 | + fi |
664 | + else |
665 | + export PARTIAL=1 |
666 | + printf "\tMAAS: Cannot link eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_1} because node is in a ${MAAS_STATUS} state\n" |
667 | + printf "\n" |
668 | + |
669 | + fi |
670 | + elif [[ $DUALNETWORK -eq 1 ]] && [[ -z $(echo $MAAS_MACHINE_STATES|jq -r '.[]|select(.system_id=="'${MAAS_SYSID}'")|.interface_set[]|select(.name=="eth1")|.links[]') ]];then |
671 | + if [[ ${MAAS_STATUS} = Ready || ${MAAS_STATUS} = Broken ]];then |
672 | + maas admin interface link-subnet ${MAAS_SYSID} eth1 mode=auto subnet="${MAAS_SUB_NET_2}" >> ${OB_LOG} 2>&1 |
673 | + if [[ $? -eq 0 ]];then |
674 | + printf "\tMAAS: Successfully linked eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_2}\n" |
675 | + else |
676 | + printf "\t\tMAAS: Failed to link eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_2}\n\n" |
677 | + [[ ${FORCE} -eq 0 ]] && exit 2 |
678 | + fi |
679 | + else |
680 | + export PARTIAL=1 |
681 | + printf "\tMAAS: Cannot link eth1 on ${MAAS_NODE_NAME} (${MAAS_SYSID}) to subnet ${MAAS_SUB_NET_2} because node is in a ${MAAS_STATUS} state\n" |
682 | + fi |
683 | + fi |
684 | + |
685 | +done |
686 | +[[ $SINGLENETWORK -eq 1 && PARTIAL -eq 0 ]] && printf "\n Successfully configured OrangeBox${OB_NUM} for Single Network Mode!\n\n" |
687 | +[[ $DUALNETWORK -eq 1 && PARTIAL -eq 0 ]] && printf "\n Successfully configured OrangeBox${OB_NUM} for Dual Network Mode!\n\n" |
688 | +[[ $SINGLENETWORK -eq 1 && PARTIAL -eq 1 ]] && printf "\nPartially configured OrangeBox${OB_NUM} for Single Network Mode.\n\n" |
689 | +[[ $DUALNETWORK -eq 1 && PARTIAL -eq 1 ]] && printf "\nPartially configured OrangeBox${OB_NUM} for Dual Network Mode.\n\n" |
690 | + |
691 | + |
692 | +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 |
693 | + |
694 | + |
695 | + |
This patch mixes whitespace adjustments with actual code changes, which is problematic to the review. Consider one patchset for fixes/enhancements, and a separate one for trivial whitespace changes.