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