2 #placeholder for deployment script.
8 if [ ! -e $HOME/.ssh/id_rsa ]; then
9 ssh-keygen -N '' -f $HOME/.ssh/id_rsa
12 #install the packages needed
13 sudo apt-add-repository ppa:juju/stable -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 bridge-utils 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 expect -y
23 sudo pip install --upgrade pip
25 #first parameter should be custom and second should be either
26 # absolute location of file (including file name) or url of the
34 # Get labconfig and generate deployconfig.yaml
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
42 cp ../labconfig/att/virpod1/labconfig.yaml .
43 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
47 if [ -e $labfile ]; then
48 cp $labfile ./labconfig.yaml || true
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
56 if [ ! -e ./labconfig.yaml ]; then
59 cp ../labconfig/default/labconfig.yaml ./
60 cp ../labconfig/default/deployconfig.yaml ./
62 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
63 labname=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
69 cp ../labconfig/default/labconfig.yaml ./
70 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
74 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < labconfig.yaml > labconfig.json
75 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < deployconfig.yaml > deployconfig.json
77 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
78 MAAS_NAME=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
79 API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
80 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
82 MY_UPSTREAM_DNS=`grep "upstream_dns" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
83 SSH_KEY=`cat ~/.ssh/id_rsa.pub`
84 MAIN_ARCHIVE=`grep "main_archive" deployconfig.yaml | cut -d ':' -f 2-3 | sed -e 's/ //'`
85 URL=https://images.maas.io/ephemeral-v2/daily/
86 KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
89 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
90 SUBNET_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.cidr | cut -d \" -f 2 `
91 SUBNETDATA_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.cidr | cut -d \" -f 2 `
92 SUBNETPUB_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="public")'.cidr | cut -d \" -f 2 `
93 SUBNETSTOR_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="storage")'.cidr | cut -d \" -f 2 `
94 SUBNETFLOAT_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="floating")'.cidr | cut -d \" -f 2 `
95 VLAN_UNTTAGED="untagged"
97 # In the case of a virtual deployment get deployconfig.yaml
98 if [ "$virtinstall" -eq 1 ]; then
102 #create backup directory
103 mkdir ~/joid_config/ || true
105 # Backup deployconfig.yaml in joid_config folder
107 if [ -e ./deployconfig.yaml ]; then
108 cp ./deployconfig.yaml ~/joid_config/
109 cp ./labconfig.yaml ~/joid_config/
113 # Prepare local environment to avoid password asking
116 # make sure no password asked during the deployment.
117 sudoer_file=/etc/sudoers.d/90-joid-init
118 sudoer_entry="$USER ALL=(ALL) NOPASSWD:ALL"
119 if [ -e $sudoer_file ]; then
120 if ! sudo grep -q "$sudoer_entry" $sudoer_file; then
121 sudo sed -i -e "1i$sudoer_entry" $sudoer_file
124 echo "$sudoer_entry" > 90-joid-init
125 sudo chown root:root 90-joid-init
126 sudo mv 90-joid-init /etc/sudoers.d/
129 echo "... Deployment of maas Started ...."
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
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 rm -f default-net-org.xml
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
164 if [ ! -e ~maas/.ssh/id_rsa.pub ]; then
165 if [ ! -e $HOME/id_rsa_maas.pub ]; then
166 [ -e $HOME/id_rsa_maas ] && rm -f $HOME/id_rsa_maas
167 sudo su - $USER -c "echo |ssh-keygen -t rsa -f $HOME/id_rsa_maas"
169 sudo -u maas mkdir ~maas/.ssh/ || true
170 sudo cp $HOME/id_rsa_maas ~maas/.ssh/id_rsa
171 sudo cp $HOME/id_rsa_maas.pub ~maas/.ssh/id_rsa.pub
172 sudo chown maas:maas ~maas/.ssh/id_rsa
173 sudo chown maas:maas ~maas/.ssh/id_rsa.pub
176 # Ensure virsh can connect without ssh auth
177 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
178 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
185 sudo apt-get install maas maas-region-controller -y
190 # https://insights.ubuntu.com/2016/01/23/maas-setup-deploying-openstack-on-maas-1-9-with-juju/
191 # http://blog.naydenov.net/2016/01/nodes-networking-deploying-openstack-on-maas-1-9-with-juju/
194 #reconfigure maas with correct MAAS address.
195 #Below code is needed as MAAS have issue in commisoning without restart.
196 sudo ./maas-reconfigure-region.sh $MAAS_IP
198 sudo maas-rack config --region-url http://$MAAS_IP:5240/MAAS
200 sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com --password=ubuntu || true
201 API_KEY=`sudo maas-region apikey --username=ubuntu`
202 maas login $PROFILE $API_SERVERMAAS $API_KEY
203 maas $PROFILE maas set-config name='main_archive' value=$MAIN_ARCHIVE || true
204 maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS || true
205 maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME || true
206 maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com' || true
207 maas $PROFILE sshkeys create "key=$SSH_KEY" || true
209 for tag in bootstrap compute control storage
211 maas $PROFILE tags create name=$tag || true
214 #create the required spaces.
215 maas $PROFILE space update 0 name=default || true
216 for space in unused admin-api internal-api public-api compute-data \
217 compute-external storage-data storage-cluster
219 echo "Creating the space $space"
220 maas $PROFILE spaces create name=$space || true
223 #maas $PROFILE boot-source update $SOURCE_ID \
224 # url=$URL keyring_filename=$KEYRING_FILE || true
225 #maas $PROFILE boot-resources import || true
228 while [ "$(maas $PROFILE boot-resources is-importing)" == "true" ];
234 deleteexistingnetw(){
235 NETID_LIST=$(maas $PROFILE subnets read | jq ".[].id")
236 for NETID in $NETW; do
237 maas $PROFILE subnet delete $NETID_LIST
242 # Based on first node we get the fabric mapping
243 NODE_0_MAC_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[0].nics[] ".mac[] | sort -u)
245 for MAC in $NODE_0_MAC_LIST; do
246 # Create a new fabric
247 FABRIC_ID=$(maas $PROFILE fabrics create name=opnfv$FAB_ID| jq --raw-output ".id")
248 # Get the spaces attached to a mac
249 IF_SPACES=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.mac[] | contains(\"$MAC\")) ".spaces[])
250 # Create the network attached to a space
251 for SPACE in $IF_SPACES; do
252 # First check if this space have a vlan
253 SP_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$SPACE\")".vlan)
254 # Create it if needed
255 if ([ $SP_VLAN ] && [ "$SP_VLAN" != "null" ]); then
256 maas $PROFILE vlans create $FABRIC_ID vid=$SP_VLAN
259 SP_VLAN=$VLAN_UNTTAGED
264 'admin') SUBNET_CIDR=$SUBNET_CIDR; JUJU_SPACE="admin"; DHCP='enabled' ;;
265 'data') SUBNET_CIDR=$SUBNETDATA_CIDR; JUJU_SPACE="tenant-data"; DHCP='' ;;
266 'public') SUBNET_CIDR=$SUBNETPUB_CIDR; JUJU_SPACE="public-api"; DHCP='' ;;
267 'storage') SUBNET_CIDR=$SUBNETSTOR_CIDR; JUJU_SPACE="tenant-api"; DHCP='' ;;
268 'floating') SUBNET_CIDR=$SUBNETFLOAT_CIDR; JUJU_SPACE="tenant-public"; DHCP='' ;;
269 *) JUJU_SPACE='null'; DHCP='OFF'; echo " >>> Unknown SPACE" ;;
271 # If we have a network, we create it
272 if ([ $SUBNET_CIDR ] && [ "$SUBNET_CIDR" != "null" ]); then
273 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SUBNET_CIDR $VID
275 GW=$(cat labconfig.json | jq ".opnfv.spaces[] | select(.type==\"$SPACE\")".gateway | cut -d \" -f 2)
276 if ([ $GW ] && [ "$GW" != "null" ]); then
277 maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$GW || true
280 SUBNET_PREFIX=${SUBNET_CIDR::-5}
281 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
282 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
283 IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
284 IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
285 maas $PROFILE ipranges create type=reserved \
286 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
287 comment='This is a reserved range' || true
288 maas $PROFILE ipranges create type=dynamic \
289 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
290 comment='This is a reserved dynamic range' || true
293 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
294 maas $PROFILE vlan update $FABRIC_ID $SP_VLAN dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
302 enablesubnetanddhcp(){
307 SUBNET_PREFIX=${TEMP_CIDR::-5}
309 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
310 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
312 API_KEY=`sudo maas-region apikey --username=ubuntu`
313 maas login $PROFILE $API_SERVERMAAS $API_KEY
315 maas $PROFILE ipranges create type=reserved \
316 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
317 comment='This is a reserved range' || true
319 IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
320 IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
322 maas $PROFILE ipranges create type=dynamic \
323 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
324 comment='This is a reserved dynamic range' || true
326 FABRIC_ID=$(maas $PROFILE subnet read $TEMP_CIDR | jq '.vlan.fabric_id')
328 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
330 if [ "$space" == "admin" ]; then
331 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.gateway | cut -d \" -f 2 `
332 #MY_NAMESERVER=`cat deployconfig.json | jq '.opnfv.upstream_dns' | cut -d \" -f 2`
333 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
334 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
336 #maas $PROFILE subnet update $TEMP_CIDR dns_servers=$MY_NAMESERVER || true
337 #below command will enable the interface with internal-api space.
338 SPACEID=$(maas $PROFILE space read internal-api | jq '.id')
339 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
340 if [ "$enabledhcp" == "true" ]; then
341 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
343 elif [ "$space" == "data" ]; then
344 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.gateway | cut -d \" -f 2 `
345 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
346 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
348 #below command will enable the interface with data-api space for data network.
349 SPACEID=$(maas $PROFILE space read admin-api | jq '.id')
350 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
351 if [ "$enabledhcp" == "true" ]; then
352 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
354 elif [ "$space" == "public" ]; then
355 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.public | cut -d \" -f 2 `
356 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
357 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
359 #below command will enable the interface with public-api space for data network.
360 SPACEID=$(maas $PROFILE space read public-api | jq '.id')
361 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
362 if [ "$enabledhcp" == "true" ]; then
363 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
365 elif [ "$space" == "storage" ]; then
366 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.storage | cut -d \" -f 2 `
367 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
368 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
370 #below command will enable the interface with public-api space for data network.
371 SPACEID=$(maas $PROFILE space read storage-data | jq '.id')
372 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
373 if [ "$enabledhcp" == "true" ]; then
374 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
380 API_KEY=`sudo maas-region apikey --username=ubuntu`
381 maas login $PROFILE $API_SERVERMAAS $API_KEY
383 # make sure there is no machine entry in maas
384 for m in $(maas $PROFILE machines read | jq -r '.[].system_id')
386 maas ubuntu machine delete $m
389 if [ "$virtinstall" -eq 1 ]; then
390 netw=" --network bridge=virbr0,model=virtio"
392 brid=`brctl show | grep 8000 | cut -d "8" -f 1 | tr "\n" " " | tr "\t" " " | tr -s " "`
395 for feature in $brid; do
396 if [ "$feature" == "" ]; then
398 elif [ "$feature" == "virbr0" ]; then
401 netw=$netw" --network bridge="$feature",model=virtio"
406 sudo virt-install --connect qemu:///system --name bootstrap --ram 4098 --cpu host --vcpus 2 --video \
407 cirrus --arch x86_64 --disk size=20,format=qcow2,bus=virtio,io=native,pool=default \
408 $netw --boot network,hd,menu=off --noautoconsole \
409 --vnc --print-xml | tee bootstrap
411 if [ "$virtinstall" -eq 1 ]; then
412 bootstrapmac=`grep "mac address" bootstrap | head -1 | cut -d '"' -f 2`
415 bootstrapmacs=`grep "mac address" bootstrap| cut -d '"' -f 2`
416 for mac in $bootstrapmacs; do
417 bootstrapmac=$bootstrapmac" mac_addresses="$mac
420 sudo virsh -c qemu:///system define --file bootstrap
423 maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
424 tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
425 power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
426 architecture='amd64/generic' power_parameters_power_id='bootstrap'
428 bootstrapid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == "bootstrap").system_id')
430 maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
432 if [ "$virtinstall" -eq 1 ]; then
433 units=`cat deployconfig.json | jq .opnfv.units`
435 until [ $(($units)) -lt 1 ]; do
436 units=$(($units - 1));
437 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
439 sudo virt-install --connect qemu:///system --name $NODE_NAME --ram 8192 --cpu host --vcpus 4 \
440 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
441 $netw $netw --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee $NODE_NAME
443 nodemac=`grep "mac address" $NODE_NAME | head -1 | cut -d '"' -f 2`
444 sudo virsh -c qemu:///system define --file $NODE_NAME
446 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
447 tags='control compute' hostname=$NODE_NAME power_type='virsh' mac_addresses=$nodemac \
448 power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
449 architecture='amd64/generic' power_parameters_power_id=$NODE_NAME
450 nodeid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == '\"$NODE_NAME\"').system_id')
451 maas $PROFILE tag update-nodes control add=$nodeid || true
452 maas $PROFILE tag update-nodes compute add=$nodeid || true
455 units=`cat deployconfig.json | jq .opnfv.units`
457 until [ $(($units)) -lt 1 ]; do
458 units=$(($units - 1));
459 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
460 MAC_ADDRESS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"admin\").mac"[0] | cut -d \" -f 2 `
461 POWER_TYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.type" | cut -d \" -f 2 `
462 POWER_IP=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.address" | cut -d \" -f 2 `
463 POWER_USER=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.user" | cut -d \" -f 2 `
464 POWER_PASS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.pass" | cut -d \" -f 2 `
466 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
467 hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
468 power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS mac_addresses=$MAC_ADDRESS \
469 architecture='amd64/generic'
473 # make sure nodes are added into MAAS and none of them is in commisoning state
474 while [ "$(maas $PROFILE nodes read | grep Commissioning )" ];
481 #configure MAAS with the different options.
484 # functioncall with subnetid to add and second parameter is dhcp enable
485 # third parameter will define the space. It is required to have admin
487 if [ $SUBNET_CIDR ]; then
488 enablesubnetanddhcp $SUBNET_CIDR true admin
490 echo "atleast admin network should be defined"
491 echo "MAAS configuration can not continue"
495 if [ $SUBNETDATA_CIDR ]; then
496 enablesubnetanddhcp $SUBNETDATA_CIDR false data
498 if [ $SUBNETPUB_CIDR ]; then
499 enablesubnetanddhcp $SUBNETPUB_CIDR false public
502 if [ $SUBNETSTOR_CIDR ]; then
503 enablesubnetanddhcp $SUBNETSTOR_CIDR false storage
506 #just make sure rack controller has been synced and import only
507 # just whether images have been imported or not.
510 #lets add the nodes now. Currently works only for virtual deploymnet.
513 echo "... Deployment of maas finish ...."
515 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
516 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
517 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
520 # Functions for MAAS network customization
523 #Below function will mark the interfaces in Auto mode to enbled by MAAS
524 # using hostname of the node added into MAAS
525 enableautomodebyname() {
526 API_KEY=`sudo maas-region apikey --username=ubuntu`
527 maas login $PROFILE $API_SERVERMAAS $API_KEY
529 if [ ! -z "$4" ]; then
532 nodes=$(maas $PROFILE nodes read | jq -r '.[].system_id')
533 if [ ! -z "$nodes" ]; then
534 maas $PROFILE interface link-subnet $nodes $1 mode=$2 subnet=$3 || true
540 #Below function will create vlan and update interface with the new vlan
541 # will return the vlan id created
543 API_KEY=`sudo maas-region apikey --username=ubuntu`
544 maas login $PROFILE $API_SERVERMAAS $API_KEY
546 # TODO: fix subnet creation and use 'jq'
547 newvlanid=`maas $PROFILE vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
548 maas $PROFILE subnet update $5 vlan=$newvlanid
549 eval "$1"="'$newvlanid'"
552 #Below function will create interface with new vlan and bind to physical interface
554 API_KEY=`sudo maas-region apikey --username=ubuntu`
555 maas login $PROFILE $API_SERVERMAAS $API_KEY
557 for node in $(maas $PROFILE nodes read | jq -r '.[].system_id')
559 vlanid=$(maas $PROFILE subnets read | jq '.[].vlan | select(.vid=='$1')'.id)
560 fabricid=`maas $PROFILE subnets read | jq '.[].vlan | select(.vid=='$1')'.fabric_id`
561 interface=`maas $PROFILE interfaces read $node | jq '.[] | select(.vlan.fabric_id=='$fabricid')'.id`
562 maas $PROFILE interfaces create-vlan $node vlan=$vlanid parent=$interface || true
566 #function for JUJU envronment
569 API_KEY=`sudo maas-region apikey --username=ubuntu`
570 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
571 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
573 echo "credentials:" > credential.yaml
574 echo " $controllername:" >> credential.yaml
575 echo " opnfv-credentials:" >> credential.yaml
576 echo " auth-type: oauth1" >> credential.yaml
577 echo " maas-oauth: $API_KEY" >> credential.yaml
579 juju add-credential $controllername -f credential.yaml --replace
583 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
584 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
586 echo "clouds:" > maas-cloud.yaml
587 echo " $cloudname:" >> maas-cloud.yaml
588 echo " type: maas" >> maas-cloud.yaml
589 echo " auth-types: [oauth1]" >> maas-cloud.yaml
590 echo " endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
592 juju add-cloud $cloudname maas-cloud.yaml --replace
602 crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
603 crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
604 crnodevlanint $vlan905 eth1 || true
605 crnodevlanint $vlan905 eth3 || true
606 enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
607 enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
608 enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
609 enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
614 # Enable MAAS nodes interfaces
616 API_KEY=`sudo maas-region apikey --username=ubuntu`
617 maas login $PROFILE $API_SERVERMAAS $API_KEY
619 if [ -e ./labconfig.json ]; then
620 # We will configure all node, so we need the qty, and loop on it
621 NODE_QTY=$(cat labconfig.json | jq --raw-output '.lab.racks[0].nodes[]'.name | wc -l)
622 NODE_QTY=$((NODE_QTY-1))
623 for NODE_ID in $(seq 0 $NODE_QTY); do
624 # Get the NAME/SYS_ID of this node
625 NODE_NAME=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].name")
626 NODE_SYS_ID=$(maas $PROFILE nodes read | jq -r ".[] | select(.hostname==\"$NODE_NAME\")".system_id)
627 echo ">>> Configuring node $NODE_NAME [$NODE_ID][$NODE_SYS_ID]"
628 # Recover the network interfaces list and configure each one
629 # with sorting the list, we have hardware interface first, than the vlan interfaces
630 IF_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] ".ifname )
631 for IF_NAME in $IF_LIST; do
632 # get the space of the interface
633 IF_SPACE=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NAME\") ".spaces[])
635 'data') SUBNET_CIDR=$SUBNETDATA_CIDR; IF_MODE='AUTO' ;;
636 'public') SUBNET_CIDR=$SUBNETPUB_CIDR; IF_MODE='AUTO' ;;
637 'storage') SUBNET_CIDR=$SUBNETSTOR_CIDR; IF_MODE='AUTO' ;;
638 'floating') SUBNET_CIDR=$SUBNETFLOAT_CIDR; IF_MODE='link_up' ;;
639 *) SUBNET_CIDR='null'; IF_MODE='null'; echo " >>> Unknown SPACE" ;;
641 echo " >>> Configuring interface $IF_NAME [$IF_SPACE][$SUBNET_CIDR]"
643 # if we have a vlan parameter in the space config
644 IF_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$IF_SPACE\")".vlan)
645 if ([ -z $IF_VLAN ] && [ $IF_NAME =~ \. ]); then
646 # We have no vlan specified on spaces, but we have a vlan subinterface
647 IF_VLAN = ${IF_NAME##*.}; fi
649 # in case of interface renaming
652 if ([ $IF_NEWNAME ] && [ "$IF_NEWNAME" != "null" ]); then
653 # rename interface if needed
654 IF_MACLOWER=$( cat labconfig.json | jq ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NEWNAME\")".mac[0])
655 IF_MAC=(${IF_MACLOWER,,})
656 IF_ID=$( maas ubuntu interfaces read $NODE_SYS_ID | jq ".[] | select(.mac_address==$IF_MAC)".id)
657 maas $PROFILE interface update $NODE_SYS_ID $IF_ID name=$IF_NEWNAME
661 # In case of a VLAN interface
662 if ([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
663 echo " >>> Configuring VLAN $IF_VLAN"
664 VLANID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".id)
665 FABRICID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".fabric_id)
666 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
667 if [[ -z $INTERFACE ]]; then
668 # parent interface is not set because it does not have a SUBNET_CIDR
669 PARENT_VLANID=$(maas $PROFILE fabrics read | jq ".[].vlans[] | select(.fabric_id==$FABRICID and .name==\"untagged\")".id)
670 # If we need to rename the interface, use new interface name
671 if ([ $IF_NEWNAME ] && [ "$IF_NEWNAME" != "null" ]); then
672 PARENT_IF_NAME=${IF_NEWNAME%%.*}
675 PARENT_IF_NAME=${IF_NAME%%.*}
677 # We set the physical interface to the targeted fabric
678 maas $PROFILE interface update $NODE_SYS_ID $PARENT_IF_NAME vlan=$PARENT_VLANID
680 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
682 maas $PROFILE interfaces create-vlan $NODE_SYS_ID vlan=$VLANID parent=$INTERFACE || true
684 # Configure the interface
685 if ([ $SUBNET_CIDR ] && [ "$SUBNET_CIDR" != "null" ]); then
686 VLANID=$(maas $PROFILE subnet read $SUBNET_CIDR | jq -r '.vlan.id')
687 if !([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
688 # If this interface is not a VLAN (done withe create-vlan)
689 maas $PROFILE interface update $NODE_SYS_ID $IF_NAME vlan=$VLANID
691 maas $PROFILE interface link-subnet $NODE_SYS_ID $IF_NAME mode=$IF_MODE subnet=$SUBNET_CIDR || true
694 echo " >>> Not configuring, we have an empty Subnet CIDR"
701 # Add the cloud and controller credentials for MAAS for that lab.
702 jujuver=`juju --version`
704 if [[ "$jujuver" > "2" ]]; then
712 echo " .... MAAS deployment finished successfully ...."