Shut down running labs VMs before building cluster
Running cluster VMs from an earlier cluster build have the potential to influence nodes (especially the controller node) while they are being built. To prevent that, this patch sends an ACPI powerbutton signal to all VMs in the group VM_GROUP. For KVM, we use the VM description's title field to store the group name. Change-Id: Ibe0a38a407c5e569b9a792faa7cf8b184f35022a
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
: ${VIRSH_CALL:=sudo virsh --connect=$LIBVIRT_CONNECT_URI}
|
||||
: ${VIRT_INSTALL_CALL:=sudo virt-install --connect=$LIBVIRT_CONNECT_URI}
|
||||
|
||||
# KVM VM group (stored in VM description)
|
||||
: ${VM_GROUP:=OpenStack training-labs}
|
||||
|
||||
# VM GUI type (one of headless, gui, vnc)
|
||||
: ${VM_UI:=vnc}
|
||||
|
||||
|
||||
@@ -41,6 +41,20 @@ function virsh_uses_kvm {
|
||||
# VM status
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function set_vm_group {
|
||||
local vm_name=$1
|
||||
|
||||
$VIRSH desc "$vm_name" --title --new-desc "$VM_GROUP"
|
||||
$VIRSH desc "$vm_name" --new-desc "All VMs with description title" \
|
||||
"'$VM_GROUP' get shut down when a new cluster build starts."
|
||||
}
|
||||
|
||||
function get_vm_group {
|
||||
local vm_name=$1
|
||||
|
||||
$VIRSH desc "$vm_name" --title
|
||||
}
|
||||
|
||||
function vm_exists {
|
||||
local vm_name=$1
|
||||
|
||||
@@ -72,6 +86,27 @@ function vm_power_off {
|
||||
fi
|
||||
}
|
||||
|
||||
function vm_acpi_shutdown {
|
||||
local vm_name=$1
|
||||
if vm_is_running "$vm_name"; then
|
||||
echo -e >&2 "${CStatus:-}ACPI shutdown for VM ${CData:-}\"$vm_name\"${CReset:-}"
|
||||
$VIRSH shutdown "$vm_name"
|
||||
fi
|
||||
}
|
||||
|
||||
function stop_running_cluster_vms {
|
||||
local vm_id
|
||||
|
||||
$VIRSH list --uuid | while read vm_id; do
|
||||
if [ -z "$vm_id" ]; then
|
||||
continue
|
||||
elif [ "$(get_vm_group "$vm_id")" = "$VM_GROUP" ]; then
|
||||
# vm_id instead of vm_name works just as well
|
||||
vm_acpi_shutdown "$vm_id"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function vm_snapshot {
|
||||
: # Not implemented
|
||||
}
|
||||
|
||||
@@ -72,6 +72,9 @@ function vm_init_node {
|
||||
echo -n .
|
||||
done
|
||||
|
||||
# Set VM group in description so we know which VMs are ours.
|
||||
set_vm_group "$vm_name"
|
||||
|
||||
# The SSH_IP needs to get out, so it can't be set in a sub-shell
|
||||
local mac=$(node_to_mac "$vm_name")
|
||||
echo -e "${CInfo:-}MAC address for node $vm_name: ${CData:-}$mac${CReset:-}"
|
||||
|
||||
@@ -81,6 +81,31 @@ function vm_power_off {
|
||||
vbox_sleep 1
|
||||
}
|
||||
|
||||
function vm_acpi_shutdown {
|
||||
local vm_name=$1
|
||||
if vm_is_running "$vm_name"; then
|
||||
echo -e >&2 "${CStatus:-}ACPI shutdown for VM ${CData:-}\"$vm_name\"${CReset:-}"
|
||||
$VBM controlvm "$vm_name" acpipowerbutton
|
||||
fi
|
||||
# VirtualBox VM needs a break before taking new commands
|
||||
vbox_sleep 1
|
||||
}
|
||||
|
||||
# Shut down all VMs in group VM_GROUP
|
||||
function stop_running_cluster_vms {
|
||||
local vm_id
|
||||
|
||||
# Get VM ID from a line looking like this:
|
||||
# "My VM" {0a13e26d-9543-460d-82d6-625fa657b7c4}
|
||||
$VBM list runningvms | sed 's/.* {\(.*\)}/\1/' | while read vm_id; do
|
||||
if $VBM showvminfo --machinereadable $vm_id |
|
||||
grep -qe '^groups="/'$VM_GROUP; then
|
||||
# vm_id instead of vm_name works just as well
|
||||
vm_acpi_shutdown $vm_id
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function vm_snapshot {
|
||||
local vm_name=$1
|
||||
local shot_name=$2
|
||||
|
||||
@@ -232,6 +232,8 @@ if [ "$CMD" = basedisk ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
stop_running_cluster_vms
|
||||
|
||||
echo "Building nodes using base disk $(get_base_disk_name)"
|
||||
|
||||
create_host_networks
|
||||
|
||||
Reference in New Issue
Block a user