Skip to content

Commit

Permalink
chore: modify script logic to rule out other errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lennessyy committed Nov 21, 2023
1 parent 8f7b1eb commit a5e61e7
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions edge/vmware/clone_vm_template/delete-packer-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a5e61e7

Please sign in to comment.