From f1837236e265cfa6f38ea8d4f4d11489e27133bb Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sat, 22 Oct 2022 10:25:27 +0200 Subject: [PATCH] Add a virshall virshall can start, shutdown or destroy all VMs on a hypervisor LAB so I can remove 'start' from create and pristine; sometimes it is useful to only create (but not start) the LABs. Similarly, sometimes bringing the LAB into pristine state, but without restarting the VMs, is useful. --- README.md | 16 ++++++++++------ create | 9 +-------- pristine | 11 ++--------- virshall | 23 +++++++++++++++++++++++ 4 files changed, 36 insertions(+), 23 deletions(-) create mode 100755 virshall diff --git a/README.md b/README.md index e76e1d0..9ff9367 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,12 @@ shut down the VMs and destroy the clones. ``` lab:~/src/lab$ ./generate --host hvn0.lab.ipng.ch --overlay default -lab:~/src/lab$ lab=0 ./destroy ## remove VMs and ZFS clones -lab:~/src/lab$ lab=0 ./create ## create ZFS 'pristine' snapshot and start VMs -lab:~/src/lab$ lab=0 ./pristine ## return the lab to the latest 'pristine' snapshot +lab:~/src/lab$ LAB=0 ./destroy ## remove VMs and ZFS clones +lab:~/src/lab$ LAB=0 ./create ## create ZFS 'pristine' snapshot +lab:~/src/lab$ LAB=0 ./virshall start ## Start the VMs +lab:~/src/lab$ LAB=0 ./virshall shutdown ## Gracefully stop the VMs +lab:~/src/lab$ LAB=0 ./virshall destroy ## Hard poweroff the VMs +lab:~/src/lab$ LAB=0 ./pristine ## return the lab to the latest 'pristine' snapshot ``` ### Generate @@ -111,7 +114,7 @@ clones are destroyed. Obviously this is the most dangerous operation of the bunc of the lab is that the VMs can be re-created off of a stable base image and a generated build. ``` -lab:~/src/lab$ lab=0 ./destroy ## remove VMs and ZFS clones on hvn0.lab.ipng.ch +lab:~/src/lab$ LAB=0 ./destroy ## remove VMs and ZFS clones on hvn0.lab.ipng.ch ``` ### Create @@ -126,7 +129,7 @@ Typically, it's necessary to destroy/create, only when the build or the base ima the lab can be brought back into a _factory default_ state by rolling back to the `pristine` snapshot. ``` -lab:~/src/lab$ lab=0 ./create ## create ZFS 'pristine' snapshots and start VMs +lab:~/src/lab$ LAB=0 ./create ## create ZFS 'pristine' snapshots and start VMs ``` ### Pristine @@ -137,5 +140,6 @@ brought back into a default state by rolling back the disks to the `pristine` sn the virtual machines. ``` -lab:~/src/lab$ lab=0 ./pristine ## return the lab to the latest 'pristine' snapshot +lab:~/src/lab$ LAB=0 ./pristine ## return the lab to the latest 'pristine' snapshot +lab:~/src/lab$ LAB=0 ./vishall start ## Start the VMs ``` diff --git a/create b/create index 16fb90b..934efde 100755 --- a/create +++ b/create @@ -15,7 +15,7 @@ ## * Unmount the staging directories ## * Start the VMs -BASE=${BASE:=ssd-vol0/hvn0.chbtl0.ipng.ch/ssd-vol0/vpp-proto-disk0@20221019-release} +BASE=${BASE:=ssd-vol0/hvn0.chbtl0.ipng.ch/ssd-vol0/vpp-proto-disk0@20221022-release} BUILD=${BUILD:=default} LAB=${LAB:=0} @@ -39,10 +39,3 @@ ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; chown -R r echo "* Unmounting and snapshotting pristine state" ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; umount $STAGING/\$VM; zfs snapshot ssd-vol0/\${VM}@pristine; done" - -echo "* Starting VMs" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; virsh start \$VM; done" - -echo "* Committing OVS config" -scp overlays/$BUILD/ovs-config.sh root@$HVN:$LABDIR -ssh root@$HVN "set -x; LAB=$LAB $LABDIR/ovs-config.sh" diff --git a/pristine b/pristine index bab3e7a..887d3b1 100755 --- a/pristine +++ b/pristine @@ -1,17 +1,10 @@ #!/bin/sh -BUILD=${BUILD:=default} LAB=${LAB:=0} ## Do not touch below this line -LABDIR=/var/lab -STAGING=$LABDIR/staging HVN="hvn${LAB}.lab.ipng.ch" -## Bring back into pristine state +## Destroy the VMs and bring them back into pristine state echo "* Restarting VMs from pristine snapshot" -ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; virsh destroy \$VM; zfs rollback ssd-vol0/\${VM}@pristine; virsh start \$VM; done" - -echo "* Committing OVS config" -scp overlays/$BUILD/ovs-config.sh root@$HVN:$LABDIR -ssh root@$HVN "set -x; $LABDIR/ovs-config.sh" +ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; virsh destroy \$VM; zfs rollback ssd-vol0/\${VM}@pristine; done" diff --git a/virshall b/virshall new file mode 100755 index 0000000..6081ce8 --- /dev/null +++ b/virshall @@ -0,0 +1,23 @@ +#!/bin/sh +BUILD=${BUILD:=default} +LAB=${LAB:=0} + +## Do not touch below this line +LABDIR=/var/lab +STAGING=$LABDIR/staging +HVN="hvn${LAB}.lab.ipng.ch" +CMD=$1 + +[ "$CMD" != "start" -a "$CMD" != "shutdown" -a "$CMD" != "destroy" ] && { + echo "Usage: LAB=0 ./virshall start|shutdown|destroy" + exit +} + +echo "* Executing $CMD against all VMs on lab $LAB" +ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; virsh $CMD \$VM; done" + +[ "$CMD" = "start" ] && { + echo "* Committing OVS config" + scp overlays/$BUILD/ovs-config.sh root@$HVN:$LABDIR + ssh root@$HVN "set -x; $LABDIR/ovs-config.sh" +}