2 #placeholder for deployment script.
10 { set +x; } 2> /dev/null
12 echo "OPNFV JOID deployer of the MAAS (Metal as a Service) infrastructure."
13 echo "Usage: $0 custom <path_to_labconfig>"
18 # Print usage help message if requested
19 if [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]
28 opnfvdistro=`cat /etc/lsb-release | grep CODENAME | cut -d "=" -f 2`
30 if [ "bionic" == "$opnfvdistro" ]; then
35 if [ ! -e $HOME/.ssh/id_rsa ]; then
36 ssh-keygen -N '' -f $HOME/.ssh/id_rsa
42 if [ "ppc64le" == "$NODE_ARCTYPE" ]; then
44 elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
46 CPU_MODEL="host-passthrough"
51 NODE_ARC="$NODE_ARCHES/generic"
53 # Install the packages needed
54 echo_info "Installing and upgrading required packages"
55 #sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5EDB1B62EC4926EA
56 sudo apt-get update -y || true
57 sudo apt-get install software-properties-common -y
59 if [ "$snapinstall" -eq "0" ]; then
60 sudo apt-add-repository ppa:juju/stable -y
61 sudo apt-add-repository ppa:maas/stable -y
63 if [ "bionic" != "$opnfvdistro" ]; then
64 sudo apt-add-repository cloud-archive:queens -y
65 if [ "aarch64" == "$NODE_ARCTYPE" ]; then
66 sudo add-apt-repository ppa:ubuntu-cloud-archive/queens-staging -y
70 sudo apt-get update -y || true
71 #sudo apt-get dist-upgrade -y
73 if [ "$snapinstall" -eq "1" ]; then
74 sudo apt-get install bridge-utils openssh-server bzr git virtinst qemu-kvm libvirt-bin \
75 maas maas-region-controller juju python-pip python-psutil python-openstackclient \
76 python-congressclient gsutil pastebinit python-jinja2 sshpass \
77 openssh-server vlan ipmitool jq expect snap -y --allow-unauthenticated
79 sudo snap install charm
80 sudo snap install --devmode --stable maas
82 sudo apt-get install bridge-utils openssh-server bzr git virtinst qemu-kvm libvirt-bin \
83 maas maas-region-controller juju python-pip python-psutil python-openstackclient \
84 python-congressclient gsutil charm-tools pastebinit python-jinja2 sshpass \
85 openssh-server vlan ipmitool jq expect snap -y --allow-unauthenticated
88 if [ "aarch64" == "$NODE_ARCTYPE" ]; then
89 sudo apt-get install qemu qemu-efi qemu-system-aarch64 -y --allow-unauthenticated
92 sudo -H pip install --upgrade pip
98 # Get labconfig and generate deployconfig.yaml
102 # Deployment with a custom labconfig file
104 if [ -z "$labfile" ]; then
105 if [ ! -e ./labconfig.yaml ]; then
106 # no labconfig file was specified and no ci/labconfig.yaml is present
107 echo_error "Labconfig file must be specified when using custom"
110 # no labconfig file was specified and but a (backup) ci/labconfig.yaml found
111 echo_warning "Labconfig was not specified, using ./labconfig.yaml instead"
112 # no action needed, ./labconfig.yaml already present
114 elif [ ! -e "$labfile" ]; then
115 # labconfig file was specified but does not exist on disk
116 echo_warning "Labconfig not found locally, trying download"
118 wget $labfile -t 3 -T 10 -O ./labconfig.yaml || true
119 count=`wc -l labconfig.yaml | cut -d " " -f 1`
120 if [ $count -lt 10 ]; then
121 echo_error "Unable to download labconfig"
125 echo_info "Using $labfile to setup deployment"
126 cp $labfile ./labconfig.yaml
129 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
130 labname=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
133 # Virtual deployment using a default labconfig file
134 echo_info "Using default labconfig for virtual install"
135 cp ../labconfig/default/labconfig.yaml ./
136 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
142 echo_error "Unknown script argument: $labname"
147 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < labconfig.yaml > labconfig.json
148 python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < deployconfig.yaml > deployconfig.json
150 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
151 MAAS_NAME=`grep "maas_name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
152 API_SERVER="http://$MAAS_IP:5240/MAAS/api/2.0"
153 API_SERVERMAAS="http://$MAAS_IP:5240/MAAS/"
155 MY_UPSTREAM_DNS=`grep "upstream_dns" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
156 SSH_KEY=`cat ~/.ssh/id_rsa.pub`
157 MAIN_ARCHIVE=`grep "main_archive" deployconfig.yaml | cut -d ':' -f 2-3 | sed -e 's/ //'`
158 URL=https://images.maas.io/ephemeral-v3/daily/
159 KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
162 PRIMARY_RACK_CONTROLLER="$MAAS_IP"
163 VLAN_UNTTAGED="untagged"
165 # In the case of a virtual deployment get deployconfig.yaml
168 #create backup directory
169 mkdir ~/joid_config/ || true
171 # Backup deployconfig.yaml in joid_config folder
173 if [ -e ./deployconfig.yaml ]; then
174 cp ./deployconfig.yaml ~/joid_config/
175 cp ./labconfig.yaml ~/joid_config/
179 # Prepare local environment to avoid password asking
182 # make sure no password asked during the deployment.
183 sudoer_file=/etc/sudoers.d/90-joid-init
184 sudoer_entry="$USER ALL=(ALL) NOPASSWD:ALL"
185 if [ -e $sudoer_file ]; then
186 if ! sudo grep -q "$sudoer_entry" $sudoer_file; then
187 sudo sed -i -e "1i$sudoer_entry" $sudoer_file
190 echo "$sudoer_entry" > 90-joid-init
191 sudo chown root:root 90-joid-init
192 sudo mv 90-joid-init /etc/sudoers.d/
195 echo_info "Deployment of MAAS started"
201 # define the pool and try to start even though its already exist.
202 # For fresh install this may or may not there.
203 #some system i am seeing libvirt and some have libvirtd looks like libvirt-bin is
204 #keep switching so lets try both.
206 sudo adduser $USER libvirtd || true
207 sudo adduser $USER libvirt || true
208 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
209 sudo virsh pool-start default || true
210 sudo virsh pool-autostart default || true
212 # As we use kvm so setup network on admin network
213 ADMIN_BR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.bridge | cut -d \" -f 2 `
214 sed -i "s@brAdm@$ADMIN_BR@" net.xml
215 sudo virsh net-destroy default || true
216 sudo virsh net-undefine default || true
217 sudo virsh net-define net.xml || true
218 sudo virsh net-autostart default || true
219 sudo virsh net-start default || true
222 # Cleanup, juju init and config backup
225 # To avoid problem between apiclient/maas_client and apiclient from google
226 # we remove the package google-api-python-client from yardstick installer
227 if [ $(pip list --format=columns | grep google-api-python-client | wc -l) == 1 ]; then
228 sudo pip uninstall google-api-python-client
231 if [ "$snapinstall" -eq "0" ]; then
232 if [ ! -e ~maas/.ssh/id_rsa.pub ]; then
233 if [ ! -e $HOME/id_rsa_maas.pub ]; then
234 [ -e $HOME/id_rsa_maas ] && rm -f $HOME/id_rsa_maas
235 sudo su - $USER -c "echo |ssh-keygen -t rsa -f $HOME/id_rsa_maas"
237 sudo -u maas mkdir ~maas/.ssh/ || true
238 sudo cp $HOME/id_rsa_maas ~maas/.ssh/id_rsa
239 sudo cp $HOME/id_rsa_maas.pub ~maas/.ssh/id_rsa.pub
240 sudo chown maas:maas ~maas/.ssh/id_rsa
241 sudo chown maas:maas ~maas/.ssh/id_rsa.pub
242 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
245 if [ ! -e /root/.ssh/id_rsa.pub ]; then
246 if [ ! -e $HOME/id_rsa_maas.pub ]; then
247 [ -e $HOME/id_rsa_maas ] && rm -f $HOME/id_rsa_maas
248 sudo su - $USER -c "echo |ssh-keygen -t rsa -f $HOME/id_rsa_maas"
250 sudo -u root mkdir /root/.ssh/ || true
251 sudo cp $HOME/id_rsa_maas /root/.ssh/id_rsa
252 sudo cp $HOME/id_rsa_maas.pub /root/.ssh/id_rsa.pub
253 sudo chown root:root /root/.ssh/id_rsa
254 sudo chown root:root /root/.ssh/id_rsa.pub
255 sudo cat /root/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
259 # Ensure virsh can connect without ssh auth
260 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
262 if [ "$snapinstall" -eq "1" ]; then
263 sudo maas init --mode all --maas-url http://$MAAS_IP:5240/MAAS --admin-username $PROFILE \
264 --admin-password $PROFILE --admin-email ubuntu@ubuntu.com || true
265 API_KEY=`sudo maas apikey --username=$PROFILE`
267 sudo maas-rack config --region-url http://$MAAS_IP:5240/MAAS
268 sudo maas createadmin --username=$PROFILE --email=ubuntu@ubuntu.com --password=$PROFILE || true
269 API_KEY=`sudo maas-region apikey --username=$PROFILE`
273 # https://insights.ubuntu.com/2016/01/23/maas-setup-deploying-openstack-on-maas-1-9-with-juju/
274 # http://blog.naydenov.net/2016/01/nodes-networking-deploying-openstack-on-maas-1-9-with-juju/
277 #reconfigure maas with correct MAAS address.
278 maas login $PROFILE $API_SERVERMAAS $API_KEY
279 maas $PROFILE maas set-config name='main_archive' value=$MAIN_ARCHIVE || true
280 maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS || true
281 maas $PROFILE maas set-config name='maas_name' value=$MAAS_NAME || true
282 maas $PROFILE maas set-config name='ntp_server' value='ntp.ubuntu.com' || true
283 maas $PROFILE domain update 0 name=$MAAS_NAME || true
284 maas $PROFILE sshkeys create "key=$SSH_KEY" || true
286 for tag in bootstrap compute control storage
288 maas $PROFILE tags create name=$tag || true
291 #below tag would be used to enable huge pages for DPDK and SRIOV enablement in Ubuntu kernel via MAAS
292 maas $PROFILE tags create name='opnfv-dpdk' comment='OPNFV DPDK enablement' \
293 kernel_opts='hugepagesz=2M hugepages=1024 hugepagesz=1G hugepages=20 default_hugepagesz=1G intel_iommu=on' || true
295 #maas $PROFILE package-repositories create name="Ubuntu Proposed new" \
296 # url="http://archive.ubuntu.com/ubuntu" components="main" \
297 # distributions="xenial-proposed" arches=amd64,i386
299 #create the required spaces.
300 maas $PROFILE space update 0 name=default || true
301 for space in admin-api internal-api public-api \
302 storage-access storage-cluster admin \
303 tenant-data tenant-api tenant-public os-api
305 echo_info "Creating the space $space"
306 maas $PROFILE spaces create name=$space || true
309 maas $PROFILE boot-source update $SOURCE_ID \
310 url=$URL keyring_filename=$KEYRING_FILE || true
312 maas $PROFILE boot-source-selections create 1 \
313 os="ubuntu" release="xenial" arches="amd64" \
315 maas $PROFILE boot-source-selections create 1 \
316 os="ubuntu" release="bionic" arches="amd64" \
319 if [ $NODE_ARCTYPE != "x86_64" ] ; then
320 maas $PROFILE boot-source-selection update 1 1 arches="$NODE_ARCHES" || true
321 maas $PROFILE boot-source-selection update 1 2 arches="$NODE_ARCHES" || true
324 if [ "$snapinstall" -eq "0" ]; then
325 maas $PROFILE boot-resources import || true
328 while [ "$(maas $PROFILE boot-resources is-importing)" == "true" ];
335 #get space, subnet and vlan and create accordingly.
336 #for type in admin osapi data storage external floating public; do
337 nettypes=`cat labconfig.json | jq '.opnfv.spaces[]'.type | cut -d \" -f 2`
338 for type in $nettypes; do
340 SPACE_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.cidr | cut -d \" -f 2 `
341 SPACE_VLAN=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.vlan | cut -d \" -f 2 `
342 SPACE_GWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.gateway | cut -d \" -f 2 `
343 NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
344 if ([ $NET_FABRIC_NAME ] && [ $NET_FABRIC_NAME != "null" ]); then
345 NET_FABRIC_VID=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.vid)
346 NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
347 if ([ $SPACE_VLAN == "null" ]); then
350 NET_VLAN_ID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".id)
351 NET_VLAN_VID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".vid)
352 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
353 maas $PROFILE subnet update $SPACE_CIDR gateway_ip=$SPACE_GWAY || true
355 if ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == "0" ]); then
357 elif ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == $SPACE_VLAN ]); then
360 NET_VLAN_ID=$(maas $PROFILE vlans create $NET_FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
361 if ([ $NET_VLAN_ID ] && [ $NET_VLAN_ID != "null" ]); then
362 maas $PROFILE subnet update $SPACE_CIDR vlan=$NET_VLAN_ID || true
363 NET_FABRIC_VID=$SPACE_VLAN
367 if ([ $SPACE_CIDR ] && [ "$SPACE_CIDR" != "null" ]); then
368 FABRIC_ID=$(maas $PROFILE fabrics create name=opnfv$type | jq --raw-output ".id")
369 NET_FABRIC_ID=$FABRIC_ID
370 NET_FABRIC_VID=$SPACE_VLAN
371 if ([ $SPACE_VLAN ] && [ "$SPACE_VLAN" != "null" ]); then
372 NET_VLAN_ID=$(maas $PROFILE vlans create $FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
373 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
374 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID gateway_ip=$SPACE_GWAY || true
376 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID || true
378 NET_FABRIC_VID=$VLAN_ID
380 if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
381 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0" gateway_ip=$SPACE_GWAY || true
383 maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0" || true
386 NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
390 'admin') JUJU_SPACE="internal-api"; DHCP='enabled' ;;
391 'data') JUJU_SPACE="tenant-data"; DHCP='' ;;
392 'public') JUJU_SPACE="public-api"; DHCP='' ;;
393 'storage') JUJU_SPACE="storage-cluster"; DHCP='' ;;
394 'storageaccess') JUJU_SPACE="storage-data"; DHCP='' ;;
395 'floating') JUJU_SPACE="tenant-public"; DHCP='' ;;
396 'osapi') JUJU_SPACE="os-api"; DHCP='' ;;
397 *) JUJU_SPACE='default'; DHCP='OFF'; echo_info " >>> Unknown SPACE" ;;
399 JUJU_SPACE_ID=$(maas $PROFILE spaces read | jq -r ".[] | select(.name==\"$JUJU_SPACE\")".id)
400 JUJU_VLAN_VID=$(maas $PROFILE subnets read | jq -r ".[] | select(.name==\"$SPACE_CIDR\")".vlan.vid)
401 NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
402 if ([ $NET_FABRIC_ID ] && [ $NET_FABRIC_ID != "null" ]); then
403 if ([ $JUJU_VLAN_VID ] && [ $JUJU_VLAN_VID != "null" ]); then
404 maas $PROFILE vlan update $NET_FABRIC_ID $JUJU_VLAN_VID space=$JUJU_SPACE_ID || true
407 if ([ $type == "admin" ]); then
408 # If we have a network, we create it
409 if ([ $NET_FABRIC_ID ]); then
411 SUBNET_PREFIX=${SPACE_CIDR::-5}
412 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
413 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
414 IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
415 IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
416 maas $PROFILE ipranges create type=reserved \
417 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
418 comment='This is a reserved range' || true
419 maas $PROFILE ipranges create type=dynamic \
420 start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
421 comment='This is a reserved dynamic range' || true
423 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
424 maas $PROFILE vlan update $NET_FABRIC_ID $NET_FABRIC_VID dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
426 elif ([ $type == "public" ] || [ $type == "osapi" ]); then
427 # If we have a network, we create reserve IPS for public IP range
428 if ([ $NET_FABRIC_ID ]); then
430 SUBNET_PREFIX=${SPACE_CIDR::-5}
431 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
432 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
433 maas $PROFILE ipranges create type=reserved \
434 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
435 comment='This is a reserved range' || true
438 if ([ $NET_FABRIC_ID ]); then
440 SUBNET_PREFIX=${SPACE_CIDR::-5}
441 IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
442 IP_RES_RANGE_HIGH="$SUBNET_PREFIX.5"
443 maas $PROFILE ipranges create type=reserved \
444 start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
445 comment='This is a reserved range' || true
452 maas login $PROFILE $API_SERVERMAAS $API_KEY
454 maas $PROFILE maas set-config name=default_min_hwe_kernel value=hwe-16.04-edge || true
456 # make sure there is no machine entry in maas
457 for m in $(maas $PROFILE machines read | jq -r '.[].system_id')
459 maas $PROFILE machine delete $m
461 podno=$(maas $PROFILE pods read | jq -r ".[]".id)
462 maas $PROFILE pod delete $podno || true
464 # if we have a virshurl configuration we use it, else we use local
465 VIRSHURL=$(cat labconfig.json | jq -r '.opnfv.virshurl')
466 if ([ $VIRSHURL == "" ] || [ "$VIRSHURL" == "null" ]); then
468 VIRSHURL="qemu+ssh://$USER@$VIRSHIP/system "
471 VIRSHHOST=$(echo $VIRSHURL| cut -d\/ -f 3 | cut -d@ -f2)
472 VIRSHIP="" # TODO: parse from $VIRSHURL if needed
475 if ([ "$VIRSHHOST" != "" ]); then
476 # Get the bridge hosting the remote virsh
477 brid=$(ssh $VIRSHHOST "ip a l | grep $VIRSHHOST | perl -pe 's/.* (.*)\$/\$1/g'")
478 netw=" --network bridge=$brid,model=virtio"
479 # prepare a file containing virsh remote url to connect without adding it n command line
480 echo "export VIRSH_DEFAULT_CONNECT_URI=$VIRSHURL" > virsh_uri.sh
484 brid=`sudo brctl show | grep 8000 | cut -d "8" -f 1 | tr "\n" " " | tr " " " " | tr -s " "`
485 ADMIN_BR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.bridge | cut -d \" -f 2 `
487 for feature in $brid; do
488 if ([ "$feature" == "$ADMIN_BR" ]); then
489 netw=$netw" --network bridge="$feature",model=virtio"
496 # Add server fingerprint to known hosts to prevent security prompt in the
497 # SSH connection during the virt-install
498 if [ $VIRSHIP != "" ]; then
499 # Check if the IP is not already present among the known hosts
500 if ! ssh-keygen -F $VIRSHIP > /dev/null ; then
501 echo_info "SSH fingerprint of the host is not known yet, adding to known_hosts"
502 ssh-keyscan -H $VIRSHIP >> ~/.ssh/known_hosts
506 echo_info "Creating and adding bootstrap node"
508 virt-install --connect $VIRSHURL --name bootstrap --ram 4098 --cpu $CPU_MODEL --vcpus 2 \
509 --disk size=20,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
510 $netw --boot network,hd,menu=off --video virtio --noautoconsole --autostart \
511 --accelerate --print-xml | tee bootstrap
513 if [ "$virtinstall" -eq 1 ]; then
514 bootstrapmac=`grep "mac address" bootstrap | head -1 | cut -d '"' -f 2`
517 bootstrapmacs=`grep "mac address" bootstrap| cut -d '"' -f 2`
518 for mac in $bootstrapmacs; do
519 bootstrapmac=$bootstrapmac" mac_addresses="$mac
522 virsh -c $VIRSHURL define --file bootstrap
528 maas $PROFILE machines create autodetect_nodegroup='yes' name='bootstrap' \
529 tags='bootstrap' hostname='bootstrap' power_type='virsh' mac_addresses=$bootstrapmac \
530 power_parameters_power_address="$VIRSHURL" \
531 architecture=$NODE_ARC power_parameters_power_id='bootstrap'
533 bootstrapid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == "bootstrap").system_id')
535 maas $PROFILE tag update-nodes bootstrap add=$bootstrapid
537 if [ "$virtinstall" -eq 1 ]; then
538 units=`cat deployconfig.json | jq .opnfv.units`
540 until [ $(($units)) -lt 1 ]; do
541 units=$(($units - 1));
542 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
544 virt-install --connect $VIRSHURL --name $NODE_NAME --ram 8192 --cpu $CPU_MODEL --vcpus 4 \
545 --disk size=120,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
546 $netw $netw --boot network,hd,menu=off --video virtio --noautoconsole --autostart \
547 --accelerate --print-xml | tee $NODE_NAME
549 nodemac=`grep "mac address" $NODE_NAME | head -1 | cut -d '"' -f 2`
550 virsh -c $VIRSHURL define --file $NODE_NAME
553 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
554 tags='control compute' hostname=$NODE_NAME power_type='virsh' mac_addresses=$nodemac \
555 power_parameters_power_address="$VIRSHURL" \
556 architecture=$NODE_ARC power_parameters_power_id=$NODE_NAME
557 nodeid=$(maas $PROFILE machines read | jq -r '.[] | select(.hostname == '\"$NODE_NAME\"').system_id')
558 maas $PROFILE tag update-nodes control add=$nodeid || true
559 maas $PROFILE tag update-nodes compute add=$nodeid || true
562 units=`cat deployconfig.json | jq .opnfv.units`
564 until [ $(($units)) -lt 1 ]; do
565 units=$(($units - 1));
566 NODE_NAME=`cat labconfig.json | jq ".lab.racks[].nodes[$units].name" | cut -d \" -f 2 `
567 MAC_ADDRESS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].nics[] | select(.spaces[]==\"admin\").mac"[0] | cut -d \" -f 2 `
568 POWER_TYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.type" | cut -d \" -f 2 `
569 POWER_IP=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.address" | cut -d \" -f 2 `
570 POWER_USER=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.user" | cut -d \" -f 2 `
571 POWER_PASS=`cat labconfig.json | jq ".lab.racks[].nodes[$units].power.pass" | cut -d \" -f 2 `
572 NODE_ARCTYPE=`cat labconfig.json | jq ".lab.racks[].nodes[$units].architecture" | cut -d \" -f 2 `
574 if [ "ppc64le" == "$NODE_ARCTYPE" ]; then
575 NODE_ARCHES="ppc64el"
576 elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
582 NODE_ARC="$NODE_ARCHES/generic"
584 echo_info "Creating node $NODE_NAME"
585 maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
586 hostname=$NODE_NAME power_type=$POWER_TYPE power_parameters_power_address=$POWER_IP \
587 power_parameters_power_user=$POWER_USER power_parameters_power_pass=$POWER_PASS \
588 mac_addresses=$MAC_ADDRESS architecture=$NODE_ARC
592 # Iterate to avoid "Conflict error" issue
593 for ii in 1 2 3 4 5 6 7 8 9 10
596 maas $PROFILE pods create type=virsh power_address="$VIRSHURL" power_user=$USER > /tmp/deploy.out 2>&1 || true
598 if ! fgrep -q 'Conflict' /tmp/deploy.out
607 # Make sure nodes are added into MAAS and none of them is in commissioning state
609 while [ "$(maas $PROFILE nodes read | grep Commissioning )" ];
611 echo_info "Waiting for nodes to finish commissioning. ${i} minutes elapsed."
615 # Make sure that no nodes have failed commissioning or testing
616 if [ "$(maas $PROFILE nodes read | grep 'Failed' )" ];
618 echo "Error: Some nodes have failed commissioning or testing" 1>&2
626 # configure MAAS with the different options.
630 # functioncall with subnetid to add and second parameter is dhcp enable
631 # third parameter will define the space. It is required to have admin
635 if [ "$snapinstall" -eq 0 ]; then
636 sudo sed -i 's/localhost/'$MAAS_IP'/g' /etc/maas/rackd.conf
637 sudo service maas-rackd restart
638 sudo service maas-regiond restart
642 # Let's add the nodes now. Currently works only for virtual deployment.
645 echo_info "Initial deployment of MAAS finished"
647 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
648 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
649 #maas $PROFILE sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
652 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
653 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
655 echo "credentials:" > credential.yaml
656 echo " $controllername:" >> credential.yaml
657 echo " opnfv-credentials:" >> credential.yaml
658 echo " auth-type: oauth1" >> credential.yaml
659 echo " maas-oauth: $API_KEY" >> credential.yaml
661 juju add-credential $controllername -f credential.yaml --replace
665 controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
666 cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
668 echo "clouds:" > maas-cloud.yaml
669 echo " $cloudname:" >> maas-cloud.yaml
670 echo " type: maas" >> maas-cloud.yaml
671 echo " auth-types: [oauth1]" >> maas-cloud.yaml
672 echo " endpoint: $API_SERVERMAAS" >> maas-cloud.yaml
674 echo_info "Adding cloud $cloudname"
675 juju add-cloud $cloudname maas-cloud.yaml --replace
679 # Enable MAAS nodes interfaces
681 maas login $PROFILE $API_SERVERMAAS $API_KEY
683 if [ -e ./labconfig.json ]; then
684 # We will configure all node, so we need the qty, and loop on it
685 NODE_QTY=$(cat labconfig.json | jq --raw-output '.lab.racks[0].nodes[]'.name | wc -l)
686 NODE_QTY=$((NODE_QTY-1))
687 for NODE_ID in $(seq 0 $NODE_QTY); do
688 # Get the NAME/SYS_ID of this node
689 NODE_NAME=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].name")
690 NODE_SYS_ID=$(maas $PROFILE nodes read | jq -r ".[] | select(.hostname==\"$NODE_NAME\")".system_id)
691 echo_info ">>> Configuring node $NODE_NAME [$NODE_ID][$NODE_SYS_ID]"
692 # Recover the network interfaces list and configure each one
693 # with sorting the list, we have hardware interface first, than the vlan interfaces
694 IF_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] ".ifname | sort -u )
695 for IF_NAME in $IF_LIST; do
696 # get the space of the interface
697 IF_SPACE=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NAME\") ".spaces[])
698 SUBNET_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$IF_SPACE'")'.cidr | cut -d \" -f 2 `
700 'data') IF_MODE='AUTO' ;;
701 'public') IF_MODE='AUTO' ;;
702 'storage') IF_MODE='AUTO' ;;
703 'osapi') IF_MODE='AUTO' ;;
704 'floating') IF_MODE='link_up' ;;
705 *) SUBNET_CIDR='null'; IF_MODE='null'; echo_info " >>> Unknown SPACE" ;;
707 echo_info " >>> Configuring interface $IF_NAME [$IF_SPACE][$SUBNET_CIDR]"
709 # if we have a vlan parameter in the space config
710 IF_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$IF_SPACE\")".vlan)
711 if ([ -z $IF_VLAN ] && [ $IF_NAME =~ \. ]); then
712 # We have no vlan specified on spaces, but we have a vlan subinterface
713 IF_VLAN = ${IF_NAME##*.}; fi
715 # in case of interface renaming
718 # In case of a VLAN interface
719 if ([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
720 echo_info " >>> Configuring VLAN $IF_VLAN"
721 VLANID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".id)
722 if ([ $VLANID ] && [ "$VLANID" != "null" ]); then
723 FABRICID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".fabric_id)
724 if ([ $FABRICID ] && [ "$FABRICID" != "null" ]); then
725 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
728 if [[ -z $INTERFACE ]]; then
729 # parent interface is not set because it does not have a SUBNET_CIDR
730 PARENT_VLANID=$(maas $PROFILE fabrics read | jq ".[].vlans[] | select(.fabric_id==$FABRICID and .name==\"untagged\")".id)
731 # If we need to rename the interface, use new interface name
732 if ([ $IF_NEWNAME ] && [ "$IF_NEWNAME" != "null" ]); then
733 PARENT_IF_NAME=${IF_NEWNAME%%.*}
736 PARENT_IF_NAME=${IF_NAME%%.*}
738 # We set the physical interface to the targeted fabric
739 maas $PROFILE interface update $NODE_SYS_ID $PARENT_IF_NAME vlan=$PARENT_VLANID
741 INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
743 maas $PROFILE interfaces create-vlan $NODE_SYS_ID vlan=$VLANID parent=$INTERFACE || true
745 # rename interface if needed
746 IF_MACLOWER=$( cat labconfig.json | jq ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.ifname==\"$IF_NEWNAME\")".mac[0])
747 IF_MAC=(${IF_MACLOWER,,})
748 IF_ID=$( maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.mac_address==$IF_MAC)".id)
749 if ([ $IF_ID ] && [ "$IF_ID" != "null" ]); then
750 maas $PROFILE interface update $NODE_SYS_ID $IF_ID name=$IF_NEWNAME
753 # Configure the interface
754 if ([ $SUBNET_CIDR ] && [ "$SUBNET_CIDR" != "null" ]); then
755 VLANID=$(maas $PROFILE subnet read $SUBNET_CIDR | jq -r '.vlan.id')
756 if !([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
757 # If this interface is not a VLAN (done withe create-vlan)
758 maas $PROFILE interface update $NODE_SYS_ID $IF_NAME vlan=$VLANID || true
760 maas $PROFILE interface link-subnet $NODE_SYS_ID $IF_NAME mode=$IF_MODE subnet=$SUBNET_CIDR || true
763 echo_info " >>> Not configuring, we have an empty Subnet CIDR"
770 # Add the cloud and controller credentials for MAAS for that lab.
777 echo_info "MAAS deployment finished successfully"