8019bb7a78066e389044f579ebd9626ea3446de4
[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 -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 ]; then
169     sudo -u maas mkdir ~maas/.ssh/
170     sudo -u maas touch ~maas/.ssh/id_rsa
171     sudo -u maas chmod 600 ~maas/.ssh/id_rsa
172     sudo -u maas ssh-keygen  -t rsa -f ~maas/.ssh/id_rsa -q -N "" -y
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
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
197     maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS
198     maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME
199     maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com'
200     maas $PROFILE sshkeys create "key=$SSH_KEY"
201     maas $PROFILE boot-source update $SOURCE_ID \
202          url=$URL keyring_filename=$KEYRING_FILE
203     maas $PROFILE boot-source-selections create 1 \
204          release='trusty' arches='amd64' labels='daily' \
205          os='ubuntu' subarches='*'
206     maas $PROFILE boot-resources import
207
208     while [ "$(maas $PROFILE boot-resources read | grep trusty | wc -l )" -le 0 ];
209     do
210         maas $PROFILE boot-resources import
211         sleep 20
212     done
213
214     maas $PROFILE tags create name='bootstrap'
215     maas $PROFILE tags create name='compute'
216     maas $PROFILE tags create name='control'
217     maas $PROFILE tags create name='storage'
218
219     #create the required spaces.
220     maas $PROFILE space update 0 name=default
221     maas $PROFILE spaces create name=unused
222     maas $PROFILE spaces create name=admin-api
223     maas $PROFILE spaces create name=internal-api
224     maas $PROFILE spaces create name=public-api
225     maas $PROFILE spaces create name=compute-data
226     maas $PROFILE spaces create name=compute-external
227     maas $PROFILE spaces create name=storage-data
228     maas $PROFILE spaces create name=storage-cluster
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'
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'
260
261
262     FABRIC_ID=$(maas $PROFILE subnet read $SUBNET_CIDR \
263                 | grep fabric | cut -d ' ' -f 10 | cut -d '"' -f 2)
264
265     PRIMARY_RACK_CONTROLLER=`maas $PROFILE rack-controllers read  | grep system_id | cut -d '"' -f 4`
266
267     maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER
268
269     MY_GATEWAY="192.168.122.1"
270     MY_NAMESERVER=192.168.122.1
271     maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$MY_GATEWAY
272     maas $PROFILE subnet update $SUBNET_CIDR dns_servers=$MY_NAMESERVER
273
274 }
275
276 ## derived from https://gist.github.com/epiloque/8cf512c6d64641bde388
277 ## works for arrays of hashes, as long as the hashes do not have arrays
278 parse_yaml2() {
279     local prefix=$2
280     local s
281     local w
282     local fs
283     s='[[:space:]]*'
284     w='[a-zA-Z0-9_]*'
285     fs="$(echo @|tr @ '\034')"
286     sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
287         -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
288     awk -F"$fs" '{
289       indent = length($1)/2;
290       if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
291       vname[indent] = $2;
292       for (i in vname) {if (i > indent) {delete vname[i]}}
293       if (length($3) > 0) {
294               vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
295               printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
296       }
297     }' | sed 's/_=/+=/g'
298 }
299
300 addnodes(){
301     sudo virt-install --connect qemu:///system --name bootstrap --ram 4098 --cpu host --vcpus 2 --video \
302                  cirrus --arch x86_64 --disk size=20,format=qcow2,bus=virtio,io=native,pool=default \
303                  --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole \
304                  --vnc --print-xml | tee bootstrap
305
306     bootstrapmac=`grep  "mac address" bootstrap | head -1 | cut -d '"' -f 2`
307
308     sudo virsh -c qemu:///system define --file bootstrap
309
310     bootstrapid=`maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
311                  tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
312                  power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' \
313                  architecture='amd64/generic' power_parameters_power_id='bootstrap' | grep system_id | cut -d '"' -f 4 `
314
315     API_KEY=`sudo maas-region apikey --username=ubuntu`
316     maas login $PROFILE $API_SERVERMAAS $API_KEY
317
318     maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
319 }
320
321 configuremaas
322 addnodes
323 #sudo chown $USER:$USER environments.yaml
324
325 echo "... Deployment of maas finish ...."
326
327 # Backup deployment.yaml and deployconfig.yaml in .juju folder
328
329 #cp ./environments.yaml ~/.juju/
330 #cp ./environments.yaml ~/joid_config/
331
332 if [ -e ./deployconfig.yaml ]; then
333     cp ./deployconfig.yaml ~/.juju/
334     cp ./labconfig.yaml ~/.juju/
335     cp ./deployconfig.yaml ~/joid_config/
336     cp ./labconfig.yaml ~/joid_config/
337 fi
338
339 if [ -e ./deployment.yaml ]; then
340     cp ./deployment.yaml ~/.juju/
341     cp ./deployment.yaml ~/joid_config/
342 fi
343
344 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
345 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
346 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
347
348 #adding compute and control nodes VM to MAAS for virtual deployment purpose.
349 if [ "$virtinstall" -eq 1 ]; then
350     # create two more VMs to do the deployment.
351     sudo virt-install --connect qemu:///system --name node1-control --ram 8192 --cpu host --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node1-control
352
353     sudo virt-install --connect qemu:///system --name node2-compute --ram 8192 --cpu host --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node2-compute
354
355     sudo virt-install --connect qemu:///system --name node5-compute --ram 8192 --cpu host --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node5-compute
356
357     node1controlmac=`grep  "mac address" node1-control | head -1 | cut -d '"' -f 2`
358     node2computemac=`grep  "mac address" node2-compute | head -1 | cut -d '"' -f 2`
359     node5computemac=`grep  "mac address" node5-compute | head -1 | cut -d '"' -f 2`
360
361     sudo virsh -c qemu:///system define --file node1-control
362     sudo virsh -c qemu:///system define --file node2-compute
363     sudo virsh -c qemu:///system define --file node5-compute
364
365     API_KEY=`sudo maas-region apikey --username=ubuntu`
366     maas login $PROFILE $API_SERVERMAAS $API_KEY
367
368     controlnodeid=`maas $PROFILE machines create autodetect_nodegroup='yes' name='node1-control' tags='control' hostname='node1-control' power_type='virsh' mac_addresses=$node1controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node1-control' | grep system_id | cut -d '"' -f 4 `
369
370     maas $PROFILE tag update-nodes control add=$controlnodeid
371
372     computenodeid=`maas $PROFILE machines create autodetect_nodegroup='yes' name='node2-compute' tags='compute' hostname='node2-compute' power_type='virsh' mac_addresses=$node2computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node2-compute' | grep system_id | cut -d '"' -f 4 `
373
374     maas $PROFILE tag update-nodes compute add=$computenodeid
375
376     computenodeid=`maas $PROFILE machines create autodetect_nodegroup='yes' name='node5-compute' tags='compute' hostname='node5-compute' power_type='virsh' mac_addresses=$node5computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node5-compute' | grep system_id | cut -d '"' -f 4 `
377
378     maas $PROFILE tag update-nodes compute add=$computenodeid
379 fi
380
381 #
382 # Functions for MAAS network customization
383 #
384
385 #Below function will mark the interfaces in Auto mode to enbled by MAAS
386 enableautomode() {
387     API_KEY=`sudo maas-region apikey --username=ubuntu`
388     maas login $PROFILE $API_SERVERMAAS $API_KEY
389
390     listofnodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
391     for nodes in $listofnodes
392     do
393         maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
394     done
395 }
396
397 #Below function will mark the interfaces in Auto mode to enbled by MAAS
398 # using hostname of the node added into MAAS
399 enableautomodebyname() {
400     API_KEY=`sudo maas-region apikey --username=ubuntu`
401     maas login $PROFILE $API_SERVERMAAS $API_KEY
402
403     if [ ! -z "$4" ]; then
404         for i in `seq 1 7`;
405         do
406             nodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
407             if [ ! -z "$nodes" ]; then
408                 maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
409             fi
410        done
411     fi
412 }
413
414 #Below function will create vlan and update interface with the new vlan
415 # will return the vlan id created
416 crvlanupdsubnet() {
417     API_KEY=`sudo maas-region apikey --username=ubuntu`
418     maas login $PROFILE $API_SERVERMAAS $API_KEY
419
420     newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
421     maas maas subnet update $5 vlan=$newvlanid
422     eval "$1"="'$newvlanid'"
423 }
424
425 #Below function will create interface with new vlan and bind to physical interface
426 crnodevlanint() {
427     API_KEY=`sudo maas-region apikey --username=ubuntu`
428     maas login $PROFILE $API_SERVERMAAS $API_KEY
429
430     listofnodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
431
432     for nodes in $listofnodes
433     do
434         parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
435         maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
436      done
437  }
438
439 #function for JUJU envronment
440
441 addcredential() {
442     API_KEY=`sudo maas-region apikey --username=ubuntu`
443     controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
444     cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
445
446     echo  "credentials:" > credential.yaml
447     echo  "  $controllername:" >> credential.yaml
448     echo  "    opnfv-credentials:" >> credential.yaml
449     echo  "      auth-type: oauth1" >> credential.yaml
450     echo  "      maas-oauth: $API_KEY" >> credential.yaml
451
452     juju add-credential $controllername -f credential.yaml --replace
453 }
454
455 addcloud() {
456     controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
457     cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
458
459     echo "clouds:" > maas-cloud.yaml
460     echo "   $cloudname:" >> maas-cloud.yaml
461     echo "      type: maas" >> maas-cloud.yaml
462     echo "      auth-types: [oauth1]" >> maas-cloud.yaml
463     echo "      endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
464
465     juju add-cloud $cloudname maas-cloud.yaml --replace
466 }
467
468
469 #
470 # VLAN customization
471 #
472
473 case "$labname" in
474     'intelpod9' )
475         maas refresh
476         crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
477         crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
478         crnodevlanint $vlan905 eth1 || true
479         crnodevlanint $vlan905 eth3 || true
480         enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
481         enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
482         enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
483         enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
484         ;;
485 esac
486
487 #
488 # Enable MAAS nodes interfaces
489 #
490
491 #read interface needed in Auto mode and enable it. Will be rmeoved once auto enablement will be implemented in the maas-deployer.
492 if [ -e ~/joid_config/deployconfig.yaml ]; then
493   cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml
494 elif [ -e ~/.juju/deployconfig.yaml ]; then
495   cp ~/.juju/deployconfig.yaml ./deployconfig.yaml
496 fi
497
498 if [ -e ./deployconfig.yaml ]; then
499   enableiflist=`grep "interface-enable" deployconfig.yaml | cut -d ' ' -f 4 `
500   datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
501   stornet=`grep "storageNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
502   pubnet=`grep "publicNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
503
504   # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
505
506   maas maas spaces create internal "Using for pxe network within the lab"
507
508   if [ "$datanet" != "''" ]; then
509       EXTNET=(${enableiflist//,/ })
510       i="0"
511       while [ ! -z "${EXTNET[i]}" ];
512       do
513           enableautomode ${EXTNET[i]} AUTO $datanet || true
514           i=$[$i+1]
515       done
516       maas maas spaces create admin "Using for admin network within the lab"
517
518   fi
519   if [ "$stornet" != "''" ]; then
520       EXTNET=(${enableiflist//,/ })
521       i="0"
522       while [ ! -z "${EXTNET[i]}" ];
523       do
524           enableautomode ${EXTNET[i]} AUTO $stornet || true
525           i=$[$i+1]
526       done
527   fi
528   if [ "$pubnet" != "''" ]; then
529       EXTNET=(${enableiflist//,/ })
530       i="0"
531       while [ ! -z "${EXTNET[i]}" ];
532       do
533           enableautomode ${EXTNET[i]} AUTO $pubnet || true
534           i=$[$i+1]
535       done
536       maas maas spaces create public "Using for public network within the lab"
537   fi
538 fi
539
540
541 # Add the cloud and controller credentials for MAAS for that lab.
542 jujuver=`juju --version`
543
544 if [ "$jujuver" > "2" ]; then
545     addcloud
546     addcredential
547 fi
548
549 #
550 # End of scripts
551 #
552 echo " .... MAAS deployment finished successfully ...."