2 #placeholder for deployment script.
5 maasver=`apt-cache policy maas | grep Installed | cut -d ':' -f 2 | sed -e 's/ //'`
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
16 if [ ! -e $HOME/.ssh/id_rsa ]; then
17 ssh-keygen -N '' -f $HOME/.ssh/id_rsa
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
31 sudo pip install --upgrade pip
33 #first parameter should be custom and second should be either
34 # absolute location of file (including file name) or url of the
42 # Get labconfig and generate deployment.yaml for MAAS and deployconfig.yaml
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
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
56 cp maas/juniper/pod1/deployment.yaml ./deployment.yaml
60 if [ -e $labfile ]; then
61 cp $labfile ./labconfig.yaml || true
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
69 if [ ! -e ./labconfig.yaml ]; then
72 cp ../labconfig/default/deployment.yaml ./
73 cp ../labconfig/default/labconfig.yaml ./
74 cp ../labconfig/default/deployconfig.yaml ./
76 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
77 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
78 labname=`grep "maas_name" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
84 cp ../labconfig/default/deployment.yaml ./
85 cp ../labconfig/default/labconfig.yaml ./
86 cp ../labconfig/default/deployconfig.yaml ./
90 MAAS_IP=$(grep " ip_address" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //')
91 MAAS_NAME=`grep "maas_name" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
92 API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
93 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
95 MY_UPSTREAM_DNS=`grep "upstream_dns" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
96 SSH_KEY=`cat ~/.ssh/id_rsa.pub`
97 MAIN_ARCHIVE=`grep "main_archive" deployment.yaml | cut -d ':' -f 2-3 | sed -e 's/ //'`
98 URL=https://images.maas.io/ephemeral-v2/daily/
99 KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
103 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
104 SUBNET_CIDR="192.168.122.0/24"
107 # In the case of a virtual deployment get deployment.yaml and deployconfig.yaml
108 if [ "$virtinstall" -eq 1 ]; then
109 MAAS_IP="192.168.122.1"
110 API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
111 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
112 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
116 #create backup directory
117 mkdir ~/joid_config/ || true
119 # Backup deployment.yaml and deployconfig.yaml in joid_config folder
121 if [ -e ./deployconfig.yaml ]; then
122 cp ./deployconfig.yaml ~/joid_config/
123 cp ./labconfig.yaml ~/joid_config/
126 if [ -e ./deployment.yaml ]; then
127 cp ./deployment.yaml ~/joid_config/
132 # Prepare local environment to avoid password asking
135 # make sure no password asked during the deployment.
136 echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
138 if [ -e /etc/sudoers.d/90-joid-init ]; then
139 sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
140 sudo chown $USER:$USER 91-joid-init
141 sudo chmod 660 91-joid-init
142 sudo cat 90-joid-init >> 91-joid-init
143 sudo chown root:root 91-joid-init
144 sudo mv 91-joid-init /etc/sudoers.d/
146 sudo chown root:root 90-joid-init
147 sudo mv 90-joid-init /etc/sudoers.d/
150 echo "... Deployment of maas Started ...."
156 # define the pool and try to start even though its already exist.
157 # For fresh install this may or may not there.
158 sudo adduser $USER libvirtd
159 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
160 sudo virsh pool-start default || true
161 sudo virsh pool-autostart default || true
163 # In case of virtual install set network
164 if [ "$virtinstall" -eq 1 ]; then
165 sudo virsh net-dumpxml default > default-net-org.xml
166 sudo sed -i '/dhcp/d' default-net-org.xml
167 sudo sed -i '/range/d' default-net-org.xml
168 sudo virsh net-define default-net-org.xml
169 sudo virsh net-destroy default
170 sudo virsh net-start default
174 # Cleanup, juju init and config backup
177 # To avoid problem between apiclient/maas_client and apiclient from google
178 # we remove the package google-api-python-client from yardstick installer
179 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
180 sudo pip uninstall google-api-python-client
184 if [ ! -e ~maas/.ssh/id_rsa.pub ]; then
185 sudo su - $USER -c "echo |ssh-keygen -t rsa -f $HOME/id_rsa_maas"
186 sudo -u maas mkdir ~maas/.ssh/ || true
187 sudo cp $HOME/id_rsa_maas ~maas/.ssh/id_rsa
188 sudo cp $HOME/id_rsa_maas.pub ~maas/.ssh/id_rsa.pub
189 sudo chown maas:maas ~maas/.ssh/id_rsa
190 sudo chown maas:maas ~maas/.ssh/id_rsa.pub
193 # Ensure virsh can connect without ssh auth
194 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
195 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
202 sudo apt-get install maas maas-region-controller -y
207 # https://insights.ubuntu.com/2016/01/23/maas-setup-deploying-openstack-on-maas-1-9-with-juju/
208 # http://blog.naydenov.net/2016/01/nodes-networking-deploying-openstack-on-maas-1-9-with-juju/
211 sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com --password=ubuntu || true
212 API_KEY=`sudo maas-region apikey --username=ubuntu`
213 maas login $PROFILE $API_SERVERMAAS $API_KEY
214 maas $PROFILE maas set-config name='main_archive' value=$MAIN_ARCHIVE || true
215 maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS || true
216 maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME || true
217 maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com' || true
218 maas $PROFILE sshkeys create "key=$SSH_KEY" || true
219 maas $PROFILE boot-source update $SOURCE_ID \
220 url=$URL keyring_filename=$KEYRING_FILE || true
221 maas $PROFILE boot-source-selections create 1 \
222 release='trusty' arches='amd64' labels='daily' \
223 os='ubuntu' subarches='*' || true
224 maas $PROFILE boot-resources import || true
226 while [ "$(maas $PROFILE boot-resources read | grep trusty | wc -l )" -le 0 ];
228 maas $PROFILE boot-resources import || true
232 maas $PROFILE tags create name='bootstrap' || true
233 maas $PROFILE tags create name='compute' || true
234 maas $PROFILE tags create name='control' || true
235 maas $PROFILE tags create name='storage' || true
237 #create the required spaces.
238 maas $PROFILE space update 0 name=default || true
239 maas $PROFILE spaces create name=unused || true
240 maas $PROFILE spaces create name=admin-api || true
241 maas $PROFILE spaces create name=internal-api || true
242 maas $PROFILE spaces create name=public-api || true
243 maas $PROFILE spaces create name=compute-data || true
244 maas $PROFILE spaces create name=compute-external || true
245 maas $PROFILE spaces create name=storage-data || true
246 maas $PROFILE spaces create name=storage-cluster || true
248 #maas $PROFILE subnet update vlan:<vlan id> name=internal-api space=<0> gateway_ip=10.5.1.1
249 #maas $PROFILE subnet update vlan:<vlan id> name=admin-api space=<2> gateway_ip=10.5.12.1
250 #maas $PROFILE subnet update vlan:<vlan id> name=public-api space=<1> gateway_ip=10.5.15.1
251 #maas $PROFILE subnet update vlan:<vlan id> name=compute-data space=<3> gateway_ip=10.5.17.1
252 #maas $PROFILE subnet update vlan:<vlan id> name=compute-external space=<4> gateway_ip=10.5.19.1
253 #maas $PROFILE subnet update vlan:<vlan id> name=storage-data space=<5> gateway_ip=10.5.20.1
254 #maas $PROFILE subnet update vlan:<vlan id> name=storage-cluster space=<6> gateway_ip=10.5.21.1
258 enablesubnetanddhcp(){
260 SUBNET_PREFIX="192.168.122"
261 SUBNET_CIDR="($SUBNET_PREFIX).0/24"
263 IP_STATIC_RANGE_LOW="192.168.122.1"
264 IP_STATIC_RANGE_HIGH="192.168.122.49"
266 API_KEY=`sudo maas-region apikey --username=ubuntu`
267 maas login $PROFILE $API_SERVERMAAS $API_KEY
269 maas $PROFILE ipranges create type=reserved \
270 start_ip=$IP_STATIC_RANGE_LOW end_ip=$IP_STATIC_RANGE_HIGH \
271 comment='This is a reserved range' || true
273 IP_DYNAMIC_RANGE_LOW="192.168.122.50"
274 IP_DYNAMIC_RANGE_HIGH="192.168.122.150"
275 maas $PROFILE ipranges create type=dynamic \
276 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
277 comment='This is a reserved dynamic range' || true
280 FABRIC_ID=$(maas $PROFILE subnet read $SUBNET_CIDR \
281 | grep fabric | cut -d ' ' -f 10 | cut -d '"' -f 2)
283 PRIMARY_RACK_CONTROLLER=`maas $PROFILE rack-controllers read | grep system_id | cut -d '"' -f 4`
285 maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
287 MY_GATEWAY="192.168.122.1"
288 MY_NAMESERVER=192.168.122.1
289 maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$MY_GATEWAY || true
290 maas $PROFILE subnet update $SUBNET_CIDR dns_servers=$MY_NAMESERVER || true
294 ## derived from https://gist.github.com/epiloque/8cf512c6d64641bde388
295 ## works for arrays of hashes, as long as the hashes do not have arrays
303 fs="$(echo @|tr @ '\034')"
304 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
305 -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
307 indent = length($1)/2;
308 if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
310 for (i in vname) {if (i > indent) {delete vname[i]}}
311 if (length($3) > 0) {
312 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
313 printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
319 API_KEY=`sudo maas-region apikey --username=ubuntu`
320 maas login $PROFILE $API_SERVERMAAS $API_KEY
322 # make sure there is no machine entry in maas
323 for m in `maas $PROFILE machines read | grep system_id | cut -d '"' -f4 | sort | uniq`
325 maas ubuntu machine delete $m
328 if [ "$virtinstall" -eq 1 ]; then
331 brid=`brctl show | grep 8000 | cut -d "8" -f 1 | tr "\n" " " | tr "\t" " " | tr -s " "`
334 for feature in $brid; do
335 if [ "$feature" == "" ]; then
338 netw=$netw" --network bridge="$feature",model=virtio"
343 sudo virt-install --connect qemu:///system --name bootstrap --ram 4098 --cpu host --vcpus 2 --video \
344 cirrus --arch x86_64 --disk size=20,format=qcow2,bus=virtio,io=native,pool=default \
345 $netw --boot network,hd,menu=off --noautoconsole \
346 --vnc --print-xml | tee bootstrap
347 if [ "$virtinstall" -eq 1 ]; then
348 bootstrapmac=`grep "mac address" bootstrap | head -1 | cut -d '"' -f 2`
351 bootstrapmacs=`grep "mac address" bootstrap| cut -d "'" -f 2`
352 for mac in $bootstrapmacs; do
353 bootstrapmac=$bootstrapmac" mac_addresses="$mac
356 sudo virsh -c qemu:///system define --file bootstrap
358 bootstrap=`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 bootstrapid=`echo "$bootstrap" | grep -m1 'system_id' | cut -d '"' -f 4`
364 maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
366 if [ "$virtinstall" -eq 1 ]; then
368 sudo virt-install --connect qemu:///system --name node1-control --ram 8192 --cpu host --vcpus 4 \
369 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
370 --network bridge=virbr0,model=virtio $netw \
371 --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node1-control
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 --network bridge=virbr0,model=virtio $netw \
376 --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node2-compute
378 sudo virt-install --connect qemu:///system --name node5-compute --ram 8192 --cpu host --vcpus 4 \
379 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
380 --network bridge=virbr0,model=virtio $netw \
381 --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node5-compute
384 node1controlmac=`grep "mac address" node1-control | head -1 | cut -d '"' -f 2`
385 node2computemac=`grep "mac address" node2-compute | head -1 | cut -d '"' -f 2`
386 node5computemac=`grep "mac address" node5-compute | head -1 | cut -d '"' -f 2`
388 sudo virsh -c qemu:///system define --file node1-control
389 sudo virsh -c qemu:///system define --file node2-compute
390 sudo virsh -c qemu:///system define --file node5-compute
393 controlnode=`maas $PROFILE machines create autodetect_nodegroup='yes' name='node1-control' \
394 tags='control' hostname='node1-control' power_type='virsh' mac_addresses=$node1controlmac \
395 power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
396 architecture='amd64/generic' power_parameters_power_id='node1-control'`
397 controlnodeid=`echo "$controlnode" | grep -m1 'system_id' | cut -d '"' -f 4`
398 computenode2=`maas $PROFILE machines create autodetect_nodegroup='yes' name='node2-compute' \
399 tags='compute' hostname='node2-compute' power_type='virsh' mac_addresses=$node2computemac \
400 power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
401 architecture='amd64/generic' power_parameters_power_id='node2-compute'`
402 computenode2id=`echo "$computenode2" | grep -m1 'system_id' | cut -d '"' -f 4`
403 computenode5=`maas $PROFILE machines create autodetect_nodegroup='yes' name='node5-compute' \
404 tags='compute' hostname='node5-compute' power_type='virsh' mac_addresses=$node5computemac \
405 power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
406 architecture='amd64/generic' power_parameters_power_id='node5-compute'`
407 computenode5id=`echo "$computenode5" | grep -m1 'system_id' | cut -d '"' -f 4`
409 maas $PROFILE tag update-nodes control add=$controlnodeid || true
410 maas $PROFILE tag update-nodes compute add=$compute2nodeid || true
411 maas $PROFILE tag update-nodes compute add=$compute5nodeid || true
416 if [ "$virtinstall" -eq 1 ]; then
420 #sudo chown $USER:$USER environments.yaml
422 echo "... Deployment of maas finish ...."
424 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
425 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
426 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
429 # Functions for MAAS network customization
432 #Below function will mark the interfaces in Auto mode to enbled by MAAS
434 API_KEY=`sudo maas-region apikey --username=ubuntu`
435 maas login $PROFILE $API_SERVERMAAS $API_KEY
437 listofnodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
438 for nodes in $listofnodes
440 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3 || true
444 #Below function will mark the interfaces in Auto mode to enbled by MAAS
445 # using hostname of the node added into MAAS
446 enableautomodebyname() {
447 API_KEY=`sudo maas-region apikey --username=ubuntu`
448 maas login $PROFILE $API_SERVERMAAS $API_KEY
450 if [ ! -z "$4" ]; then
453 nodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
454 if [ ! -z "$nodes" ]; then
455 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3 || true
461 #Below function will create vlan and update interface with the new vlan
462 # will return the vlan id created
464 API_KEY=`sudo maas-region apikey --username=ubuntu`
465 maas login $PROFILE $API_SERVERMAAS $API_KEY
467 newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
468 maas maas subnet update $5 vlan=$newvlanid
469 eval "$1"="'$newvlanid'"
472 #Below function will create interface with new vlan and bind to physical interface
474 API_KEY=`sudo maas-region apikey --username=ubuntu`
475 maas login $PROFILE $API_SERVERMAAS $API_KEY
477 listofnodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
479 for nodes in $listofnodes
481 parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
482 maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
486 #function for JUJU envronment
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`
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
499 juju add-credential $controllername -f credential.yaml --replace
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`
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
512 juju add-cloud $cloudname maas-cloud.yaml --replace
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
535 # Enable MAAS nodes interfaces
538 #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 ./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/ //'`
546 # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
548 if [ "$datanet" != "''" ]; then
549 EXTNET=(${enableiflist//,/ })
551 while [ ! -z "${EXTNET[i]}" ];
553 enableautomode ${EXTNET[i]} AUTO $datanet || true
558 if [ "$stornet" != "''" ]; then
559 EXTNET=(${enableiflist//,/ })
561 while [ ! -z "${EXTNET[i]}" ];
563 enableautomode ${EXTNET[i]} AUTO $stornet || true
567 if [ "$pubnet" != "''" ]; then
568 EXTNET=(${enableiflist//,/ })
570 while [ ! -z "${EXTNET[i]}" ];
572 enableautomode ${EXTNET[i]} AUTO $pubnet || true
579 # Add the cloud and controller credentials for MAAS for that lab.
580 jujuver=`juju --version`
582 if [ "$jujuver" > "2" ]; then
590 echo " .... MAAS deployment finished successfully ...."