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