Fold destroy, pristine and virshall into 'command'. Add a lock to avoid destroying active/inuse LABs
This commit is contained in:
		
							
								
								
									
										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"
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user