Files
lab/create
2022-11-27 14:11:53 +00:00

42 lines
1.6 KiB
Bash
Executable File

#!/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 any of these exist, bail and require the user to run ./destroy first
##
##
## * Log in to the hypervisor, and:
## * Clone the base image to all VM names (ssd-vol0/vpp0-[0-3])
## * Mount these in a staging directory
## * Rsync over our build/$(overlay)/$(hypervisor)/*
## * Unmount the staging directories
## * Start the VMs
BASE=${BASE:=ssd-vol0/hvn0.chbtl0.ipng.ch/ssd-vol0/vpp-proto-disk0@20221127-release}
BUILD=${BUILD:=default}
LAB=${LAB:=0}
## Do not touch below this line
LABDIR=/var/lab
STAGING=$LABDIR/staging
HVN="hvn${LAB}.lab.ipng.ch"
echo "* Cloning base"
ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; mkdir -p $STAGING/\$VM; zfs clone $BASE ssd-vol0/\$VM; done"
sleep 1
echo "* Mounting in staging"
ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; mount /dev/zvol/ssd-vol0/\$VM-part1 $STAGING/\$VM; done"
echo "* Rsyncing build"
rsync -avugP build/$BUILD/$HVN/ root@hvn${LAB}.lab.ipng.ch:$STAGING
echo "* Setting permissions"
ssh root@$HVN "set -x; for node in 0 1 2 3; do VM=vpp${LAB}-\${node}; chown -R root. $STAGING/\$VM/root; done"
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"