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
48 { set +x; } 2> /dev/null
50 echo "OPNFV JOID deployer of the MAAS (Metal as a Service) infrastructure."
51 echo "Usage: $0 custom <path_to_labconfig>"
56 if [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]
66 # Get labconfig and generate deployconfig.yaml
70 # Deployment with a custom labconfig file
72 if [ -z "$labfile" ]; then
73 if [ ! -e ./labconfig.yaml ]; then
74 # no labconfig file was specified and no ci/labconfig.yaml is present
75 echo_error "Labconfig file must be specified when using custom"
78 # no labconfig file was specified and but a (backup) ci/labconfig.yaml found
79 echo_warning "Labconfig was not specified, using ./labconfig.yaml instead"
80 # no action needed, ./labconfig.yaml already present
82 elif [ ! -e "$labfile" ]; then
83 # labconfig file was specified but does not exist on disk
84 echo_warning "Labconfig not found locally, trying download"
86 wget $labfile -t 3 -T 10 -O ./labconfig.yaml || true
87 count=`wc -l labconfig.yaml | cut -d " " -f 1`
88 if [ $count -lt 10 ]; then
89 echo_error "Unable to download labconfig"
93 echo_info "Using $labfile to setup deployment"
94 cp $labfile ./labconfig.yaml
97 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
98 labname=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
101 # Virtual deployment using a default labconfig file
102 echo_info "Using default labconfig for virtual install"
103 cp ../labconfig/default/labconfig.yaml ./
104 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
110 echo_error "Unknown script argument: $labname"
115 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < labconfig.yaml > labconfig.json
116 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < deployconfig.yaml > deployconfig.json
118 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
119 MAAS_NAME=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
120 API_SERVER="http://$MAAS_IP:5240/MAAS/api/2.0"
121 API_SERVERMAAS="http://$MAAS_IP:5240/MAAS/"
123 MY_UPSTREAM_DNS=`grep "upstream_dns" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
124 SSH_KEY=`cat ~/.ssh/id_rsa.pub`
125 MAIN_ARCHIVE=`grep "main_archive" deployconfig.yaml | cut -d ':' -f 2-3 | sed -e 's/ //'`
126 URL=https://images.maas.io/ephemeral-v3/daily/
127 KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
130 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
131 VLAN_UNTTAGED="untagged"
133 # In the case of a virtual deployment get deployconfig.yaml
134 if [ "$virtinstall" -eq 1 ]; then
138 #create backup directory
139 mkdir ~/joid_config/ || true
141 # Backup deployconfig.yaml in joid_config folder
143 if [ -e ./deployconfig.yaml ]; then
144 cp ./deployconfig.yaml ~/joid_config/
145 cp ./labconfig.yaml ~/joid_config/
149 # Prepare local environment to avoid password asking
152 # make sure no password asked during the deployment.
153 sudoer_file=/etc/sudoers.d/90-joid-init
154 sudoer_entry="$USER ALL=(ALL) NOPASSWD:ALL"
155 if [ -e $sudoer_file ]; then
156 if ! sudo grep -q "$sudoer_entry" $sudoer_file; then
157 sudo sed -i -e "1i$sudoer_entry" $sudoer_file
160 echo "$sudoer_entry" > 90-joid-init
161 sudo chown root:root 90-joid-init
162 sudo mv 90-joid-init /etc/sudoers.d/
165 echo_info "Deployment of MAAS started"
171 # define the pool and try to start even though its already exist.
172 # For fresh install this may or may not there.
173 #some system i am seeing libvirt and some have libvirtd looks like libvirt-bin is
174 #keep switching so lets try both.
176 sudo adduser $USER libvirtd || true
177 sudo adduser $USER libvirt || true
178 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
179 sudo virsh pool-start default || true
180 sudo virsh pool-autostart default || true
182 # In case of virtual install set network
183 if [ "$virtinstall" -eq 1 ]; then
184 sudo virsh net-dumpxml default > default-net-org.xml
185 sed -i '/dhcp/d' default-net-org.xml
186 sed -i '/range/d' default-net-org.xml
187 sudo virsh net-destroy default
188 sudo virsh net-define default-net-org.xml
189 sudo virsh net-start default
190 rm -f default-net-org.xml
194 # Cleanup, juju init and config backup
197 # To avoid problem between apiclient/maas_client and apiclient from google
198 # we remove the package google-api-python-client from yardstick installer
199 if [ $(pip list --format=columns | grep google-api-python-client | wc -l) == 1 ]; then
200 sudo pip uninstall google-api-python-client
204 if [ ! -e ~maas/.ssh/id_rsa.pub ]; then
205 if [ ! -e $HOME/id_rsa_maas.pub ]; then
206 [ -e $HOME/id_rsa_maas ] && rm -f $HOME/id_rsa_maas
207 sudo su - $USER -c "echo |ssh-keygen -t rsa -f $HOME/id_rsa_maas"
209 sudo -u maas mkdir ~maas/.ssh/ || true
210 sudo cp $HOME/id_rsa_maas ~maas/.ssh/id_rsa
211 sudo cp $HOME/id_rsa_maas.pub ~maas/.ssh/id_rsa.pub
212 sudo chown maas:maas ~maas/.ssh/id_rsa
213 sudo chown maas:maas ~maas/.ssh/id_rsa.pub
216 # Ensure virsh can connect without ssh auth
217 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
218 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
225 sudo apt-get install maas maas-region-controller -y
230 # https://insights.ubuntu.com/2016/01/23/maas-setup-deploying-openstack-on-maas-1-9-with-juju/
231 # http://blog.naydenov.net/2016/01/nodes-networking-deploying-openstack-on-maas-1-9-with-juju/
234 #reconfigure maas with correct MAAS address.
235 #Below code is needed as MAAS have issue in commissioning without restart.
236 #sudo ./maas-reconfigure-region.sh $MAAS_IP
238 sudo maas-rack config --region-url http://$MAAS_IP:5240/MAAS
240 sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com --password=ubuntu || true
241 API_KEY=`sudo maas-region apikey --username=ubuntu`
242 maas login $PROFILE $API_SERVERMAAS $API_KEY
243 maas $PROFILE maas set-config name='main_archive' value=$MAIN_ARCHIVE || true
244 maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS || true
245 maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME || true
246 maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com' || true
247 maas $PROFILE sshkeys create "key=$SSH_KEY" || true
249 for tag in bootstrap compute control storage
251 maas $PROFILE tags create name=$tag || true
254 #create the required spaces.
255 maas $PROFILE space update 0 name=default || true
256 for space in unused admin-api internal-api public-api \
257 storage-access storage-cluster admin \
258 tenant-data tenant-api tenant-public oam-space
260 echo_info "Creating the space $space"
261 maas $PROFILE spaces create name=$space || true
264 maas $PROFILE boot-source update $SOURCE_ID \
265 url=$URL keyring_filename=$KEYRING_FILE || true
267 if [ $NODE_ARCTYPE != "x86_64" ] ; then
268 maas $PROFILE boot-source-selection update 1 1 arches="$NODE_ARCHES"
271 maas $PROFILE boot-resources import || true
273 while [ "$(maas $PROFILE boot-resources is-importing)" == "true" ];
281 #get space, subnet and vlan and create accordingly.
282 #for type in pxe admin data storage external floating public; do
283 nettypes=`cat labconfig.json | jq '.opnfv.spaces[]'.type | cut -d \" -f 2`
284 for type in $nettypes; do
286 SPACE_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.cidr | cut -d \" -f 2 `
287 SPACE_VLAN=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.vlan | cut -d \" -f 2 `
288 SPACE_GWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.gateway | cut -d \" -f 2 `
289 NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
290 if ([ $NET_FABRIC_NAME ] && [ $NET_FABRIC_NAME != "null" ]); then
291 NET_FABRIC_VID=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.vid)
292 NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
293 if ([ $SPACE_VLAN == "null" ]); then
296 NET_VLAN_ID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".id)
297 NET_VLAN_VID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".vid)
298 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
299 maas $PROFILE subnet update $SPACE_CIDR gateway_ip=$SPACE_GWAY
301 if ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == "0" ]); then
303 elif ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == $SPACE_VLAN ]); then
306 NET_VLAN_ID=$(maas $PROFILE vlans create $NET_FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
307 if ([ $NET_VLAN_ID ] && [ $NET_VLAN_ID != "null" ]); then
308 maas $PROFILE subnet update $SPACE_CIDR vlan=$NET_VLAN_ID
309 NET_FABRIC_VID=$SPACE_VLAN
313 if ([ $SPACE_CIDR ] && [ "$SPACE_CIDR" != "null" ]); then
314 FABRIC_ID=$(maas $PROFILE fabrics create name=opnfv$type | jq --raw-output ".id")
315 NET_FABRIC_ID=$FABRIC_ID
316 NET_FABRIC_VID=$SPACE_VLAN
317 if ([ $SPACE_VLAN ] && [ "$SPACE_VLAN" != "null" ]); then
318 NET_VLAN_ID=$(maas $PROFILE vlans create $FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
319 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
320 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID gateway_ip=$SPACE_GWAY
322 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID
324 NET_FABRIC_VID=$VLAN_ID
326 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
327 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0" gateway_ip=$SPACE_GWAY
329 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0"
332 NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
336 'pxe') JUJU_SPACE="oam-space"; DHCP='enabled' ;;
337 'admin') JUJU_SPACE="internal-api"; DHCP='enabled' ;;
338 'data') JUJU_SPACE="tenant-data"; DHCP='' ;;
339 'public') JUJU_SPACE="public-api"; DHCP='' ;;
340 'storage') JUJU_SPACE="storage-cluster"; DHCP='' ;;
341 'storageaccess') JUJU_SPACE="storage-data"; DHCP='' ;;
342 'floating') JUJU_SPACE="tenant-public"; DHCP='' ;;
343 *) JUJU_SPACE='default'; DHCP='OFF'; echo_info " >>> Unknown SPACE" ;;
345 JUJU_SPACE_ID=$(maas $PROFILE spaces read | jq -r ".[] | select(.name==\"$JUJU_SPACE\")".id)
346 JUJU_VLAN_VID=$(maas $PROFILE subnets read | jq -r ".[] | select(.name==\"$SPACE_CIDR\")".vlan.vid)
347 NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
348 if ([ $NET_FABRIC_ID ] && [ $NET_FABRIC_ID != "null" ]); then
349 if ([ $JUJU_VLAN_VID ] && [ $JUJU_VLAN_VID != "null" ]); then
350 maas $PROFILE vlan update $NET_FABRIC_ID $JUJU_VLAN_VID space=$JUJU_SPACE_ID
353 if ([ $type == "admin" ] || [ $type == "pxe" ]); then
354 # If we have a network, we create it
355 if ([ $NET_FABRIC_ID ]); then
357 SUBNET_PREFIX=${SPACE_CIDR::-5}
358 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
359 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
360 IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
361 IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
362 maas $PROFILE ipranges create type=reserved \
363 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
364 comment='This is a reserved range' || true
365 maas $PROFILE ipranges create type=dynamic \
366 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
367 comment='This is a reserved dynamic range' || true
369 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
370 maas $PROFILE vlan update $NET_FABRIC_ID $NET_FABRIC_VID dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
377 API_KEY=`sudo maas-region apikey --username=ubuntu`
378 maas login $PROFILE $API_SERVERMAAS $API_KEY
380 # make sure there is no machine entry in maas
381 for m in $(maas $PROFILE machines read | jq -r '.[].system_id')
383 maas $PROFILE machine delete $m
386 # if we have a virshurl configuration we use it, else we use local
387 VIRSHURL=$(cat labconfig.json | jq -r '.opnfv.virshurl')
388 if ([ $VIRSHURL == "" ] || [ "$VIRSHURL" == "null" ]); then
390 VIRSHURL="qemu+ssh://$USER@$VIRSHIP/system "
393 VIRSHHOST=$(echo $VIRSHURL| cut -d\/ -f 3 | cut -d@ -f2)
394 VIRSHIP="" # TODO: parse from $VIRSHURL if needed
397 if [ "$virtinstall" -eq 1 ]; then
398 netw=" --network bridge=virbr0,model=virtio"
399 elif ([ "$VIRSHHOST" != "" ]); then
400 # Get the bridge hosting the remote virsh
401 brid=$(ssh $VIRSHHOST "ip a l | grep $VIRSHHOST | perl -pe 's/.* (.*)\$/\$1/g'")
402 netw=" --network bridge=$brid,model=virtio"
403 # prepare a file containing virsh remote url to connect without adding it n command line
404 echo "export VIRSH_DEFAULT_CONNECT_URI=$VIRSHURL" > virsh_uri.sh
408 brid=`brctl show | grep 8000 | cut -d "8" -f 1 | tr "\n" " " | tr " " " " | tr -s " "`
409 ADMIN_BR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.bridge | cut -d \" -f 2 `
410 PXE_BR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.bridge | cut -d \" -f 2 `
412 for feature in $brid; do
413 if ([ "$feature" == "$ADMIN_BR" ] || [ "$feature" == "$PXE_BR" ]); then
414 netw=$netw" --network bridge="$feature",model=virtio"
421 # Add server fingerprint to known hosts to prevent security prompt in the
422 # SSH connection during the virt-install
423 if [ $VIRSHIP != "" ]; then
424 # Check if the IP is not already present among the known hosts
425 if ! ssh-keygen -F $VIRSHIP > /dev/null ; then
426 echo_info "SSH fingerprint of the host is not known yet, adding to known_hosts"
427 ssh-keyscan -H $VIRSHIP >> ~/.ssh/known_hosts
431 echo_info "Creating and adding bootstrap node"
433 virt-install --connect $VIRSHURL --name bootstrap --ram 4098 --cpu host --vcpus 2 \
434 --disk size=20,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
435 $netw --boot network,hd,menu=off --noautoconsole \
436 --print-xml | tee bootstrap
438 if [ "$virtinstall" -eq 1 ]; then
439 bootstrapmac=`grep "mac address" bootstrap | head -1 | cut -d '"' -f 2`
442 bootstrapmacs=`grep "mac address" bootstrap| cut -d '"' -f 2`
443 for mac in $bootstrapmacs; do
444 bootstrapmac=$bootstrapmac" mac_addresses="$mac
447 virsh -c $VIRSHURL define --file bootstrap
452 maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
453 tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
454 power_parameters_power_address="$VIRSHURL" \
455 architecture=$NODE_ARC power_parameters_power_id='bootstrap'
457 bootstrapid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == "bootstrap").system_id')
459 maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
461 if [ "$virtinstall" -eq 1 ]; then
462 units=`cat deployconfig.json | jq .opnfv.units`
464 until [ $(($units)) -lt 1 ]; do
465 units=$(($units - 1));
466 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
468 virt-install --connect $VIRSHURL --name $NODE_NAME --ram 8192 --cpu host --vcpus 4 \
469 --disk size=120,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
470 $netw $netw --boot network,hd,menu=off --noautoconsole --print-xml | tee $NODE_NAME
472 nodemac=`grep "mac address" $NODE_NAME | head -1 | cut -d '"' -f 2`
473 virsh -c $VIRSHURL define --file $NODE_NAME
475 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
476 tags='control compute' hostname=$NODE_NAME power_type='virsh' mac_addresses=$nodemac \
477 power_parameters_power_address="$VIRSHURL" \
478 architecture=$NODE_ARC power_parameters_power_id=$NODE_NAME
479 nodeid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == '\"$NODE_NAME\"').system_id')
480 maas $PROFILE tag update-nodes control add=$nodeid || true
481 maas $PROFILE tag update-nodes compute add=$nodeid || true
484 units=`cat deployconfig.json | jq .opnfv.units`
486 until [ $(($units)) -lt 1 ]; do
487 units=$(($units - 1));
488 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
489 MAC_ADDRESS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"admin\").mac"[0] | cut -d \" -f 2 `
490 MAC_ADDRESS_PXE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"pxe\").mac"[0] | cut -d \" -f 2 `
491 #MAC_ADDRESS1=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"floating\").mac"[0] | cut -d \" -f 2 `
492 POWER_TYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.type" | cut -d \" -f 2 `
493 POWER_IP=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.address" | cut -d \" -f 2 `
494 POWER_USER=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.user" | cut -d \" -f 2 `
495 POWER_PASS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.pass" | cut -d \" -f 2 `
496 NODE_ARCTYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].architecture" | cut -d \" -f 2 `
498 if [ "ppc64le" == "$NODE_ARCTYPE" ]; then
499 NODE_ARCHES="ppc64el"
500 elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
506 NODE_ARC="$NODE_ARCHES/generic"
508 echo_info "Creating node $NODE_NAME"
509 if ([ $MAC_ADDRESS_PXE ] && ["$MAC_ADDRESS_PXE" != "null" ]); then
510 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
511 hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
512 power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS \
513 mac_addresses=$MAC_ADDRESS_PXE architecture=$NODE_ARC
515 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
516 hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
517 power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS \
518 mac_addresses=$MAC_ADDRESS architecture=$NODE_ARC
523 maas $PROFILE pods create type=virsh power_address="$VIRSHURL" power_user=$USER
525 # Make sure nodes are added into MAAS and none of them is in commissioning state
527 while [ "$(maas $PROFILE nodes read | grep Commissioning )" ];
529 echo_info "Waiting for nodes to finish commissioning. ${i} minutes elapsed."
533 # Make sure that no nodes have failed commissioning or testing
534 if [ "$(maas $PROFILE nodes read | grep 'Failed' )" ];
536 echo "Error: Some nodes have failed commissioning or testing" 1>&2
544 # configure MAAS with the different options.
548 # functioncall with subnetid to add and second parameter is dhcp enable
549 # third parameter will define the space. It is required to have admin
553 #just make sure rack controller has been synced and import only
554 # just whether images have been imported or not.
555 sudo ./maas-reconfigure-region.sh $MAAS_IP
558 # Let's add the nodes now. Currently works only for virtual deployment.
561 echo_info "Initial deployment of MAAS finished"
563 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
564 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
565 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
568 API_KEY=`sudo maas-region apikey --username=ubuntu`
569 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
570 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
572 echo "credentials:" > credential.yaml
573 echo " $controllername:" >> credential.yaml
574 echo " opnfv-credentials:" >> credential.yaml
575 echo " auth-type: oauth1" >> credential.yaml
576 echo " maas-oauth: $API_KEY" >> credential.yaml
578 juju add-credential $controllername -f credential.yaml --replace
582 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
583 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
585 echo "clouds:" > maas-cloud.yaml
586 echo " $cloudname:" >> maas-cloud.yaml
587 echo " type: maas" >> maas-cloud.yaml
588 echo " auth-types: [oauth1]" >> maas-cloud.yaml
589 echo " endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
591 echo_info "Adding cloud $cloudname"
592 juju add-cloud $cloudname maas-cloud.yaml --replace
596 # Enable MAAS nodes interfaces
598 API_KEY=`sudo maas-region apikey --username=ubuntu`
599 maas login $PROFILE $API_SERVERMAAS $API_KEY
601 if [ -e ./labconfig.json ]; then
602 # We will configure all node, so we need the qty, and loop on it
603 NODE_QTY=$(cat labconfig.json | jq --raw-output '.lab.racks[0].nodes[]'.name | wc -l)
604 NODE_QTY=$((NODE_QTY-1))
605 for NODE_ID in $(seq 0 $NODE_QTY); do
606 # Get the NAME/SYS_ID of this node
607 NODE_NAME=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].name")
608 NODE_SYS_ID=$(maas $PROFILE nodes read | jq -r ".[] | select(.hostname==\"$NODE_NAME\")".system_id)
609 echo_info ">>> Configuring node $NODE_NAME [$NODE_ID][$NODE_SYS_ID]"
610 # Recover the network interfaces list and configure each one
611 # with sorting the list, we have hardware interface first, than the vlan interfaces
612 IF_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] ".ifname | sort -u )
613 for IF_NAME in $IF_LIST; do
614 # get the space of the interface
615 IF_SPACE=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NAME\") ".spaces[])
616 SUBNET_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$IF_SPACE'")'.cidr | cut -d \" -f 2 `
618 'data') IF_MODE='AUTO' ;;
619 'public') IF_MODE='AUTO' ;;
620 'storage') IF_MODE='AUTO' ;;
621 'floating') IF_MODE='link_up' ;;
622 *) SUBNET_CIDR='null'; IF_MODE='null'; echo_info " >>> Unknown SPACE" ;;
624 echo_info " >>> Configuring interface $IF_NAME [$IF_SPACE][$SUBNET_CIDR]"
626 # if we have a vlan parameter in the space config
627 IF_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$IF_SPACE\")".vlan)
628 if ([ -z $IF_VLAN ] && [ $IF_NAME =~ \. ]); then
629 # We have no vlan specified on spaces, but we have a vlan subinterface
630 IF_VLAN = ${IF_NAME##*.}; fi
632 # in case of interface renaming
635 # In case of a VLAN interface
636 if ([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
637 echo_info " >>> Configuring VLAN $IF_VLAN"
638 VLANID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".id)
639 FABRICID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".fabric_id)
640 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
641 if [[ -z $INTERFACE ]]; then
642 # parent interface is not set because it does not have a SUBNET_CIDR
643 PARENT_VLANID=$(maas $PROFILE fabrics read | jq ".[].vlans[] | select(.fabric_id==$FABRICID and .name==\"untagged\")".id)
644 # If we need to rename the interface, use new interface name
645 if ([ $IF_NEWNAME ] && [ "$IF_NEWNAME" != "null" ]); then
646 PARENT_IF_NAME=${IF_NEWNAME%%.*}
649 PARENT_IF_NAME=${IF_NAME%%.*}
651 # We set the physical interface to the targeted fabric
652 maas $PROFILE interface update $NODE_SYS_ID $PARENT_IF_NAME vlan=$PARENT_VLANID
654 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
656 maas $PROFILE interfaces create-vlan $NODE_SYS_ID vlan=$VLANID parent=$INTERFACE || true
658 # rename interface if needed
659 IF_MACLOWER=$( cat labconfig.json | jq ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NEWNAME\")".mac[0])
660 IF_MAC=(${IF_MACLOWER,,})
661 IF_ID=$( maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.mac_address==$IF_MAC)".id)
662 if ([ $IF_ID ] && [ "$IF_ID" != "null" ]); then
663 maas $PROFILE interface update $NODE_SYS_ID $IF_ID name=$IF_NEWNAME
666 # Configure the interface
667 if ([ $SUBNET_CIDR ] && [ "$SUBNET_CIDR" != "null" ]); then
668 VLANID=$(maas $PROFILE subnet read $SUBNET_CIDR | jq -r '.vlan.id')
669 if !([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
670 # If this interface is not a VLAN (done withe create-vlan)
671 maas $PROFILE interface update $NODE_SYS_ID $IF_NAME vlan=$VLANID || true
673 maas $PROFILE interface link-subnet $NODE_SYS_ID $IF_NAME mode=$IF_MODE subnet=$SUBNET_CIDR || true
676 echo_info " >>> Not configuring, we have an empty Subnet CIDR"
683 # Add the cloud and controller credentials for MAAS for that lab.
684 jujuver=`juju --version`
686 if [[ "$jujuver" > "2" ]]; then
694 echo_info "MAAS deployment finished successfully"