Fold destroy, pristine and virshall into 'command'. Add a lock to avoid destroying active/inuse LABs
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.json
|
||||
__pycache__/
|
||||
.peeringdb/
|
||||
.lock*
|
||||
|
49
command
Executable file
49
command
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
BUILD=${BUILD:=default}
|
||||
LAB=${LAB:=0}
|
||||
|
||||
[ -r .lock${LAB} ] && {
|
||||
echo "Lock file for LAB${LAB}, bailing"
|
||||
exit
|
||||
}
|
||||
|
||||
## 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" -a "$CMD" != "pristine" ] && {
|
||||
echo "Usage: LAB=0 ./command start|shutdown|destroy|pristine"
|
||||
exit
|
||||
}
|
||||
|
||||
VMS=$(ls -1 build/${BUILD}/${HVN}/)
|
||||
|
||||
for VM in $VMS; do
|
||||
echo "[$VM] Executing $CMD"
|
||||
case $CMD in
|
||||
pristine)
|
||||
echo "[$VM] Destroying VM"
|
||||
ssh root@$HVN "/usr/bin/virsh list --all | grep $VM.*running >/dev/null && virsh destroy $VM"
|
||||
echo "[$VM] Rolling VM back to pristine snapshot"
|
||||
ssh root@$HVN "zfs rollback ssd-vol0/${VM}@pristine"
|
||||
;;
|
||||
start|shutdown)
|
||||
echo "[$VM] Sending $CMD to VM"
|
||||
ssh root@$HVN "virsh $CMD $VM"
|
||||
;;
|
||||
destroy)
|
||||
echo "[$VM] Destroying VM"
|
||||
ssh root@$HVN "/usr/bin/virsh list --all | grep $VM.*running >/dev/null && virsh destroy $VM"
|
||||
echo "[$VM] Destroying ZFS image"
|
||||
ssh root@$HVN "zfs destroy -r ssd-vol0/$VM"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ "$CMD" = "start" ] && {
|
||||
echo "* Committing OVS config"
|
||||
scp overlays/$BUILD/ovs-config.sh root@$HVN:$LABDIR
|
||||
ssh root@$HVN "set -x; LAB=${LAB} $LABDIR/ovs-config.sh"
|
||||
}
|
5
create
5
create
@ -19,6 +19,11 @@ BASE=${BASE:=ssd-vol0/hvn0.chbtl0.ipng.ch/ssd-vol0/vpp-proto-disk0@20230403-rele
|
||||
BUILD=${BUILD:=default}
|
||||
LAB=${LAB:=0}
|
||||
|
||||
[ -r .lock${LAB} ] && {
|
||||
echo "Lock file for LAB${LAB}, bailing"
|
||||
exit
|
||||
}
|
||||
|
||||
## Do not touch below this line
|
||||
LABDIR=/var/lab
|
||||
STAGING=$LABDIR/staging
|
||||
|
26
destroy
26
destroy
@ -1,26 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
## Using SSH:
|
||||
## * Log in to hypervisor, retrieve list of running VMs
|
||||
## * Log in to hypervisor, retrieve list of ZFS volumes
|
||||
## * List any VM matching spec ^vpp[\d]+-[\d+]$
|
||||
## * List any ZFS datasets matching matching spec ^ssd-vol0/vpp[\d]+-[\d+]$
|
||||
## * If --force is set:
|
||||
## * Destroy matching VMs
|
||||
## * Recursively delete any matching ZFS datasets
|
||||
|
||||
BASE=${BASE:=ssd-vol0/hvn0.chbtl0.ipng.ch/ssd-vol0/vpp-proto-disk0@20221018-release}
|
||||
BUILD=${BUILD:=default}
|
||||
LAB=${LAB:=0}
|
||||
|
||||
## Do not touch below this line
|
||||
HVN="hvn${LAB}.lab.ipng.ch"
|
||||
|
||||
VMS=$(ls -1 build/${BUILD}/${HVN}/)
|
||||
|
||||
for VM in $VMS; do
|
||||
echo "[$VM] Destroying VM"
|
||||
ssh root@$HVN "/usr/bin/virsh list --all | grep $VM.*running >/dev/null && virsh destroy $VM"
|
||||
echo "[$VM] Destroying ZFS datasets"
|
||||
ssh root@$HVN "zfs destroy -r ssd-vol0/$VM"
|
||||
done
|
14
pristine
14
pristine
@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
BUILD=${BUILD:=default}
|
||||
LAB=${LAB:=0}
|
||||
|
||||
## Do not touch below this line
|
||||
HVN="hvn${LAB}.lab.ipng.ch"
|
||||
VMS=$(ls -1 build/${BUILD}/${HVN}/)
|
||||
|
||||
for VM in $VMS; do
|
||||
echo "[$VM] Destroying VM"
|
||||
ssh root@$HVN "/usr/bin/virsh list --all | grep $VM.*running >/dev/null && virsh destroy $VM"
|
||||
echo "[$VM] Rolling VM back to pristine snapshot"
|
||||
ssh root@$HVN "zfs rollback ssd-vol0/${VM}@pristine"
|
||||
done
|
27
virshall
27
virshall
@ -1,27 +0,0 @@
|
||||
#!/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
|
||||
}
|
||||
|
||||
VMS=$(ls -1 build/${BUILD}/${HVN}/)
|
||||
|
||||
for VM in $VMS; do
|
||||
echo "[$VM] Executing $CMD against VMs on lab $LAB"
|
||||
ssh root@$HVN "virsh $CMD $VM"
|
||||
done
|
||||
|
||||
[ "$CMD" = "start" ] && {
|
||||
echo "* Committing OVS config"
|
||||
scp overlays/$BUILD/ovs-config.sh root@$HVN:$LABDIR
|
||||
ssh root@$HVN "set -x; LAB=${LAB} $LABDIR/ovs-config.sh"
|
||||
}
|
Reference in New Issue
Block a user