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 -y
30 sudo pip install --upgrade pip
32 #first parameter should be custom and second should be either
33 # absolute location of file (including file name) or url of the
41 # Get labconfig and generate deployment.yaml for MAAS and deployconfig.yaml
43 intelpod[569]|orangepod[12]|cengnpod[12] )
44 array=(${labname//pod/ })
45 cp ../labconfig/${array[0]}/pod${array[1]}/labconfig.yaml .
46 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
47 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
50 cp ../labconfig/att/virpod1/labconfig.yaml .
51 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
52 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
55 cp maas/juniper/pod1/deployment.yaml ./deployment.yaml
59 if [ -e $labfile ]; then
60 cp $labfile ./labconfig.yaml || true
62 wget $labconfigfile -t 3 -T 10 -O ./labconfig.yaml || true
63 count=`wc -l labconfig.yaml | cut -d " " -f 1`
64 if [ $count -lt 10 ]; then
68 if [ ! -e ./labconfig.yaml ]; then
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/ //'`
81 MAAS_IP=$(grep " ip_address" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //')
82 MAAS_NAME=`grep "maas_name" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
83 API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
84 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
86 MY_UPSTREAM_DNS=`grep "upstream_dns" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
87 SSH_KEY=`cat ~/.ssh/id_rsa.pub`
88 MAIN_ARCHIVE=`grep "main_archive" deployment.yaml | cut -d ':' -f 2-3 | sed -e 's/ //'`
89 URL=https://images.maas.io/ephemeral-v2/daily/
90 KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
94 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
95 SUBNET_CIDR="192.168.122.0/24"
98 # In the case of a virtual deployment get deployment.yaml and deployconfig.yaml
99 if [ "$virtinstall" -eq 1 ]; then
101 MAAS_IP="192.168.122.1"
102 API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
103 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
104 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
106 cp ../labconfig/default/deployment.yaml ./
107 cp ../labconfig/default/labconfig.yaml ./
108 cp ../labconfig/default/deployconfig.yaml ./
112 # Prepare local environment to avoid password asking
115 # make sure no password asked during the deployment.
116 echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
118 if [ -e /etc/sudoers.d/90-joid-init ]; then
119 sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
120 sudo chown $USER:$USER 91-joid-init
121 sudo chmod 660 91-joid-init
122 sudo cat 90-joid-init >> 91-joid-init
123 sudo chown root:root 91-joid-init
124 sudo mv 91-joid-init /etc/sudoers.d/
126 sudo chown root:root 90-joid-init
127 sudo mv 90-joid-init /etc/sudoers.d/
130 echo "... Deployment of maas Started ...."
136 # define the pool and try to start even though its already exist.
137 # For fresh install this may or may not there.
138 sudo adduser $USER libvirtd
139 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
140 sudo virsh pool-start default || true
141 sudo virsh pool-autostart default || true
143 # In case of virtual install set network
144 if [ "$virtinstall" -eq 1 ]; then
145 sudo virsh net-dumpxml default > default-net-org.xml
146 sudo sed -i '/dhcp/d' default-net-org.xml
147 sudo sed -i '/range/d' default-net-org.xml
148 sudo virsh net-define default-net-org.xml
149 sudo virsh net-destroy default
150 sudo virsh net-start default
154 # Cleanup, juju init and config backup
157 # To avoid problem between apiclient/maas_client and apiclient from google
158 # we remove the package google-api-python-client from yardstick installer
159 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
160 sudo pip uninstall google-api-python-client
163 #create backup directory
164 mkdir ~/joid_config/ || true
165 mkdir ~/.juju/ || true
167 if [ ! -e ~maas/.ssh/id_rsa ]; then
168 sudo -u maas mkdir ~maas/.ssh/
169 sudo -u maas touch ~maas/.ssh/id_rsa
170 sudo -u maas chmod 600 ~maas/.ssh/id_rsa
171 sudo -u maas ssh-keygen -t rsa -f ~maas/.ssh/id_rsa -q -N "" -y
174 # Ensure virsh can connect without ssh auth
175 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
176 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
183 sudo apt-get install maas maas-region-controller -y
190 sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com --password=ubuntu
191 API_KEY=`sudo maas-region apikey --username=ubuntu`
192 maas login $PROFILE $API_SERVERMAAS $API_KEY
193 maas $PROFILE maas set-config name='main_archive' value=$MAIN_ARCHIVE
194 maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS
195 maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME
196 maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com'
197 maas $PROFILE sshkeys create "key=$SSH_KEY"
198 maas $PROFILE boot-source update $SOURCE_ID \
199 url=$URL keyring_filename=$KEYRING_FILE
200 maas $PROFILE boot-source-selections create 1 \
201 release='trusty' arches='amd64' labels='daily' \
202 os='ubuntu' subarches='*'
203 maas $PROFILE boot-resources import
205 while [ "$(maas $PROFILE boot-resources read | grep trusty | wc -l )" -le 0 ];
207 maas $PROFILE boot-resources import
211 maas $PROFILE tags create name='bootstrap'
212 maas $PROFILE tags create name='compute'
213 maas $PROFILE tags create name='control'
214 maas $PROFILE tags create name='storage'
217 enablesubnetanddhcp(){
219 SUBNET_PREFIX="192.168.122"
220 SUBNET_CIDR="($SUBNET_PREFIX).0/24"
222 IP_STATIC_RANGE_LOW="192.168.122.1"
223 IP_STATIC_RANGE_HIGH="192.168.122.49"
225 API_KEY=`sudo maas-region apikey --username=ubuntu`
226 maas login $PROFILE $API_SERVERMAAS $API_KEY
228 maas $PROFILE ipranges create type=reserved \
229 start_ip=$IP_STATIC_RANGE_LOW end_ip=$IP_STATIC_RANGE_HIGH \
230 comment='This is a reserved range'
232 IP_DYNAMIC_RANGE_LOW="192.168.122.50"
233 IP_DYNAMIC_RANGE_HIGH="192.168.122.150"
234 maas $PROFILE ipranges create type=dynamic \
235 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
236 comment='This is a reserved dynamic range'
239 FABRIC_ID=$(maas $PROFILE subnet read $SUBNET_CIDR \
240 | grep fabric | cut -d ' ' -f 10 | cut -d '"' -f 2)
242 PRIMARY_RACK_CONTROLLER=`maas $PROFILE rack-controllers read | grep system_id | cut -d '"' -f 4`
244 maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER
246 MY_GATEWAY="192.168.122.1"
247 MY_NAMESERVER=192.168.122.1
248 maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$MY_GATEWAY
249 maas $PROFILE subnet update $SUBNET_CIDR dns_servers=$MY_NAMESERVER
253 ## derived from https://gist.github.com/epiloque/8cf512c6d64641bde388
254 ## works for arrays of hashes, as long as the hashes do not have arrays
262 fs="$(echo @|tr @ '\034')"
263 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
264 -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
266 indent = length($1)/2;
267 if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
269 for (i in vname) {if (i > indent) {delete vname[i]}}
270 if (length($3) > 0) {
271 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
272 printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
278 sudo virt-install --connect qemu:///system --name bootstrap --ram 4098 --cpu host --vcpus 2 --video \
279 cirrus --arch x86_64 --disk size=20,format=qcow2,bus=virtio,io=native,pool=default \
280 --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole \
281 --vnc --print-xml | tee bootstrap
283 bootstrapmac=`grep "mac address" bootstrap | head -1 | cut -d '"' -f 2`
285 sudo virsh -c qemu:///system define --file bootstrap
287 bootstrapid=`maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
288 tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
289 power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' \
290 architecture='amd64/generic' power_parameters_power_id='bootstrap' | grep system_id | cut -d '"' -f 4 `
292 API_KEY=`sudo maas-region apikey --username=ubuntu`
293 maas login $PROFILE $API_SERVERMAAS $API_KEY
295 maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
300 #sudo chown $USER:$USER environments.yaml
302 echo "... Deployment of maas finish ...."
304 # Backup deployment.yaml and deployconfig.yaml in .juju folder
306 #cp ./environments.yaml ~/.juju/
307 #cp ./environments.yaml ~/joid_config/
309 if [ -e ./deployconfig.yaml ]; then
310 cp ./deployconfig.yaml ~/.juju/
311 cp ./labconfig.yaml ~/.juju/
312 cp ./deployconfig.yaml ~/joid_config/
313 cp ./labconfig.yaml ~/joid_config/
316 if [ -e ./deployment.yaml ]; then
317 cp ./deployment.yaml ~/.juju/
318 cp ./deployment.yaml ~/joid_config/
321 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
322 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
323 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
325 #adding compute and control nodes VM to MAAS for virtual deployment purpose.
326 if [ "$virtinstall" -eq 1 ]; then
327 # create two more VMs to do the deployment.
328 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
330 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
332 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
334 node1controlmac=`grep "mac address" node1-control | head -1 | cut -d '"' -f 2`
335 node2computemac=`grep "mac address" node2-compute | head -1 | cut -d '"' -f 2`
336 node5computemac=`grep "mac address" node5-compute | head -1 | cut -d '"' -f 2`
338 sudo virsh -c qemu:///system define --file node1-control
339 sudo virsh -c qemu:///system define --file node2-compute
340 sudo virsh -c qemu:///system define --file node5-compute
342 API_KEY=`sudo maas-region apikey --username=ubuntu`
343 maas login $PROFILE $API_SERVERMAAS $API_KEY
345 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 `
347 maas $PROFILE tag update-nodes control add=$controlnodeid
349 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 `
351 maas $PROFILE tag update-nodes compute add=$computenodeid
353 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 `
355 maas $PROFILE tag update-nodes compute add=$computenodeid
359 # Functions for MAAS network customization
362 #Below function will mark the interfaces in Auto mode to enbled by MAAS
364 API_KEY=`sudo maas-region apikey --username=ubuntu`
365 maas login $PROFILE $API_SERVERMAAS $API_KEY
367 listofnodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
368 for nodes in $listofnodes
370 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3
374 #Below function will mark the interfaces in Auto mode to enbled by MAAS
375 # using hostname of the node added into MAAS
376 enableautomodebyname() {
377 API_KEY=`sudo maas-region apikey --username=ubuntu`
378 maas login $PROFILE $API_SERVERMAAS $API_KEY
380 if [ ! -z "$4" ]; then
383 nodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
384 if [ ! -z "$nodes" ]; then
385 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3
391 #Below function will create vlan and update interface with the new vlan
392 # will return the vlan id created
394 API_KEY=`sudo maas-region apikey --username=ubuntu`
395 maas login $PROFILE $API_SERVERMAAS $API_KEY
397 newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
398 maas maas subnet update $5 vlan=$newvlanid
399 eval "$1"="'$newvlanid'"
402 #Below function will create interface with new vlan and bind to physical interface
404 API_KEY=`sudo maas-region apikey --username=ubuntu`
405 maas login $PROFILE $API_SERVERMAAS $API_KEY
407 listofnodes=`maas maas nodes read | grep system_id | cut -d '"' -f 4`
409 for nodes in $listofnodes
411 parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
412 maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
416 #function for JUJU envronment
419 API_KEY=`sudo maas-region apikey --username=ubuntu`
420 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
421 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
423 echo "credentials:" > credential.yaml
424 echo " $controllername:" >> credential.yaml
425 echo " opnfv-credentials:" >> credential.yaml
426 echo " auth-type: oauth1" >> credential.yaml
427 echo " maas-oauth: $API_KEY" >> credential.yaml
429 juju add-credential $controllername -f credential.yaml --replace
433 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
434 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
436 echo "clouds:" > maas-cloud.yaml
437 echo " $cloudname:" >> maas-cloud.yaml
438 echo " type: maas" >> maas-cloud.yaml
439 echo " auth-types: [oauth1]" >> maas-cloud.yaml
440 echo " endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
442 juju add-cloud $cloudname maas-cloud.yaml --replace
453 crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
454 crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
455 crnodevlanint $vlan905 eth1 || true
456 crnodevlanint $vlan905 eth3 || true
457 enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
458 enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
459 enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
460 enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
465 # Enable MAAS nodes interfaces
468 #read interface needed in Auto mode and enable it. Will be rmeoved once auto enablement will be implemented in the maas-deployer.
469 if [ -e ~/joid_config/deployconfig.yaml ]; then
470 cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml
471 elif [ -e ~/.juju/deployconfig.yaml ]; then
472 cp ~/.juju/deployconfig.yaml ./deployconfig.yaml
475 if [ -e ./deployconfig.yaml ]; then
476 enableiflist=`grep "interface-enable" deployconfig.yaml | cut -d ' ' -f 4 `
477 datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
478 stornet=`grep "storageNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
479 pubnet=`grep "publicNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
481 # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
483 maas maas spaces create internal "Using for pxe network within the lab"
485 if [ "$datanet" != "''" ]; then
486 EXTNET=(${enableiflist//,/ })
488 while [ ! -z "${EXTNET[i]}" ];
490 enableautomode ${EXTNET[i]} AUTO $datanet || true
493 maas maas spaces create admin "Using for admin network within the lab"
496 if [ "$stornet" != "''" ]; then
497 EXTNET=(${enableiflist//,/ })
499 while [ ! -z "${EXTNET[i]}" ];
501 enableautomode ${EXTNET[i]} AUTO $stornet || true
505 if [ "$pubnet" != "''" ]; then
506 EXTNET=(${enableiflist//,/ })
508 while [ ! -z "${EXTNET[i]}" ];
510 enableautomode ${EXTNET[i]} AUTO $pubnet || true
513 maas maas spaces create public "Using for public network within the lab"
518 # Add the cloud and controller credentials for MAAS for that lab.
519 jujuver=`juju --version`
521 if [ "$jujuver" > "2" ]; then
529 echo " .... MAAS deployment finished successfully ...."