Don't create libvirt VM, if it already exists

This commit is contained in:
2020-12-29 00:41:42 +00:00
parent 94b8d9476b
commit 1ca6934c38

View File

@@ -212,6 +212,22 @@ wipe_disks() {
wait
}
machine_exists()
{
node_name=$1
virsh_machine=$(virsh list --all --name | grep ${node_name})
if [[ $virsh_machine != "" ]] ; then
macaddr=$(virsh domiflist ${node_name} | grep br0 | awk '{print $5}')
echo $macaddr
else
echo "false"
fi
}
# Builds the VMs from scratch, and then adds them to MAAS
build_vms() {
# To keep a track of how many juju VMs we have created
@@ -289,6 +305,18 @@ build_vms() {
done
fi
# Check to see if the libvirt machine already exists. If it exists
# then just use the same one again and commission in MAAS
check_machine=$(machine_exists ${virt_node})
if [[ $check_machine != "false" ]] ; then
macaddr=$check_machine
maas_add_node ${virt_node} ${macaddr} ${node_type} &
sleep ${build_fanout}
continue
fi
# Creates the VM with all the attributes given
virt-install -v --noautoconsole \
--print-xml \