From d2a776ae67917fccc1ae9ada8b62497b115471a4 Mon Sep 17 00:00:00 2001 From: Lenny Chen Date: Mon, 13 Nov 2023 10:40:40 -0800 Subject: [PATCH] fix: added script to check for and delete packer cache --- .../clone_vm_template/delete-packer-cache.sh | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 edge/vmware/clone_vm_template/delete-packer-cache.sh diff --git a/edge/vmware/clone_vm_template/delete-packer-cache.sh b/edge/vmware/clone_vm_template/delete-packer-cache.sh new file mode 100644 index 0000000..d970e6b --- /dev/null +++ b/edge/vmware/clone_vm_template/delete-packer-cache.sh @@ -0,0 +1,20 @@ +#!/bin/bas + +source /edge/vmware/clone_vm_template/setenv.sh + +# Check if the packer cache exists +CACHE_EXISTS=$(govc datastore.ls -ds=$vcenter_datastore /packer_cache 2>/dev/null) + +if [ -z "$CACHE_EXISTS" ]; then + echo "Existing packer cache not found. Nothing to delete." +else + # Cache exists, attempt to delete it + govc datastore.rm -ds=$vcenter_datastore /packer_cache + RESULT=$? + if [ $RESULT -eq 0 ]; then + echo "Deleted previous packer cache." + else + echo "Failed to delete packer cache." + fi +fi +