modfiied to fix parse error.
[joid.git] / ci / 03-maasdeploy.sh
1 #!/bin/bash
2 #placeholder for deployment script.
3 set -ex
4
5 virtinstall=0
6 labname=$1
7
8 if [ ! -e $HOME/.ssh/id_rsa ]; then
9     ssh-keygen -N '' -f $HOME/.ssh/id_rsa
10 fi
11
12 #install the packages needed
13 sudo apt-add-repository ppa:juju/devel -y
14 sudo apt-add-repository ppa:maas/stable -y
15 sudo apt-add-repository cloud-archive:newton -y
16 sudo apt-get update -y
17 #sudo apt-get dist-upgrade -y
18 sudo apt-get install openssh-server bzr git virtinst qemu-kvm libvirt-bin juju \
19              maas maas-region-controller python-pip python-psutil python-openstackclient \
20              python-congressclient gsutil charm-tools pastebinit python-jinja2 sshpass \
21              openssh-server vlan ipmitool jq expect -y
22
23 sudo pip install --upgrade pip
24
25 #first parameter should be custom and second should be either
26 # absolute location of file (including file name) or url of the
27 # file to download.
28
29
30 #
31 # Config preparation
32 #
33
34 # Get labconfig and generate deployconfig.yaml
35 case "$labname" in
36     intelpod[569]|orangepod[12]|cengnpod[12] )
37         array=(${labname//pod/ })
38         cp ../labconfig/${array[0]}/pod${array[1]}/labconfig.yaml .
39         python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
40         ;;
41     'attvirpod1' )
42         cp ../labconfig/att/virpod1/labconfig.yaml .
43         python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
44         ;;
45     'custom')
46         labfile=$2
47         if [ -e $labfile ]; then
48             cp $labfile ./labconfig.yaml || true
49         else
50             wget $labconfigfile -t 3 -T 10 -O ./labconfig.yaml || true
51             count=`wc -l labconfig.yaml  | cut -d " " -f 1`
52             if [ $count -lt 10 ]; then
53                 rm -rf labconfig.yaml
54             fi
55         fi
56         if [ ! -e ./labconfig.yaml ]; then
57             virtinstall=1
58             labname="default"
59             cp ../labconfig/default/labconfig.yaml ./
60             cp ../labconfig/default/deployconfig.yaml ./
61         else
62             python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
63             labname=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
64         fi
65         ;;
66     * )
67         virtinstall=1
68         labname="default"
69         cp ../labconfig/default/labconfig.yaml ./
70         python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
71         ;;
72 esac
73
74 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < labconfig.yaml > labconfig.json
75 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < deployconfig.yaml > deployconfig.json
76
77 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
78 MAAS_NAME=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
79 API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
80 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
81 PROFILE=ubuntu
82 MY_UPSTREAM_DNS=`grep "upstream_dns" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
83 SSH_KEY=`cat ~/.ssh/id_rsa.pub`
84 MAIN_ARCHIVE=`grep "main_archive" deployconfig.yaml | cut -d ':' -f 2-3 | sed -e 's/ //'`
85 URL=https://images.maas.io/ephemeral-v2/daily/
86 KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
87 SOURCE_ID=1
88 FABRIC_ID=1
89 VLAN_TAG=""
90 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
91 SUBNET_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.cidr | cut -d \" -f 2 `
92 VLAN_TAG="untagged"
93
94 # In the case of a virtual deployment get deployconfig.yaml
95 if [ "$virtinstall" -eq 1 ]; then
96     ./cleanvm.sh || true
97 fi
98
99 #create backup directory
100 mkdir ~/joid_config/ || true
101
102 # Backup deployconfig.yaml in joid_config folder
103
104 if [ -e ./deployconfig.yaml ]; then
105     cp ./deployconfig.yaml ~/joid_config/
106     cp ./labconfig.yaml ~/joid_config/
107 fi
108
109 #
110 # Prepare local environment to avoid password asking
111 #
112
113 # make sure no password asked during the deployment.
114 sudoer_file=/etc/sudoers.d/90-joid-init
115 sudoer_entry="$USER ALL=(ALL) NOPASSWD:ALL"
116 if [ -e $sudoer_file ]; then
117     if ! sudo grep -q "$sudoer_entry" $sudoer_file; then
118         sudo sed -i -e "1i$sudoer_entry" $sudoer_file
119     fi
120 else
121     echo "$sudoer_entry" > 90-joid-init
122     sudo chown root:root 90-joid-init
123     sudo mv 90-joid-init /etc/sudoers.d/
124 fi
125
126 echo "... Deployment of maas Started ...."
127
128 #
129 # Virsh preparation
130 #
131
132 # define the pool and try to start even though its already exist.
133 # For fresh install this may or may not there.
134 sudo adduser $USER libvirtd
135 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
136 sudo virsh pool-start default || true
137 sudo virsh pool-autostart default || true
138
139 # In case of virtual install set network
140 if [ "$virtinstall" -eq 1 ]; then
141     sudo virsh net-dumpxml default > default-net-org.xml
142     sudo sed -i '/dhcp/d' default-net-org.xml
143     sudo sed -i '/range/d' default-net-org.xml
144     sudo virsh net-define default-net-org.xml
145     sudo virsh net-destroy default
146     sudo virsh net-start default
147     rm -f default-net-org.xml
148 fi
149
150 #
151 # Cleanup, juju init and config backup
152 #
153
154 # To avoid problem between apiclient/maas_client and apiclient from google
155 # we remove the package google-api-python-client from yardstick installer
156 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
157     sudo pip uninstall google-api-python-client
158 fi
159
160
161 if [ ! -e ~maas/.ssh/id_rsa.pub ]; then
162     if [ ! -e $HOME/id_rsa_maas.pub ]; then
163         [ -e $HOME/id_rsa_maas ] && rm -f $HOME/id_rsa_maas
164         sudo su - $USER -c "echo |ssh-keygen -t rsa -f $HOME/id_rsa_maas"
165     fi
166     sudo -u maas mkdir ~maas/.ssh/ || true
167     sudo cp $HOME/id_rsa_maas ~maas/.ssh/id_rsa
168     sudo cp $HOME/id_rsa_maas.pub ~maas/.ssh/id_rsa.pub
169     sudo chown maas:maas ~maas/.ssh/id_rsa
170     sudo chown maas:maas ~maas/.ssh/id_rsa.pub
171 fi
172
173 # Ensure virsh can connect without ssh auth
174 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
175 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
176
177 #
178 # MAAS deploy
179 #
180
181 installmaas(){
182     sudo apt-get install maas maas-region-controller -y
183 }
184
185 #
186 # MAAS config
187 # https://insights.ubuntu.com/2016/01/23/maas-setup-deploying-openstack-on-maas-1-9-with-juju/
188 # http://blog.naydenov.net/2016/01/nodes-networking-deploying-openstack-on-maas-1-9-with-juju/
189 #
190 configuremaas(){
191     #reconfigure maas with correct MAAS address.
192     #Below code is needed as MAAS have issue in commisoning without restart.
193     sudo ./maas-reconfigure-region.sh $MAAS_IP
194     sudo maas-rack config --region-url http://$MAAS_IP:5240/MAAS
195
196     sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com --password=ubuntu || true
197     API_KEY=`sudo maas-region apikey --username=ubuntu`
198     maas login $PROFILE $API_SERVERMAAS $API_KEY
199     maas $PROFILE maas set-config name='main_archive' value=$MAIN_ARCHIVE || true
200     maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS || true
201     maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME || true
202     maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com' || true
203     maas $PROFILE sshkeys create "key=$SSH_KEY" || true
204
205     maas $PROFILE tags create name='bootstrap' || true
206     maas $PROFILE tags create name='compute' || true
207     maas $PROFILE tags create name='control' || true
208     maas $PROFILE tags create name='storage' || true
209
210     #create the required spaces.
211     maas $PROFILE space update 0 name=default || true
212     maas $PROFILE spaces create name=unused || true
213     maas $PROFILE spaces create name=admin-api || true
214     maas $PROFILE spaces create name=internal-api || true
215     maas $PROFILE spaces create name=public-api || true
216     maas $PROFILE spaces create name=compute-data || true
217     maas $PROFILE spaces create name=compute-external || true
218     maas $PROFILE spaces create name=storage-data || true
219     maas $PROFILE spaces create name=storage-cluster || true
220
221     maas $PROFILE boot-source update $SOURCE_ID \
222          url=$URL keyring_filename=$KEYRING_FILE || true
223
224     maas $PROFILE boot-resources import || true
225     sleep 10
226
227     while [ "$(maas $PROFILE boot-resources is-importing)" == "true" ];
228     do
229         sleep 60
230     done
231
232     #maas $PROFILE subnet update vlan:<vlan id> name=internal-api space=<0> gateway_ip=10.5.1.1
233     #maas $PROFILE subnet update vlan:<vlan id> name=admin-api space=<2> gateway_ip=10.5.12.1
234     #maas $PROFILE subnet update vlan:<vlan id> name=public-api space=<1> gateway_ip=10.5.15.1
235     #maas $PROFILE subnet update vlan:<vlan id> name=compute-data space=<3> gateway_ip=10.5.17.1
236     #maas $PROFILE subnet update vlan:<vlan id> name=compute-external space=<4> gateway_ip=10.5.19.1
237     #maas $PROFILE subnet update vlan:<vlan id> name=storage-data space=<5> gateway_ip=10.5.20.1
238     #maas $PROFILE subnet update vlan:<vlan id> name=storage-cluster space=<6> gateway_ip=10.5.21.1
239
240 }
241
242 enablesubnetanddhcp(){
243     SUBNET_PREFIX=${SUBNET_CIDR::-5}
244
245     IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
246     IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
247
248     API_KEY=`sudo maas-region apikey --username=ubuntu`
249     maas login $PROFILE $API_SERVERMAAS $API_KEY
250
251     maas $PROFILE ipranges create type=reserved \
252          start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
253          comment='This is a reserved range' || true
254
255     IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
256     IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
257
258     maas $PROFILE ipranges create type=dynamic \
259         start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
260         comment='This is a reserved dynamic range' || true
261
262
263     FABRIC_ID=$(maas $PROFILE subnet read $SUBNET_CIDR | jq '.vlan.fabric_id')
264
265     PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
266
267     maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
268
269     MY_GATEWAY=`cat deployconfig.json | jq '.opnfv.admNetgway' | cut -d \" -f 2`
270     MY_NAMESERVER=`cat deployconfig.json | jq '.opnfv.upstream_dns' | cut -d \" -f 2`
271     maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$MY_GATEWAY || true
272     maas $PROFILE subnet update $SUBNET_CIDR dns_servers=$MY_NAMESERVER || true
273
274     #below command will enable the interface with internal-api space.
275
276     SPACEID=$(maas $PROFILE space read internal-api | jq '.id')
277     maas $PROFILE subnet update $SUBNET_CIDR space=$SPACEID || true
278
279 }
280
281 addnodes(){
282     API_KEY=`sudo maas-region apikey --username=ubuntu`
283     maas login $PROFILE $API_SERVERMAAS $API_KEY
284
285     # make sure there is no machine entry in maas
286     for m in $(maas $PROFILE machines read | jq -r '.[].system_id')
287     do
288         maas ubuntu machine delete $m
289     done
290
291     if [ "$virtinstall" -eq 1 ]; then
292         netw=" --network bridge=virbr0,model=virtio"
293     else
294         brid=`brctl show | grep 8000 | cut -d "8" -f 1 |  tr "\n" " " | tr "\t" " " | tr -s " "`
295
296         netw=""
297         for feature in $brid; do
298             if [ "$feature" == "" ]; then
299                 netw=$netw
300             elif [ "$feature" == "virbr0" ]; then
301                 netw=$netw
302             else
303                 netw=$netw" --network bridge="$feature",model=virtio"
304             fi
305         done
306     fi
307
308     sudo virt-install --connect qemu:///system --name bootstrap --ram 4098 --cpu host --vcpus 2 --video \
309                  cirrus --arch x86_64 --disk size=20,format=qcow2,bus=virtio,io=native,pool=default \
310                  $netw --boot network,hd,menu=off --noautoconsole \
311                  --vnc --print-xml | tee bootstrap
312
313     if [ "$virtinstall" -eq 1 ]; then
314         bootstrapmac=`grep  "mac address" bootstrap | head -1 | cut -d '"' -f 2`
315     else
316         bootstrapmac=""
317         bootstrapmacs=`grep  "mac address" bootstrap| cut -d '"' -f 2`
318         for mac in $bootstrapmacs; do
319             bootstrapmac=$bootstrapmac" mac_addresses="$mac
320         done
321     fi
322     sudo virsh -c qemu:///system define --file bootstrap
323     rm -f bootstrap
324
325     maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
326         tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
327         power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
328         architecture='amd64/generic' power_parameters_power_id='bootstrap'
329
330     bootstrapid=$(maas $PROFILE machines read | jq -r 'select(.[].hostname == "bootstrap")[0].system_id')
331
332     maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
333
334     if [ "$virtinstall" -eq 1 ]; then
335
336         sudo virt-install --connect qemu:///system --name node1-control --ram 8192 --cpu host --vcpus 4 \
337                      --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
338                      $netw $netw --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node1-control
339
340         sudo virt-install --connect qemu:///system --name node2-compute --ram 8192 --cpu host --vcpus 4 \
341                     --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
342                     $netw $netw --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node2-compute
343
344         sudo virt-install --connect qemu:///system --name node5-compute --ram 8192 --cpu host --vcpus 4 \
345                    --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
346                    $netw $netw --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node5-compute
347
348
349         node1controlmac=`grep  "mac address" node1-control | head -1 | cut -d '"' -f 2`
350         node2computemac=`grep  "mac address" node2-compute | head -1 | cut -d '"' -f 2`
351         node5computemac=`grep  "mac address" node5-compute | head -1 | cut -d '"' -f 2`
352
353         sudo virsh -c qemu:///system define --file node1-control
354         sudo virsh -c qemu:///system define --file node2-compute
355         sudo virsh -c qemu:///system define --file node5-compute
356         rm -f node1-control node2-compute node5-compute
357
358
359         maas $PROFILE machines create autodetect_nodegroup='yes' name='node1-control' \
360             tags='control' hostname='node1-control' power_type='virsh' mac_addresses=$node1controlmac \
361             power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
362             architecture='amd64/generic' power_parameters_power_id='node1-control'
363         controlnodeid=$(maas $PROFILE machines read | jq -r 'select(.[].hostname == "node1-control")[0].system_id')
364         maas $PROFILE machines create autodetect_nodegroup='yes' name='node2-compute' \
365             tags='compute' hostname='node2-compute' power_type='virsh' mac_addresses=$node2computemac \
366             power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
367             architecture='amd64/generic' power_parameters_power_id='node2-compute'
368         compute2nodeid=$(maas $PROFILE machines read | jq -r 'select(.[].hostname == "node2-compute")[0].system_id')
369         maas $PROFILE machines create autodetect_nodegroup='yes' name='node5-compute' \
370             tags='compute' hostname='node5-compute' power_type='virsh' mac_addresses=$node5computemac \
371             power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
372             architecture='amd64/generic' power_parameters_power_id='node5-compute'
373         compute5nodeid=$(maas $PROFILE machines read | jq -r 'select(.[].hostname == "node5-compute")[0].system_id')
374
375         maas $PROFILE tag update-nodes control add=$controlnodeid || true
376         maas $PROFILE tag update-nodes compute add=$compute2nodeid || true
377         maas $PROFILE tag update-nodes compute add=$compute5nodeid || true
378     else
379        units=`cat deployconfig.json | jq .opnfv.units`
380
381        until [ $(($units)) -lt 1 ]; do
382            units=$(($units - 1));
383            NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[i].name" | cut -d \" -f 2 `
384            MAC_ADDRESS=`cat labconfig.json | jq ".lab.racks[].nodes[i].nics[] | select(.spaces[]==\"admin\").mac"[0] | cut -d \" -f 2 `
385            POWER_TYPE=`cat labconfig.json | jq ".lab.racks[].nodes[i].power.type" | cut -d \" -f 2 `
386            POWER_IP=`cat labconfig.json |  jq ".lab.racks[].nodes[i].power.address" | cut -d \" -f 2 `
387            POWER_USER=`cat labconfig.json |  jq ".lab.racks[].nodes[i].power.user" | cut -d \" -f 2 `
388            POWER_PASS=`cat labconfig.json |  jq ".lab.racks[].nodes[i].power.pass" | cut -d \" -f 2 `
389
390            maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
391                hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
392                power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS mac_addresses=$MAC_ADDRESS \
393                architecture='amd64/generic'
394        done
395     fi
396
397     # make sure nodes are added into MAAS and none of them is in commisoning state
398     while [ "$(maas $PROFILE nodes read | grep  Commissioning )" ];
399     do
400         sleep 60
401     done
402
403 }
404
405 #configure MAAS with the different options.
406 configuremaas
407
408 #not virtual lab only. Can be done using any physical pod now.
409 enablesubnetanddhcp
410
411 #just make sure rack controller has been synced and import only
412 # just whether images have been imported or not.
413 sleep 120
414
415 #lets add the nodes now. Currently works only for virtual deploymnet.
416 addnodes
417
418 echo "... Deployment of maas finish ...."
419
420 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
421 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
422 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
423
424 #
425 # Functions for MAAS network customization
426 #
427
428 #Below function will mark the interfaces in Auto mode to enbled by MAAS
429 enableautomode() {
430     API_KEY=`sudo maas-region apikey --username=ubuntu`
431     maas login $PROFILE $API_SERVERMAAS $API_KEY
432
433     for node in $(maas $PROFILE nodes read | jq -r '.[].system_id')
434     do
435         maas $PROFILE interface link-subnet $node $1  mode=$2 subnet=$3 || true
436     done
437 }
438
439 #Below function will mark the interfaces in Auto mode to enbled by MAAS
440 # using hostname of the node added into MAAS
441 enableautomodebyname() {
442     API_KEY=`sudo maas-region apikey --username=ubuntu`
443     maas login $PROFILE $API_SERVERMAAS $API_KEY
444
445     if [ ! -z "$4" ]; then
446         for i in `seq 1 7`;
447         do
448             nodes=$(maas $PROFILE nodes read | jq -r '.[].system_id')
449             if [ ! -z "$nodes" ]; then
450                 maas $PROFILE interface link-subnet $nodes $1  mode=$2 subnet=$3 || true
451             fi
452        done
453     fi
454 }
455
456 #Below function will create vlan and update interface with the new vlan
457 # will return the vlan id created
458 crvlanupdsubnet() {
459     API_KEY=`sudo maas-region apikey --username=ubuntu`
460     maas login $PROFILE $API_SERVERMAAS $API_KEY
461
462     # TODO: fix subnet creation and use 'jq'
463     newvlanid=`maas $PROFILE vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
464     maas $PROFILE subnet update $5 vlan=$newvlanid
465     eval "$1"="'$newvlanid'"
466 }
467
468 #Below function will create interface with new vlan and bind to physical interface
469 crnodevlanint() {
470     API_KEY=`sudo maas-region apikey --username=ubuntu`
471     maas login $PROFILE $API_SERVERMAAS $API_KEY
472
473     for node in $(maas $PROFILE nodes read | jq -r '.[].system_id')
474     do
475         interface=$(maas $PROFILE interface read $node $2 | jq -r '.id')
476         maas $PROFILE interfaces create-vlan $node vlan=$1 parent=$interface
477      done
478  }
479
480 #function for JUJU envronment
481
482 addcredential() {
483     API_KEY=`sudo maas-region apikey --username=ubuntu`
484     controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
485     cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
486
487     echo  "credentials:" > credential.yaml
488     echo  "  $controllername:" >> credential.yaml
489     echo  "    opnfv-credentials:" >> credential.yaml
490     echo  "      auth-type: oauth1" >> credential.yaml
491     echo  "      maas-oauth: $API_KEY" >> credential.yaml
492
493     juju add-credential $controllername -f credential.yaml --replace
494 }
495
496 addcloud() {
497     controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
498     cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
499
500     echo "clouds:" > maas-cloud.yaml
501     echo "   $cloudname:" >> maas-cloud.yaml
502     echo "      type: maas" >> maas-cloud.yaml
503     echo "      auth-types: [oauth1]" >> maas-cloud.yaml
504     echo "      endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
505
506     juju add-cloud $cloudname maas-cloud.yaml --replace
507 }
508
509
510 #
511 # VLAN customization
512 #
513
514 case "$labname" in
515     'intelpod9' )
516         maas refresh
517         crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
518         crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
519         crnodevlanint $vlan905 eth1 || true
520         crnodevlanint $vlan905 eth3 || true
521         enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
522         enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
523         enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
524         enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
525         ;;
526 esac
527
528 #
529 # Enable MAAS nodes interfaces
530 #
531
532 #read interface needed in Auto mode and enable it. Will be rmeoved once auto enablement will be implemented in the maas-deployer.
533
534 if [ -e ./deployconfig.yaml ]; then
535   enableiflist=`grep "interface-enable" deployconfig.yaml | cut -d ' ' -f 4 `
536   datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
537   stornet=`grep "storageNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
538   pubnet=`grep "publicNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
539
540   # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
541
542   if [ "$datanet" != "''" ]; then
543       EXTNET=(${enableiflist//,/ })
544       i="0"
545       while [ ! -z "${EXTNET[i]}" ];
546       do
547           enableautomode ${EXTNET[i]} AUTO $datanet || true
548           i=$[$i+1]
549       done
550
551   fi
552   if [ "$stornet" != "''" ]; then
553       EXTNET=(${enableiflist//,/ })
554       i="0"
555       while [ ! -z "${EXTNET[i]}" ];
556       do
557           enableautomode ${EXTNET[i]} AUTO $stornet || true
558           i=$[$i+1]
559       done
560   fi
561   if [ "$pubnet" != "''" ]; then
562       EXTNET=(${enableiflist//,/ })
563       i="0"
564       while [ ! -z "${EXTNET[i]}" ];
565       do
566           enableautomode ${EXTNET[i]} AUTO $pubnet || true
567           i=$[$i+1]
568       done
569   fi
570 fi
571
572
573 # Add the cloud and controller credentials for MAAS for that lab.
574 jujuver=`juju --version`
575
576 if [[ "$jujuver" > "2" ]]; then
577     addcloud
578     addcredential
579 fi
580
581 #
582 # End of scripts
583 #
584 echo " .... MAAS deployment finished successfully ...."