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