modified all intel lab labconfig
[joid.git] / ci / 02-maasdeploy.sh
1 #!/bin/bash
2 #placeholder for deployment script.
3 set -ex
4
5 virtinstall=0
6 labname = $1
7
8 #install the packages needed
9 sudo apt-add-repository ppa:maas-deployers/stable -y
10 sudo apt-add-repository ppa:juju/stable -y
11 sudo apt-add-repository ppa:maas/stable -y
12 sudo apt-add-repository cloud-archive:liberty -y
13 sudo apt-get update -y
14 sudo apt-get dist-upgrade -y
15 sudo apt-get install openssh-server git maas-deployer juju juju-deployer maas-cli python-pip python-openstackclient gsutil -y
16
17 cp maas/deployment.yaml ./deployment.yaml
18
19 #first parameter should be custom and second should be either 
20 # absolute location of file (including file name) or url of the 
21 # file to download.
22
23 if [ "$1" == "custom" ]; then
24     if [ -e $2 ]; then
25         cp $2 ./labconfig.yaml || true
26         python deploy.py
27     else
28         wget $2 -t 3 -T 10 -O ./labconfig.yaml || true
29         count=`wc -l labconfig.yaml  | cut -d " " -f 1`
30
31         if [ $count -lt 10 ]; then
32             rm -rf labconfig.yaml
33         else
34             python deploy.py
35         fi
36     fi
37
38     if [ ! -e ./labconfig.yaml ]; then
39         virtinstall=1
40         cp ../labconfig/default/deployment.yaml ./
41         cp ../labconfig/default/labconfig.yaml ./
42     fi
43     labname=`grep "lab_location" labconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
44 else
45     case "$1" in
46         'intelpod5' )
47             cp ../labconfig/intel/pod5/labconfig.yaml ./
48             #to be removed later once converted for all labs.
49             python deploy.py
50             ;;
51         'intelpod6' )
52             cp ../labconfig/intel/pod6/labconfig.yaml ./
53             #to be removed later once converted for all labs.
54             python deploy.py
55             ;;
56         'intelpod9' )
57             cp ../labconfig/intel/pod6/labconfig.yaml ./
58             #to be removed later once converted for all labs.
59             python deploy.py
60             ;;
61         'orangepod1' )
62             cp maas/orange/pod1/deployment.yaml ./deployment.yaml
63             ;;
64         'orangepod2' )
65             cp maas/orange/pod2/deployment.yaml ./deployment.yaml
66             ;;
67         'attvirpod1' )
68             cp maas/att/virpod1/deployment.yaml ./deployment.yaml
69             ;;
70         'juniperpod1' )
71             cp maas/juniper/pod1/deployment.yaml ./deployment.yaml
72             ;;
73         'cengnlynxpod1' )
74             cp maas/cengn_lynx/pod1/deployment.yaml ./deployment.yaml
75             ;;
76         * )
77             virtinstall=1
78             labname = "default"
79             ./cleanvm.sh
80             cp ../labconfig/default/deployment.yaml ./
81             ;;
82     esac
83 fi
84
85 #make sure no password asked during the deployment.
86
87 echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
88
89 if [ -e /etc/sudoers.d/90-joid-init ]; then
90     sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
91     sudo chown $USER:$USER 91-joid-init
92     sudo chmod 660 91-joid-init
93     sudo cat 90-joid-init >> 91-joid-init
94     sudo chown root:root 91-joid-init
95     sudo mv 91-joid-init /etc/sudoers.d/
96 else
97     sudo chown root:root 90-joid-init
98     sudo mv 90-joid-init /etc/sudoers.d/
99 fi
100
101 echo "... Deployment of maas Started ...."
102
103 if [ ! -e $HOME/.ssh/id_rsa ]; then
104     ssh-keygen -N '' -f $HOME/.ssh/id_rsa
105 fi
106
107 #define the pool and try to start even though its already exist.
108 # For fresh install this may or may not there.
109
110 sudo apt-get install libvirt-bin -y
111 sudo adduser $USER libvirtd
112 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
113 sudo virsh pool-start default || true
114 sudo virsh pool-autostart default || true
115
116 # To avoid problem between apiclient/maas_client and apiclient from google
117 # we remove the package google-api-python-client from yardstick installer
118 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
119     sudo pip uninstall google-api-python-client
120 fi
121
122 sudo pip install shyaml
123 juju init -f
124
125 cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
126
127 if [ "$virtinstall" -eq 1 ]; then
128     sudo virsh net-dumpxml default > default-net-org.xml
129     sudo sed -i '/dhcp/d' default-net-org.xml
130     sudo sed -i '/range/d' default-net-org.xml
131     sudo virsh net-define default-net-org.xml
132     sudo virsh net-destroy default
133     sudo virsh net-start default
134 fi
135
136 #Below function will mark the interfaces in Auto mode to enbled by MAAS
137 enableautomode() {
138     listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
139     for nodes in $listofnodes
140     do
141         maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
142     done
143 }
144
145 #Below function will mark the interfaces in Auto mode to enbled by MAAS
146 # using hostname of the node added into MAAS
147
148 enableautomodebyname() {
149     if [ ! -z "$4" ]; then
150         for i in `seq 1 7`;
151         do
152             nodes=`maas maas nodes list hostname=node$i-$4 | grep system_id | cut -d '"' -f 4`
153             if [ ! -z "$nodes" ]; then
154                 maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
155             fi
156        done
157     fi
158 }
159
160 #Below function will create vlan and update interface with the new vlan
161 # will return the vlan id created
162 crvlanupdsubnet() {
163     newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
164     maas maas subnet update $5 vlan=$newvlanid
165     eval "$1"="'$newvlanid'"
166 }
167
168 #Below function will create interface with new vlan and bind to physical interface
169 crnodevlanint() {
170     listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
171
172     for nodes in $listofnodes
173     do
174         parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
175         maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
176      done
177  }
178
179 #convert labconfig file to deployment.yaml to consume by MAAS.
180 #python deploy.py
181
182 #just make sure the ssh keys added into maas for the current user
183 sed --i "s@/home/ubuntu@$HOME@g" ./deployment.yaml
184 sed --i "s@qemu+ssh://ubuntu@qemu+ssh://$USER@g" ./deployment.yaml
185
186 sudo maas-deployer -c deployment.yaml -d --force
187
188 sudo chown $USER:$USER environments.yaml
189
190 echo "... Deployment of maas finish ...."
191
192 maas_ip=`grep " ip_address" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
193 apikey=`grep maas-oauth: environments.yaml | cut -d "'" -f 2`
194 maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
195 maas maas sshkeys new key="`cat $HOME/.ssh/id_rsa.pub`"
196
197 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
198 maas maas sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
199
200 #adding compute and control nodes VM to MAAS for deployment purpose.
201 if [ "$virtinstall" -eq 1 ]; then
202     # create two more VMs to do the deployment.
203     sudo virt-install --connect qemu:///system --name node1-control --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node1-control
204
205     sudo virt-install --connect qemu:///system --name node2-compute --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node2-compute
206
207     sudo virt-install --connect qemu:///system --name node5-compute --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node5-compute
208
209     node1controlmac=`grep  "mac address" node1-control | head -1 | cut -d "'" -f 2`
210     node2computemac=`grep  "mac address" node2-compute | head -1 | cut -d "'" -f 2`
211     node5computemac=`grep  "mac address" node5-compute | head -1 | cut -d "'" -f 2`
212
213     sudo virsh -c qemu:///system define --file node1-control
214     sudo virsh -c qemu:///system define --file node2-compute
215     sudo virsh -c qemu:///system define --file node5-compute
216
217     maas maas tags new name='control'
218     maas maas tags new name='compute'
219
220     controlnodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node1-control' tags='control' hostname='node1-control' power_type='virsh' mac_addresses=$node1controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node1-control' | grep system_id | cut -d '"' -f 4 `
221
222     maas maas tag update-nodes control add=$controlnodeid
223
224     computenodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node2-compute' tags='compute' hostname='node2-compute' power_type='virsh' mac_addresses=$node2computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node2-compute' | grep system_id | cut -d '"' -f 4 `
225
226     maas maas tag update-nodes compute add=$computenodeid
227
228     computenodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node5-compute' tags='compute' hostname='node5-compute' power_type='virsh' mac_addresses=$node5computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node5-compute' | grep system_id | cut -d '"' -f 4 `
229
230     maas maas tag update-nodes compute add=$computenodeid
231 fi
232
233 # Enable vlan interfaces with maas
234 case "$labname" in
235     'intelpod5' )
236         maas refresh
237         enableautomodebyname eth4 AUTO "10.5.12.0/24" compute || true
238         enableautomodebyname eth4 AUTO "10.5.12.0/24" control || true
239         ;;
240     'intelpod6' )
241         maas refresh
242         enableautomodebyname eth4 AUTO "10.6.12.0/24" compute || true
243         enableautomodebyname eth4 AUTO "10.6.12.0/24" control || true
244         ;;
245     'intelpod9' )
246         maas refresh
247         crvlanupdsubnet vlan902 1 "DataNetwork" 902 2 || true
248         crvlanupdsubnet vlan905 2 "PublicNetwork" 905 3 || true
249         crnodevlanint $vlan902 eth0 || true
250         crnodevlanint $vlan905 eth1 || true
251         enableautomodebyname eth0.902 AUTO "10.9.12.0/24" compute || true
252         enableautomodebyname eth1.905 AUTO "10.9.15.0/24" compute || true
253         enableautomodebyname eth0.902 AUTO "10.9.12.0/24" control || true
254         enableautomodebyname eth1.905 AUTO "10.9.15.0/24" control || true
255         ;;
256     'orangepod1' )
257         maas refresh
258         enableautomodebyname eth2 DHCP "192.168.21.0/24" compute || true
259         enableautomodebyname eth3 AUTO "192.168.11.0/24" compute || true
260         enableautomodebyname eth2 DHCP "192.168.21.0/24" control || true
261         enableautomodebyname eth3 AUTO "192.168.11.0/24" control || true
262         ;;
263     'orangepod2' )
264         maas refresh
265         enableautomodebyname eth4 DHCP "192.168.22.0/24" compute || true
266         enableautomodebyname eth5 AUTO "192.168.12.0/24" compute || true
267         enableautomodebyname eth2 DHCP "192.168.22.0/24" control || true
268         enableautomodebyname eth3 AUTO "192.168.12.0/24" control || true
269         ;;
270     'attvirpod1' )
271         enableautomodebyname eth1 AUTO "192.168.10.0/24" control || true
272         ;;
273     'juniperpod1' )
274         ;;
275     'cengnlynxpod1' )
276         maas refresh
277         crvlanupdsubnet vlan1201 1 "DataNetwork" 1201 2 || true
278         crvlanupdsubnet vlan1202 2 "PublicNetwork" 1202 3 || true
279         crnodevlanint $vlan1201 eth1 || true
280         crnodevlanint $vlan1202 eth1 || true
281         enableautomode eth1.1201 AUTO "172.16.121.3/24" compute || true
282         enableautomode eth1.1201 AUTO "172.16.121.3/24" control || true
283         ;;
284 esac
285
286 echo " .... MAAS deployment finished successfully ...."
287
288 #echo "... Deployment of opnfv release Started ...."
289 #python deploy.py $maas_ip