~cpe-sa/obinstall/fix-eula

« back to all changes in this revision

Viewing changes to network/network-mode.sh

  • Committer: Scott Croft
  • Date: 2016-06-02 16:26:55 UTC
  • Revision ID: scott@canonical.com-20160602162655-2b0tc09amrrhyn60
New network configuration scripts and adjusted OB setup scripts to accommodate new changes to MAAS 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#version 0.1
 
3
#
 
4
#    Script to configure the switch to be a single or dual vlan
 
5
#    Copyright (C) 2016 Canonical Ltd.
 
6
#
 
7
#    Authors: Gary MacKenzie <gary.mackenzie@canonical.com>
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU General Public License as published by
 
11
#    the Free Software Foundation, version 3 of the License.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
 
 
22
# Get OrangeBox number
 
23
#
 
24
 
 
25
OB=`hostname | cut -c 10-`
 
26
BYTE1=$(echo $OB | cut -c 1)
 
27
BYTE2=$(echo $OB | cut -c 2-)
 
28
 
 
29
# Parse the variables for the OrangeBox number to eliminate any zero's at the beginning of the number.
 
30
#
 
31
if [ $BYTE1 -eq 0 ]
 
32
then
 
33
        OB=$BYTE2
 
34
fi
 
35
 
 
36
# Set the network subnet variables
 
37
#
 
38
 
 
39
PLUS1=`expr $OB + 1`
 
40
PLUS2=`expr $OB + 2`
 
41
PLUS3=`expr $OB + 3`
 
42
 
 
43
if (($# == 0)); then
 
44
        echo "Usage: ./network_mode.sh mode
 
45
Mode:
 
46
  -s|--single-network   Configure primary and secondary interfaces on nodes 1-10 on a single VLAN
 
47
  -d|--dual-network     Configure secondary interfaces on ndoes 1-10 on a second VLAN"
 
48
        exit 2
 
49
fi
 
50
 
 
51
SINGLENETWORK=0
 
52
DUALNETWORK=0
 
53
 
 
54
ARGS=`getopt -o sd --long single-network,dual-network -- "$@"`
 
55
eval set -- "$ARGS"
 
56
 
 
57
while true ; do
 
58
    case "$1" in
 
59
        -s|--single-network)
 
60
                SINGLENETWORK=1
 
61
                shift
 
62
                ;;
 
63
        -d|--dual-network) 
 
64
                DUALNETWORK=1
 
65
                shift
 
66
                ;;
 
67
        --)
 
68
                shift
 
69
                break
 
70
                ;;
 
71
        *) echo "Usage: ./network_mode.sh mode
 
72
Mode:
 
73
  -s|--single-network   Configure primary and secondary interfaces on nodes 1-10 on a single VLAN
 
74
  -d|--dual-network     Configure secondary interfaces on ndoes 1-10 on a second VLAN"
 
75
           exit 2 ;;
 
76
    esac
 
77
done
 
78
 
 
79
if [ "$SINGLENETWORK" -eq 1 ];
 
80
then
 
81
   echo "Configuring for 1 Network mode..."
 
82
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
 
83
 
 
84
echo
 
85
echo "All ports configured for 1 network mode"
 
86
   ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /beep
 
87
#Get Orangebox number from the hostname and place into the configuration file
 
88
obnum=`hostname | cut -c 10- -`
 
89
echo "orangebox_number=${obnum}" > /etc/orange-box.conf
 
90
 
 
91
# Get interface names of the 3 interfaces on node0 since in Xenial they aren't ethX anymore
 
92
# An array is declared and the interface names are placed into the array to be used later on
 
93
#
 
94
 
 
95
 
 
96
vlanid=$(maas admin vlans read 1 |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
 
97
sub_net="172.27.${ob_number}.0/23"
 
98
 
 
99
# Configure first usb interface for fabric-1 and proper subnet
 
100
#
 
101
 
 
102
for nodenum in {01..10}
 
103
do
 
104
 
 
105
 
 
106
     interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx | cut -d '"' -f4)
 
107
        echo "Interface read $interface"
 
108
     system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
 
109
     maas admin machine update $system_id cpu_count=4
 
110
     maas admin interface update $system_id $interface vlan=$vlanid
 
111
     maas admin interface link-subnet $system_id $interface mode=auto subnet="$sub_net"
 
112
done
 
113
   exit
 
114
fi
 
115
 
 
116
if [ "$DUALNETWORK" -eq 1 ];
 
117
then
 
118
   echo "Configuring for 2 Network mode..."
 
119
ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /interface ethernet set master-port=ether2-master-local 4,6,8,10,12,14,16,18,20,22
 
120
 
 
121
ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /interface ethernet set master-port=ether1-master-local 5,7,9,11,13,15,17,19,21,23
 
122
 
 
123
echo 
 
124
echo "All ports configured for 2 network mode"
 
125
   ssh -o "StrictHostKeyChecking no" admin@172.27.$PLUS1.254 /beep
 
126
#Get Orangebox number from the hostname and place into the configuration file
 
127
obnum=`hostname | cut -c 10- -`
 
128
echo "orangebox_number=${obnum}" > /etc/orange-box.conf
 
129
 
 
130
# Get interface names of the 3 interfaces on node0 since in Xenial they aren't ethX anymore
 
131
# An array is declared and the interface names are placed into the array to be used later on
 
132
#
 
133
 
 
134
 
 
135
vlanid=$(maas admin vlans read 2 |grep id |grep -v vid | awk -F, '{print $1}'|awk '{print $2}')
 
136
sub_net="172.27.`expr ${ob_number} + 2`.0/23"
 
137
 
 
138
# Configure first usb interface for fabric-1 and proper subnet
 
139
#
 
140
 
 
141
for nodenum in {01..10}
 
142
do
 
143
 
 
144
 
 
145
     interface=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep enx | cut -d '"' -f4)
 
146
        echo "Interface read $interface"
 
147
     system_id=$(maas admin nodes read hostname=node${nodenum}ob${ob_number} |grep system_id | cut -d'"' -f4)
 
148
     maas admin machine update $system_id cpu_count=4
 
149
     maas admin interface update $system_id $interface vlan=$vlanid
 
150
     maas admin interface link-subnet $system_id $interface mode=auto subnet="$sub_net"
 
151
done
 
152
echo "MAAS re-adjusted the nodes to work with dual vlan"
 
153
sleep 5
 
154
   exit
 
155
fi