From 4ad32c64a6fd1ee0e1d8449ba3e2553245ccfa97 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 18 Oct 2019 16:51:28 +1100 Subject: [PATCH 1/2] Add curl, govc, and vmware upload script for quicker nodes updates --- Dockerfile | 6 +++++- govc.env | 8 ++++++++ upload-vmware.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 govc.env create mode 100644 upload-vmware.sh diff --git a/Dockerfile b/Dockerfile index 9db4872..daed232 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,11 @@ run apt-get update \ run yes |apt-get install -y grub2 grub-pc-bin grub-efi-amd64-bin \ && apt-get clean -run apt-get install -y ca-certificates \ +run apt-get install -y ca-certificates curl \ && apt-get clean +run curl -L https://github.com/vmware/govmomi/releases/download/v0.21.0/govc_linux_amd64.gz | gunzip > /bin/govc && chmod +x /bin/govc + +copy upload-vmware.sh govc.env /var/lib/direktil/ + copy --from=build /go/bin/ /bin/ diff --git a/govc.env b/govc.env new file mode 100644 index 0000000..3900582 --- /dev/null +++ b/govc.env @@ -0,0 +1,8 @@ +export GOVC_DATACENTER= +export GOVC_PASSWORD= +export GOVC_URL= +export GOVC_USERNAME= +export GOVC_INSECURE=1 +export GOVC_DATASTORE= +export NOVIT_VM_FOLDER= +export NOVIT_ISO_FOLDER= diff --git a/upload-vmware.sh b/upload-vmware.sh new file mode 100644 index 0000000..c48e28a --- /dev/null +++ b/upload-vmware.sh @@ -0,0 +1,28 @@ +set -e + +dir=/var/lib/direktil/ +PATH=$PATH:$dir +cd $dir + +if [ ! -f govc.env ]; then + echo ERROR: govc.env file not found in dir $dir ; exit 1 +fi +source govc.env + +if [ $# != 2 ]; then + echo "Usage: $0 " ; exit 1 +fi + +if [[ -z $NOVIT_VM_FOLDER || -z $NOVIT_ISO_FOLDER ]]; then + echo "ERROR: All GOVC env vars (including NOVIT_VM_FOLDER and NOVIT_ISO_FOLDER) must be provided" ; exit 1 +fi + +VM=$1 +HOST=$2 + +govc vm.power -off $NOVIT_VM_FOLDER/$VM || true +sleep 5 +curl localhost:7606/hosts/$HOST/boot.iso | govc datastore.upload - $NOVIT_ISO_FOLDER/$VM.iso +sleep 5 +govc vm.power -on $NOVIT_VM_FOLDER/$VM + From 43304de2ca3d4bf393d15da41201ab1a96c6eff1 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 18 Oct 2019 18:00:04 +1100 Subject: [PATCH 2/2] Add double quotes for path with spaces --- upload-vmware.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/upload-vmware.sh b/upload-vmware.sh index c48e28a..8c887a1 100644 --- a/upload-vmware.sh +++ b/upload-vmware.sh @@ -20,9 +20,8 @@ fi VM=$1 HOST=$2 -govc vm.power -off $NOVIT_VM_FOLDER/$VM || true +govc vm.power -off "$NOVIT_VM_FOLDER/$VM" || true sleep 5 -curl localhost:7606/hosts/$HOST/boot.iso | govc datastore.upload - $NOVIT_ISO_FOLDER/$VM.iso +curl localhost:7606/hosts/$HOST/boot.iso | govc datastore.upload - "$NOVIT_ISO_FOLDER/$VM.iso" sleep 5 -govc vm.power -on $NOVIT_VM_FOLDER/$VM - +govc vm.power -on "$NOVIT_VM_FOLDER/$VM"