diff --git a/edge/vmware/clone_vm_template/delete-packer-cache.sh b/edge/vmware/clone_vm_template/delete-packer-cache.sh index a7a522f..ae62694 100644 --- a/edge/vmware/clone_vm_template/delete-packer-cache.sh +++ b/edge/vmware/clone_vm_template/delete-packer-cache.sh @@ -2,20 +2,25 @@ source /edge/vmware/clone_vm_template/setenv.sh -# Check if the packer cache exists -CACHE_OUTPUT=$(govc datastore.ls -ds=$vcenter_datastore /packer_cache 2>&1) +# First, list directories to confirm access and credentials +govc datastore.ls -ds=$vcenter_datastore +if [ $? -ne 0 ]; then + echo "Error accessing datastore. Please check credentials and permissions." + exit 1 +fi -if [[ $CACHE_OUTPUT == *"/packer_cache was not found"* ]]; then - echo "Existing packer cache not found. Nothing to delete." +# Now, try to list the packer_cache directory +govc datastore.ls -ds=$vcenter_datastore /packer_cache +if [ $? -ne 0 ]; 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." - exit 0 - else - echo "Failed to delete packer cache." - exit 1 - fi + # Cache exists, attempt to delete it + govc datastore.rm -ds=$vcenter_datastore /packer_cache + if [ $? -eq 0 ]; then + echo "Deleted previous packer cache." + exit 0 + else + echo "Failed to delete packer cache." + exit 1 + fi fi \ No newline at end of file