2 #placeholder for deployment script.
10 if [ ! -e $HOME/.ssh/id_rsa ]; then
11 ssh-keygen -N '' -f $HOME/.ssh/id_rsa
16 if [ "ppc64le" == "$NODE_ARCTYPE" ]; then
18 elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
24 NODE_ARC="$NODE_ARCHES/generic"
26 # Install the packages needed
27 echo_info "Installing and upgrading required packages"
28 sudo apt-get install software-properties-common -y
29 sudo apt-add-repository ppa:juju/stable -y
30 sudo apt-add-repository ppa:maas/stable -y
31 sudo apt-add-repository cloud-archive:ocata -y
32 sudo apt-get update -y
33 #sudo apt-get dist-upgrade -y
34 sudo apt-get install bridge-utils openssh-server bzr git virtinst qemu-kvm libvirt-bin \
35 maas maas-region-controller juju python-pip python-psutil python-openstackclient \
36 python-congressclient gsutil charm-tools pastebinit python-jinja2 sshpass \
37 openssh-server vlan ipmitool jq expect snap -y
39 #sudo apt-get install snap -y
40 #sudo snap install maas --classic
41 #sudo snap install juju --classic
43 sudo -H pip install --upgrade pip
45 #first parameter should be custom and second should be either
46 # absolute location of file (including file name) or url of the
54 # Get labconfig and generate deployconfig.yaml
55 echo_info "Parsing lab configuration file"
57 intelpod[569]|orangepod[12]|cengnpod[12] )
58 array=(${labname//pod/ })
59 cp ../labconfig/${array[0]}/pod${array[1]}/labconfig.yaml .
60 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
63 cp ../labconfig/att/virpod1/labconfig.yaml .
64 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
68 if [ -e $labfile ]; then
69 cp $labfile ./labconfig.yaml || true
71 wget $labconfigfile -t 3 -T 10 -O ./labconfig.yaml || true
72 count=`wc -l labconfig.yaml | cut -d " " -f 1`
73 if [ $count -lt 10 ]; then
77 if [ ! -e ./labconfig.yaml ]; then
80 cp ../labconfig/default/labconfig.yaml ./
81 cp ../labconfig/default/deployconfig.yaml ./
83 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
84 labname=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
90 cp ../labconfig/default/labconfig.yaml ./
91 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
95 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < labconfig.yaml > labconfig.json
96 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < deployconfig.yaml > deployconfig.json
98 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
99 MAAS_NAME=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
100 API_SERVER="http://$MAAS_IP:5240/MAAS/api/2.0"
101 API_SERVERMAAS="http://$MAAS_IP:5240/MAAS/"
103 MY_UPSTREAM_DNS=`grep "upstream_dns" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
104 SSH_KEY=`cat ~/.ssh/id_rsa.pub`
105 MAIN_ARCHIVE=`grep "main_archive" deployconfig.yaml | cut -d ':' -f 2-3 | sed -e 's/ //'`
106 URL=https://images.maas.io/ephemeral-v3/daily/
107 KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
110 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
111 VLAN_UNTTAGED="untagged"
113 # In the case of a virtual deployment get deployconfig.yaml
114 if [ "$virtinstall" -eq 1 ]; then
118 #create backup directory
119 mkdir ~/joid_config/ || true
121 # Backup deployconfig.yaml in joid_config folder
123 if [ -e ./deployconfig.yaml ]; then
124 cp ./deployconfig.yaml ~/joid_config/
125 cp ./labconfig.yaml ~/joid_config/
129 # Prepare local environment to avoid password asking
132 # make sure no password asked during the deployment.
133 sudoer_file=/etc/sudoers.d/90-joid-init
134 sudoer_entry="$USER ALL=(ALL) NOPASSWD:ALL"
135 if [ -e $sudoer_file ]; then
136 if ! sudo grep -q "$sudoer_entry" $sudoer_file; then
137 sudo sed -i -e "1i$sudoer_entry" $sudoer_file
140 echo "$sudoer_entry" > 90-joid-init
141 sudo chown root:root 90-joid-init
142 sudo mv 90-joid-init /etc/sudoers.d/
145 echo_info "Deployment of MAAS started"
151 # define the pool and try to start even though its already exist.
152 # For fresh install this may or may not there.
153 #some system i am seeing libvirt and some have libvirtd looks like libvirt-bin is
154 #keep switching so lets try both.
156 sudo adduser $USER libvirtd || true
157 sudo adduser $USER libvirt || true
158 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
159 sudo virsh pool-start default || true
160 sudo virsh pool-autostart default || true
162 # In case of virtual install set network
163 if [ "$virtinstall" -eq 1 ]; then
164 sudo virsh net-dumpxml default > default-net-org.xml
165 sed -i '/dhcp/d' default-net-org.xml
166 sed -i '/range/d' default-net-org.xml
167 sudo virsh net-destroy default
168 sudo virsh net-define default-net-org.xml
169 sudo virsh net-start default
170 rm -f default-net-org.xml
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 --format=columns | 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 if [ ! -e $HOME/id_rsa_maas.pub ]; then
186 [ -e $HOME/id_rsa_maas ] && rm -f $HOME/id_rsa_maas
187 sudo su - $USER -c "echo |ssh-keygen -t rsa -f $HOME/id_rsa_maas"
189 sudo -u maas mkdir ~maas/.ssh/ || true
190 sudo cp $HOME/id_rsa_maas ~maas/.ssh/id_rsa
191 sudo cp $HOME/id_rsa_maas.pub ~maas/.ssh/id_rsa.pub
192 sudo chown maas:maas ~maas/.ssh/id_rsa
193 sudo chown maas:maas ~maas/.ssh/id_rsa.pub
196 # Ensure virsh can connect without ssh auth
197 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
198 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
205 sudo apt-get install maas maas-region-controller -y
210 # https://insights.ubuntu.com/2016/01/23/maas-setup-deploying-openstack-on-maas-1-9-with-juju/
211 # http://blog.naydenov.net/2016/01/nodes-networking-deploying-openstack-on-maas-1-9-with-juju/
214 #reconfigure maas with correct MAAS address.
215 #Below code is needed as MAAS have issue in commissioning without restart.
216 #sudo ./maas-reconfigure-region.sh $MAAS_IP
218 sudo maas-rack config --region-url http://$MAAS_IP:5240/MAAS
220 sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com --password=ubuntu || true
221 API_KEY=`sudo maas-region apikey --username=ubuntu`
222 maas login $PROFILE $API_SERVERMAAS $API_KEY
223 maas $PROFILE maas set-config name='main_archive' value=$MAIN_ARCHIVE || true
224 maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS || true
225 maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME || true
226 maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com' || true
227 maas $PROFILE sshkeys create "key=$SSH_KEY" || true
229 for tag in bootstrap compute control storage
231 maas $PROFILE tags create name=$tag || true
234 #create the required spaces.
235 maas $PROFILE space update 0 name=default || true
236 for space in unused admin-api internal-api public-api \
237 storage-access storage-cluster admin \
238 tenant-data tenant-api tenant-public oam-space
240 echo_info "Creating the space $space"
241 maas $PROFILE spaces create name=$space || true
244 maas $PROFILE boot-source update $SOURCE_ID \
245 url=$URL keyring_filename=$KEYRING_FILE || true
247 if [ $NODE_ARCTYPE != "x86_64" ] ; then
248 maas $PROFILE boot-source-selection update 1 1 arches="$NODE_ARCHES"
251 maas $PROFILE boot-resources import || true
253 while [ "$(maas $PROFILE boot-resources is-importing)" == "true" ];
261 #get space, subnet and vlan and create accordingly.
262 #for type in pxe admin data storage external floating public; do
263 nettypes=`cat labconfig.json | jq '.opnfv.spaces[]'.type | cut -d \" -f 2`
264 for type in $nettypes; do
266 SPACE_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.cidr | cut -d \" -f 2 `
267 SPACE_VLAN=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.vlan | cut -d \" -f 2 `
268 SPACE_GWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.gateway | cut -d \" -f 2 `
269 NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
270 if ([ $NET_FABRIC_NAME ] && [ $NET_FABRIC_NAME != "null" ]); then
271 NET_FABRIC_VID=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.vid)
272 NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
273 if ([ $SPACE_VLAN == "null" ]); then
276 NET_VLAN_ID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".id)
277 NET_VLAN_VID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".vid)
278 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
279 maas $PROFILE subnet update $SPACE_CIDR gateway_ip=$SPACE_GWAY
281 if ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == "0" ]); then
283 elif ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == $SPACE_VLAN ]); then
286 NET_VLAN_ID=$(maas $PROFILE vlans create $NET_FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
287 if ([ $NET_VLAN_ID ] && [ $NET_VLAN_ID != "null" ]); then
288 maas $PROFILE subnet update $SPACE_CIDR vlan=$NET_VLAN_ID
289 NET_FABRIC_VID=$SPACE_VLAN
293 if ([ $SPACE_CIDR ] && [ "$SPACE_CIDR" != "null" ]); then
294 FABRIC_ID=$(maas $PROFILE fabrics create name=opnfv$type | jq --raw-output ".id")
295 NET_FABRIC_ID=$FABRIC_ID
296 NET_FABRIC_VID=$SPACE_VLAN
297 if ([ $SPACE_VLAN ] && [ "$SPACE_VLAN" != "null" ]); then
298 NET_VLAN_ID=$(maas $PROFILE vlans create $FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
299 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
300 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID gateway_ip=$SPACE_GWAY
302 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID
304 NET_FABRIC_VID=$VLAN_ID
306 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
307 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0" gateway_ip=$SPACE_GWAY
309 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0"
312 NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
316 'pxe') JUJU_SPACE="oam-space"; DHCP='enabled' ;;
317 'admin') JUJU_SPACE="internal-api"; DHCP='enabled' ;;
318 'data') JUJU_SPACE="tenant-data"; DHCP='' ;;
319 'public') JUJU_SPACE="public-api"; DHCP='' ;;
320 'storage') JUJU_SPACE="storage-cluster"; DHCP='' ;;
321 'storageaccess') JUJU_SPACE="storage-data"; DHCP='' ;;
322 'floating') JUJU_SPACE="tenant-public"; DHCP='' ;;
323 *) JUJU_SPACE='default'; DHCP='OFF'; echo_info " >>> Unknown SPACE" ;;
325 JUJU_SPACE_ID=$(maas $PROFILE spaces read | jq -r ".[] | select(.name==\"$JUJU_SPACE\")".id)
326 JUJU_VLAN_VID=$(maas $PROFILE subnets read | jq -r ".[] | select(.name==\"$SPACE_CIDR\")".vlan.vid)
327 NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
328 if ([ $NET_FABRIC_ID ] && [ $NET_FABRIC_ID != "null" ]); then
329 if ([ $JUJU_VLAN_VID ] && [ $JUJU_VLAN_VID != "null" ]); then
330 maas $PROFILE vlan update $NET_FABRIC_ID $JUJU_VLAN_VID space=$JUJU_SPACE_ID
333 if ([ $type == "admin" ] || [ $type == "pxe" ]); then
334 # If we have a network, we create it
335 if ([ $NET_FABRIC_ID ]); then
337 SUBNET_PREFIX=${SPACE_CIDR::-5}
338 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
339 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
340 IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
341 IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
342 maas $PROFILE ipranges create type=reserved \
343 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
344 comment='This is a reserved range' || true
345 maas $PROFILE ipranges create type=dynamic \
346 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
347 comment='This is a reserved dynamic range' || true
349 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
350 maas $PROFILE vlan update $NET_FABRIC_ID $NET_FABRIC_VID dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
357 API_KEY=`sudo maas-region apikey --username=ubuntu`
358 maas login $PROFILE $API_SERVERMAAS $API_KEY
360 # make sure there is no machine entry in maas
361 for m in $(maas $PROFILE machines read | jq -r '.[].system_id')
363 maas $PROFILE machine delete $m
366 # if we have a virshurl configuration we use it, else we use local
367 VIRSHURL=$(cat labconfig.json | jq -r '.opnfv.virshurl')
368 if ([ $VIRSHURL == "" ] || [ "$VIRSHURL" == "null" ]); then
370 VIRSHURL="qemu+ssh://$USER@$VIRSHIP/system "
373 VIRSHHOST=$(echo $VIRSHURL| cut -d\/ -f 3 | cut -d@ -f2)
374 VIRSHIP="" # TODO: parse from $VIRSHURL if needed
377 if [ "$virtinstall" -eq 1 ]; then
378 netw=" --network bridge=virbr0,model=virtio"
379 elif ([ $VIRSHHOST != "" ]); then
380 # Get the bridge hosting the remote virsh
381 brid=$(ssh $VIRSHHOST "ip a l | grep $VIRSHHOST | perl -pe 's/.* (.*)\$/\$1/g'")
382 netw=" --network bridge=$brid,model=virtio"
383 # prepare a file containing virsh remote url to connect without adding it n command line
384 echo "export VIRSH_DEFAULT_CONNECT_URI=$VIRSHURL" > virsh_uri.sh
388 brid=`brctl show | grep 8000 | cut -d "8" -f 1 | tr "\n" " " | tr " " " " | tr -s " "`
389 ADMIN_BR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.bridge | cut -d \" -f 2 `
390 PXE_BR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.bridge | cut -d \" -f 2 `
392 for feature in $brid; do
393 if ([ "$feature" == "$ADMIN_BR" ] || [ "$feature" == "$PXE_BR" ]); then
394 netw=$netw" --network bridge="$feature",model=virtio"
401 # Add server fingerprint to known hosts to prevent security prompt in the
402 # SSH connection during the virt-install
403 if [ $VIRSHIP != "" ]; then
404 # Check if the IP is not already present among the known hosts
405 if ! ssh-keygen -F $VIRSHIP > /dev/null ; then
406 echo_info "SSH fingerprint of the host is not known yet, adding to known_hosts"
407 ssh-keyscan -H $VIRSHIP >> ~/.ssh/known_hosts
411 echo_info "Creating and adding bootstrap node"
413 virt-install --connect $VIRSHURL --name bootstrap --ram 4098 --cpu host --vcpus 2 \
414 --disk size=20,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
415 $netw --boot network,hd,menu=off --noautoconsole \
416 --print-xml | tee bootstrap
418 if [ "$virtinstall" -eq 1 ]; then
419 bootstrapmac=`grep "mac address" bootstrap | head -1 | cut -d '"' -f 2`
422 bootstrapmacs=`grep "mac address" bootstrap| cut -d '"' -f 2`
423 for mac in $bootstrapmacs; do
424 bootstrapmac=$bootstrapmac" mac_addresses="$mac
427 virsh -c $VIRSHURL define --file bootstrap
432 maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
433 tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
434 power_parameters_power_address="$VIRSHURL" \
435 architecture=$NODE_ARC power_parameters_power_id='bootstrap'
437 bootstrapid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == "bootstrap").system_id')
439 maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
441 if [ "$virtinstall" -eq 1 ]; then
442 units=`cat deployconfig.json | jq .opnfv.units`
444 until [ $(($units)) -lt 1 ]; do
445 units=$(($units - 1));
446 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
448 virt-install --connect $VIRSHURL --name $NODE_NAME --ram 8192 --cpu host --vcpus 4 \
449 --disk size=120,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
450 $netw $netw --boot network,hd,menu=off --noautoconsole --print-xml | tee $NODE_NAME
452 nodemac=`grep "mac address" $NODE_NAME | head -1 | cut -d '"' -f 2`
453 virsh -c $VIRSHURL define --file $NODE_NAME
455 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
456 tags='control compute' hostname=$NODE_NAME power_type='virsh' mac_addresses=$nodemac \
457 power_parameters_power_address="$VIRSHURL" \
458 architecture=$NODE_ARC power_parameters_power_id=$NODE_NAME
459 nodeid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == '\"$NODE_NAME\"').system_id')
460 maas $PROFILE tag update-nodes control add=$nodeid || true
461 maas $PROFILE tag update-nodes compute add=$nodeid || true
464 units=`cat deployconfig.json | jq .opnfv.units`
466 until [ $(($units)) -lt 1 ]; do
467 units=$(($units - 1));
468 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
469 MAC_ADDRESS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"admin\").mac"[0] | cut -d \" -f 2 `
470 MAC_ADDRESS_PXE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"pxe\").mac"[0] | cut -d \" -f 2 `
471 #MAC_ADDRESS1=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"floating\").mac"[0] | cut -d \" -f 2 `
472 POWER_TYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.type" | cut -d \" -f 2 `
473 POWER_IP=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.address" | cut -d \" -f 2 `
474 POWER_USER=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.user" | cut -d \" -f 2 `
475 POWER_PASS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.pass" | cut -d \" -f 2 `
476 NODE_ARCTYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].architecture" | cut -d \" -f 2 `
478 if [ "ppc64le" == "$NODE_ARCTYPE" ]; then
479 NODE_ARCHES="ppc64el"
480 elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
486 NODE_ARC="$NODE_ARCHES/generic"
488 echo_info "Creating node $NODE_NAME"
489 if ([ $MAC_ADDRESS_PXE ] && ["$MAC_ADDRESS_PXE" != "null" ]); then
490 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
491 hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
492 power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS \
493 mac_addresses=$MAC_ADDRESS_PXE architecture=$NODE_ARC
495 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
496 hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
497 power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS \
498 mac_addresses=$MAC_ADDRESS architecture=$NODE_ARC
503 maas $PROFILE pods create type=virsh power_address="$VIRSHURL" power_user=$USER
505 # Make sure nodes are added into MAAS and none of them is in commissioning state
507 while [ "$(maas $PROFILE nodes read | grep Commissioning )" ];
509 echo_info "Waiting for nodes to finish commissioning. ${i} minutes elapsed."
513 # Make sure that no nodes have failed commissioning or testing
514 if [ "$(maas $PROFILE nodes read | grep 'Failed' )" ];
516 echo "Error: Some nodes have failed commissioning or testing" 1>&2
524 # configure MAAS with the different options.
528 # functioncall with subnetid to add and second parameter is dhcp enable
529 # third parameter will define the space. It is required to have admin
533 #just make sure rack controller has been synced and import only
534 # just whether images have been imported or not.
535 sudo ./maas-reconfigure-region.sh $MAAS_IP
538 # Let's add the nodes now. Currently works only for virtual deployment.
541 echo_info "Initial deployment of MAAS finished"
543 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
544 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
545 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
548 API_KEY=`sudo maas-region apikey --username=ubuntu`
549 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
550 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
552 echo "credentials:" > credential.yaml
553 echo " $controllername:" >> credential.yaml
554 echo " opnfv-credentials:" >> credential.yaml
555 echo " auth-type: oauth1" >> credential.yaml
556 echo " maas-oauth: $API_KEY" >> credential.yaml
558 juju add-credential $controllername -f credential.yaml --replace
562 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
563 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
565 echo "clouds:" > maas-cloud.yaml
566 echo " $cloudname:" >> maas-cloud.yaml
567 echo " type: maas" >> maas-cloud.yaml
568 echo " auth-types: [oauth1]" >> maas-cloud.yaml
569 echo " endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
571 echo_info "Adding cloud $cloudname"
572 juju add-cloud $cloudname maas-cloud.yaml --replace
576 # Enable MAAS nodes interfaces
578 API_KEY=`sudo maas-region apikey --username=ubuntu`
579 maas login $PROFILE $API_SERVERMAAS $API_KEY
581 if [ -e ./labconfig.json ]; then
582 # We will configure all node, so we need the qty, and loop on it
583 NODE_QTY=$(cat labconfig.json | jq --raw-output '.lab.racks[0].nodes[]'.name | wc -l)
584 NODE_QTY=$((NODE_QTY-1))
585 for NODE_ID in $(seq 0 $NODE_QTY); do
586 # Get the NAME/SYS_ID of this node
587 NODE_NAME=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].name")
588 NODE_SYS_ID=$(maas $PROFILE nodes read | jq -r ".[] | select(.hostname==\"$NODE_NAME\")".system_id)
589 echo_info ">>> Configuring node $NODE_NAME [$NODE_ID][$NODE_SYS_ID]"
590 # Recover the network interfaces list and configure each one
591 # with sorting the list, we have hardware interface first, than the vlan interfaces
592 IF_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] ".ifname | sort -u )
593 for IF_NAME in $IF_LIST; do
594 # get the space of the interface
595 IF_SPACE=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NAME\") ".spaces[])
596 SUBNET_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$IF_SPACE'")'.cidr | cut -d \" -f 2 `
598 'data') IF_MODE='AUTO' ;;
599 'public') IF_MODE='AUTO' ;;
600 'storage') IF_MODE='AUTO' ;;
601 'floating') IF_MODE='link_up' ;;
602 *) SUBNET_CIDR='null'; IF_MODE='null'; echo_info " >>> Unknown SPACE" ;;
604 echo_info " >>> Configuring interface $IF_NAME [$IF_SPACE][$SUBNET_CIDR]"
606 # if we have a vlan parameter in the space config
607 IF_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$IF_SPACE\")".vlan)
608 if ([ -z $IF_VLAN ] && [ $IF_NAME =~ \. ]); then
609 # We have no vlan specified on spaces, but we have a vlan subinterface
610 IF_VLAN = ${IF_NAME##*.}; fi
612 # in case of interface renaming
615 # In case of a VLAN interface
616 if ([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
617 echo_info " >>> Configuring VLAN $IF_VLAN"
618 VLANID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".id)
619 FABRICID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".fabric_id)
620 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
621 if [[ -z $INTERFACE ]]; then
622 # parent interface is not set because it does not have a SUBNET_CIDR
623 PARENT_VLANID=$(maas $PROFILE fabrics read | jq ".[].vlans[] | select(.fabric_id==$FABRICID and .name==\"untagged\")".id)
624 # If we need to rename the interface, use new interface name
625 if ([ $IF_NEWNAME ] && [ "$IF_NEWNAME" != "null" ]); then
626 PARENT_IF_NAME=${IF_NEWNAME%%.*}
629 PARENT_IF_NAME=${IF_NAME%%.*}
631 # We set the physical interface to the targeted fabric
632 maas $PROFILE interface update $NODE_SYS_ID $PARENT_IF_NAME vlan=$PARENT_VLANID
634 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
636 maas $PROFILE interfaces create-vlan $NODE_SYS_ID vlan=$VLANID parent=$INTERFACE || true
638 # rename interface if needed
639 IF_MACLOWER=$( cat labconfig.json | jq ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NEWNAME\")".mac[0])
640 IF_MAC=(${IF_MACLOWER,,})
641 IF_ID=$( maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.mac_address==$IF_MAC)".id)
642 if ([ $IF_ID ] && [ "$IF_ID" != "null" ]); then
643 maas $PROFILE interface update $NODE_SYS_ID $IF_ID name=$IF_NEWNAME
646 # Configure the interface
647 if ([ $SUBNET_CIDR ] && [ "$SUBNET_CIDR" != "null" ]); then
648 VLANID=$(maas $PROFILE subnet read $SUBNET_CIDR | jq -r '.vlan.id')
649 if !([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
650 # If this interface is not a VLAN (done withe create-vlan)
651 maas $PROFILE interface update $NODE_SYS_ID $IF_NAME vlan=$VLANID || true
653 maas $PROFILE interface link-subnet $NODE_SYS_ID $IF_NAME mode=$IF_MODE subnet=$SUBNET_CIDR || true
656 echo_info " >>> Not configuring, we have an empty Subnet CIDR"
663 # Add the cloud and controller credentials for MAAS for that lab.
664 jujuver=`juju --version`
666 if [[ "$jujuver" > "2" ]]; then
674 echo_info "MAAS deployment finished successfully"