+#by default maas creates two VMs in case of three more VM needed.
+createresource() {
+ # TODO: make sure this function run with the same parameters used in 03-maasdeploy.sh
+ PROFILE=${PROFILE:-ubuntu}
+ MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
+ API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
+ API_KEY=`sudo maas-region apikey --username=ubuntu`
+ maas login $PROFILE $API_SERVER $API_KEY
+
+ for node in node3-control node4-control
+ do
+ node_id=$(maas $PROFILE machines read | \
+ jq -r ".[] | select(.hostname == \"$node\").system_id")
+ if [[ -z "$node_id" ]]; then
+ sudo virt-install --connect qemu:///system --name $node \
+ --ram 8192 --cpu host --vcpus 4 \
+ --disk size=120,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
+ --network bridge=virbr0,model=virtio \
+ --network bridge=virbr0,model=virtio \
+ --boot network,hd,menu=off \
+ --noautoconsole --vnc --print-xml | tee _node.xml
+ node_mac=$(grep "mac address" _node.xml | head -1 | cut -d "'" -f 2)
+ sudo virsh -c qemu:///system define --file _node.xml
+ rm -f _node.xml
+
+ maas $PROFILE nodes new autodetect_nodegroup='yes' name=$node \
+ tags='control' hostname=$name power_type='virsh' \
+ mac_addresses=$node3controlmac \
+ power_parameters_power_address="qemu+ssh://$USER@192.168.122.1/system" \
+ architecture='amd64/generic' power_parameters_power_id='node3-control'
+ node_id=$(maas $PROFILE machines read | \
+ jq -r ".[] | select(.hostname == \"$node\").system_id")
+ fi
+ if [[ -z "$node_id" ]]; then
+ echo "Error: failed to create node $node ."
+ exit 1
+ fi
+ maas $PROFILE tag update-nodes control add=$node_id || true
+ done