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" ];
235 # Based on first node we get the fabric mapping
236 NODE_0_MAC_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[0].nics[] ".mac[] | sort -u)
238 for MAC in $NODE_0_MAC_LIST; do
239 # Create a new fabric
240 # SPACE_ID=$(maas $PROFILE fabrics create name=opnfv$FAB_ID| jq --raw-output ".id")
241 FABRIC_ID=$(maas $PROFILE fabric read opnfv$FAB_ID| jq --raw-output ".id")
242 # Get the spaces attached to a mac
243 IF_SPACES=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.mac[] | contains(\"$MAC\")) ".spaces[])
244 # Create the network attached to a space
245 for SPACE in $IF_SPACES; do
246 # First check if this space have a vlan
247 SP_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$SPACE\")".vlan)
248 # Create it if needed
249 if ([ $SP_VLAN ] && [ "$SP_VLAN" != "null" ]); then
250 maas $PROFILE vlans create $FABRIC_ID vid=$SP_VLAN
253 SP_VLAN=$VLAN_UNTTAGED
258 'admin') SUBNET_CIDR=$SUBNET_CIDR; JUJU_SPACE="admin"; DHCP='enabled' ;;
259 'data') SUBNET_CIDR=$SUBNETDATA_CIDR; JUJU_SPACE="tenant-data"; DHCP='' ;;
260 'public') SUBNET_CIDR=$SUBNETPUB_CIDR; JUJU_SPACE="public-api"; DHCP='' ;;
261 'storage') SUBNET_CIDR=$SUBNETSTOR_CIDR; JUJU_SPACE="tenant-api"; DHCP='' ;;
262 'floating') SUBNET_CIDR=$SUBNETFLOAT_CIDR; JUJU_SPACE="tenant-public"; DHCP='' ;;
263 *) JUJU_SPACE='null'; DHCP='OFF'; echo " >>> Unknown SPACE" ;;
265 # If we have a network, we create it
266 if ([ $SUBNET_CIDR ] && [ "$SUBNET_CIDR" != "null" ]); then
267 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SUBNET_CIDR $VID
269 GW=$(cat labconfig.json | jq ".opnfv.spaces[] | select(.type==\"$SPACE\")".gateway | cut -d \" -f 2)
270 if ([ $GW ] && [ "$GW" != "null" ]); then
271 maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$GW || true
274 SUBNET_PREFIX=${SUBNET_CIDR::-5}
275 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
276 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
277 IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
278 IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
279 maas $PROFILE ipranges create type=reserved \
280 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
281 comment='This is a reserved range' || true
282 maas $PROFILE ipranges create type=dynamic \
283 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
284 comment='This is a reserved dynamic range' || true
287 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
288 maas $PROFILE vlan update $FABRIC_ID $SP_VLAN dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
296 enablesubnetanddhcp(){
301 SUBNET_PREFIX=${TEMP_CIDR::-5}
303 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
304 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
306 API_KEY=`sudo maas-region apikey --username=ubuntu`
307 maas login $PROFILE $API_SERVERMAAS $API_KEY
309 maas $PROFILE ipranges create type=reserved \
310 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
311 comment='This is a reserved range' || true
313 IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
314 IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
316 maas $PROFILE ipranges create type=dynamic \
317 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
318 comment='This is a reserved dynamic range' || true
320 FABRIC_ID=$(maas $PROFILE subnet read $TEMP_CIDR | jq '.vlan.fabric_id')
322 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
324 if [ "$space" == "admin" ]; then
325 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.gateway | cut -d \" -f 2 `
326 #MY_NAMESERVER=`cat deployconfig.json | jq '.opnfv.upstream_dns' | cut -d \" -f 2`
327 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
328 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
330 #maas $PROFILE subnet update $TEMP_CIDR dns_servers=$MY_NAMESERVER || true
331 #below command will enable the interface with internal-api space.
332 SPACEID=$(maas $PROFILE space read internal-api | jq '.id')
333 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
334 if [ "$enabledhcp" == "true" ]; then
335 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
337 elif [ "$space" == "data" ]; then
338 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.gateway | cut -d \" -f 2 `
339 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
340 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
342 #below command will enable the interface with data-api space for data network.
343 SPACEID=$(maas $PROFILE space read admin-api | jq '.id')
344 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
345 if [ "$enabledhcp" == "true" ]; then
346 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
348 elif [ "$space" == "public" ]; then
349 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.public | cut -d \" -f 2 `
350 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
351 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
353 #below command will enable the interface with public-api space for data network.
354 SPACEID=$(maas $PROFILE space read public-api | jq '.id')
355 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
356 if [ "$enabledhcp" == "true" ]; then
357 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
359 elif [ "$space" == "storage" ]; then
360 MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.storage | cut -d \" -f 2 `
361 if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
362 maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
364 #below command will enable the interface with public-api space for data network.
365 SPACEID=$(maas $PROFILE space read storage-data | jq '.id')
366 maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
367 if [ "$enabledhcp" == "true" ]; then
368 maas $PROFILE vlan update $FABRIC_ID $VLAN_UNTTAGED dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
374 API_KEY=`sudo maas-region apikey --username=ubuntu`
375 maas login $PROFILE $API_SERVERMAAS $API_KEY
377 # make sure there is no machine entry in maas
378 for m in $(maas $PROFILE machines read | jq -r '.[].system_id')
380 maas ubuntu machine delete $m
383 if [ "$virtinstall" -eq 1 ]; then
384 netw=" --network bridge=virbr0,model=virtio"
386 brid=`brctl show | grep 8000 | cut -d "8" -f 1 | tr "\n" " " | tr "\t" " " | tr -s " "`
389 for feature in $brid; do
390 if [ "$feature" == "" ]; then
392 elif [ "$feature" == "virbr0" ]; then
395 netw=$netw" --network bridge="$feature",model=virtio"
400 sudo virt-install --connect qemu:///system --name bootstrap --ram 4098 --cpu host --vcpus 2 --video \
401 cirrus --arch x86_64 --disk size=20,format=qcow2,bus=virtio,io=native,pool=default \
402 $netw --boot network,hd,menu=off --noautoconsole \
403 --vnc --print-xml | tee bootstrap
405 if [ "$virtinstall" -eq 1 ]; then
406 bootstrapmac=`grep "mac address" bootstrap | head -1 | cut -d '"' -f 2`
409 bootstrapmacs=`grep "mac address" bootstrap| cut -d '"' -f 2`
410 for mac in $bootstrapmacs; do
411 bootstrapmac=$bootstrapmac" mac_addresses="$mac
414 sudo virsh -c qemu:///system define --file bootstrap
417 maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
418 tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
419 power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
420 architecture='amd64/generic' power_parameters_power_id='bootstrap'
422 bootstrapid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == "bootstrap").system_id')
424 maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
426 if [ "$virtinstall" -eq 1 ]; then
427 units=`cat deployconfig.json | jq .opnfv.units`
429 until [ $(($units)) -lt 1 ]; do
430 units=$(($units - 1));
431 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
433 sudo virt-install --connect qemu:///system --name $NODE_NAME --ram 8192 --cpu host --vcpus 4 \
434 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
435 $netw $netw --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee $NODE_NAME
437 nodemac=`grep "mac address" $NODE_NAME | head -1 | cut -d '"' -f 2`
438 sudo virsh -c qemu:///system define --file $NODE_NAME
440 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
441 tags='control compute' hostname=$NODE_NAME power_type='virsh' mac_addresses=$nodemac \
442 power_parameters_power_address='qemu+ssh://'$USER'@'$MAAS_IP'/system' \
443 architecture='amd64/generic' power_parameters_power_id=$NODE_NAME
444 nodeid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == '\"$NODE_NAME\"').system_id')
445 maas $PROFILE tag update-nodes control add=$nodeid || true
446 maas $PROFILE tag update-nodes compute add=$nodeid || true
449 units=`cat deployconfig.json | jq .opnfv.units`
451 until [ $(($units)) -lt 1 ]; do
452 units=$(($units - 1));
453 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
454 MAC_ADDRESS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"admin\").mac"[0] | cut -d \" -f 2 `
455 POWER_TYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.type" | cut -d \" -f 2 `
456 POWER_IP=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.address" | cut -d \" -f 2 `
457 POWER_USER=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.user" | cut -d \" -f 2 `
458 POWER_PASS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.pass" | cut -d \" -f 2 `
460 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
461 hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
462 power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS mac_addresses=$MAC_ADDRESS \
463 architecture='amd64/generic'
467 # make sure nodes are added into MAAS and none of them is in commisoning state
468 while [ "$(maas $PROFILE nodes read | grep Commissioning )" ];
475 #configure MAAS with the different options.
478 # functioncall with subnetid to add and second parameter is dhcp enable
479 # third parameter will define the space. It is required to have admin
481 if [ $SUBNET_CIDR ]; then
482 enablesubnetanddhcp $SUBNET_CIDR true admin
484 echo "atleast admin network should be defined"
485 echo "MAAS configuration can not continue"
489 if [ $SUBNETDATA_CIDR ]; then
490 enablesubnetanddhcp $SUBNETDATA_CIDR false data
492 if [ $SUBNETPUB_CIDR ]; then
493 enablesubnetanddhcp $SUBNETPUB_CIDR false public
496 if [ $SUBNETSTOR_CIDR ]; then
497 enablesubnetanddhcp $SUBNETSTOR_CIDR false storage
500 #just make sure rack controller has been synced and import only
501 # just whether images have been imported or not.
504 #lets add the nodes now. Currently works only for virtual deploymnet.
507 echo "... Deployment of maas finish ...."
509 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
510 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
511 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
514 # Functions for MAAS network customization
517 #Below function will mark the interfaces in Auto mode to enbled by MAAS
518 # using hostname of the node added into MAAS
519 enableautomodebyname() {
520 API_KEY=`sudo maas-region apikey --username=ubuntu`
521 maas login $PROFILE $API_SERVERMAAS $API_KEY
523 if [ ! -z "$4" ]; then
526 nodes=$(maas $PROFILE nodes read | jq -r '.[].system_id')
527 if [ ! -z "$nodes" ]; then
528 maas $PROFILE interface link-subnet $nodes $1 mode=$2 subnet=$3 || true
534 #Below function will create vlan and update interface with the new vlan
535 # will return the vlan id created
537 API_KEY=`sudo maas-region apikey --username=ubuntu`
538 maas login $PROFILE $API_SERVERMAAS $API_KEY
540 # TODO: fix subnet creation and use 'jq'
541 newvlanid=`maas $PROFILE vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
542 maas $PROFILE subnet update $5 vlan=$newvlanid
543 eval "$1"="'$newvlanid'"
546 #Below function will create interface with new vlan and bind to physical interface
548 API_KEY=`sudo maas-region apikey --username=ubuntu`
549 maas login $PROFILE $API_SERVERMAAS $API_KEY
551 for node in $(maas $PROFILE nodes read | jq -r '.[].system_id')
553 vlanid=$(maas $PROFILE subnets read | jq '.[].vlan | select(.vid=='$1')'.id)
554 fabricid=`maas $PROFILE subnets read | jq '.[].vlan | select(.vid=='$1')'.fabric_id`
555 interface=`maas $PROFILE interfaces read $node | jq '.[] | select(.vlan.fabric_id=='$fabricid')'.id`
556 maas $PROFILE interfaces create-vlan $node vlan=$vlanid parent=$interface || true
560 #function for JUJU envronment
563 API_KEY=`sudo maas-region apikey --username=ubuntu`
564 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
565 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
567 echo "credentials:" > credential.yaml
568 echo " $controllername:" >> credential.yaml
569 echo " opnfv-credentials:" >> credential.yaml
570 echo " auth-type: oauth1" >> credential.yaml
571 echo " maas-oauth: $API_KEY" >> credential.yaml
573 juju add-credential $controllername -f credential.yaml --replace
577 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
578 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
580 echo "clouds:" > maas-cloud.yaml
581 echo " $cloudname:" >> maas-cloud.yaml
582 echo " type: maas" >> maas-cloud.yaml
583 echo " auth-types: [oauth1]" >> maas-cloud.yaml
584 echo " endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
586 juju add-cloud $cloudname maas-cloud.yaml --replace
596 crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
597 crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
598 crnodevlanint $vlan905 eth1 || true
599 crnodevlanint $vlan905 eth3 || true
600 enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
601 enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
602 enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
603 enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
608 # Enable MAAS nodes interfaces
610 API_KEY=`sudo maas-region apikey --username=ubuntu`
611 maas login $PROFILE $API_SERVERMAAS $API_KEY
613 if [ -e ./labconfig.json ]; then
614 # We will configure all node, so we need the qty, and loop on it
615 NODE_QTY=$(cat labconfig.json | jq --raw-output '.lab.racks[0].nodes[]'.name | wc -l)
616 NODE_QTY=$((NODE_QTY-1))
617 for NODE_ID in $(seq 0 $NODE_QTY); do
618 # Get the NAME/SYS_ID of this node
619 NODE_NAME=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].name")
620 NODE_SYS_ID=$(maas $PROFILE nodes read | jq -r ".[] | select(.hostname==\"$NODE_NAME\")".system_id)
621 echo ">>> Configuring node $NODE_NAME [$NODE_ID][$NODE_SYS_ID]"
622 # Recover the network interfaces list and configure each one
623 # with sorting the list, we have hardware interface first, than the vlan interfaces
624 IF_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] ".ifname )
625 for IF_NAME in $IF_LIST; do
626 # get the space of the interface
627 IF_SPACE=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NAME\") ".spaces[])
629 'data') SUBNET_CIDR=$SUBNETDATA_CIDR; IF_MODE='AUTO' ;;
630 'public') SUBNET_CIDR=$SUBNETPUB_CIDR; IF_MODE='AUTO' ;;
631 'storage') SUBNET_CIDR=$SUBNETSTOR_CIDR; IF_MODE='AUTO' ;;
632 'floating') SUBNET_CIDR=$SUBNETFLOAT_CIDR; IF_MODE='link_up' ;;
633 *) SUBNET_CIDR='null'; IF_MODE='null'; echo " >>> Unknown SPACE" ;;
635 echo " >>> Configuring interface $IF_NAME [$IF_SPACE][$SUBNET_CIDR]"
637 # if we have a vlan parameter in the space config
638 IF_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$IF_SPACE\")".vlan)
639 if ([ -z $IF_VLAN ] && [ $IF_NAME =~ \. ]); then
640 # We have no vlan specified on spaces, but we have a vlan subinterface
641 IF_VLAN = ${IF_NAME##*.}; fi
643 # in case of interface renaming
646 if ([ $IF_NEWNAME ] && [ "$IF_NEWNAME" != "null" ]); then
647 # rename interface if needed
648 IF_MACLOWER=$( cat labconfig.json | jq ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NEWNAME\")".mac[0])
649 IF_MAC=(${IF_MACLOWER,,})
650 IF_ID=$( maas ubuntu interfaces read $NODE_SYS_ID | jq ".[] | select(.mac_address==$IF_MAC)".id)
651 maas $PROFILE interface update $NODE_SYS_ID $IF_ID name=$IF_NEWNAME
655 # In case of a VLAN interface
656 if ([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
657 echo " >>> Configuring VLAN $IF_VLAN"
658 VLANID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".id)
659 FABRICID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".fabric_id)
660 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
661 if [[ -z $INTERFACE ]]; then
662 # parent interface is not set because it does not have a SUBNET_CIDR
663 PARENT_VLANID=$(maas $PROFILE fabrics read | jq ".[].vlans[] | select(.fabric_id==$FABRICID and .name==\"untagged\")".id)
664 # If we need to rename the interface, use new interface name
665 if ([ $IF_NEWNAME ] && [ "$IF_NEWNAME" != "null" ]); then
666 PARENT_IF_NAME=${IF_NEWNAME%%.*}
669 PARENT_IF_NAME=${IF_NAME%%.*}
671 # We set the physical interface to the targeted fabric
672 maas $PROFILE interface update $NODE_SYS_ID $PARENT_IF_NAME vlan=$PARENT_VLANID
674 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
676 maas $PROFILE interfaces create-vlan $NODE_SYS_ID vlan=$VLANID parent=$INTERFACE || true
678 # Configure the interface
679 if ([ $SUBNET_CIDR ] && [ "$SUBNET_CIDR" != "null" ]); then
680 VLANID=$(maas $PROFILE subnet read $SUBNET_CIDR | jq -r '.vlan.id')
681 if !([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
682 # If this interface is not a VLAN (done withe create-vlan)
683 maas $PROFILE interface update $NODE_SYS_ID $IF_NAME vlan=$VLANID
685 maas $PROFILE interface link-subnet $NODE_SYS_ID $IF_NAME mode=$IF_MODE subnet=$SUBNET_CIDR || true
688 echo " >>> Not configuring, we have an empty Subnet CIDR"
695 # Add the cloud and controller credentials for MAAS for that lab.
696 jujuver=`juju --version`
698 if [[ "$jujuver" > "2" ]]; then
706 echo " .... MAAS deployment finished successfully ...."