Implement a script that checks available storage space in a specified datastore associated with a given cluster in a vSphere environment. The script should perform the following functionality:
Retrieve the name of the cluster from an environment variable and convert it to uppercase.
Use the govc command-line tool to fetch information about the datastore, specifically the available free space in GB.
Calculate the total available space in a manner that adds one to this value.
Ensure that the final result is an integer.
If the available space (after the increment) is less than 10,000 GB, the script should output "No more space!" and exit with a failure status (exit 1).
If there is sufficient space (10,000 GB or above), the script should output "Ok!" and exit successfully (exit 0).
Expected Inputs and Outputs
Inputs:
The script should read the CLUSTER variable from an external environment configuration or script (like govc_env).
Outputs:
The script should print "No more space!" if available space is below 10,000 GB.
The script should print "Ok!" if available space is 10,000 GB or more.
File Locations and Naming
Your solution should be placed in the /app/ directory.
Name the script check_storage.sh.
Ensure that the govc command-line tool is installed and properly configured in the environment where this script will run.
Tests
The following test script will be used to verify your solution:
bash
#!/bin/bash
. ./govc_env
. ./env
CLUSTER=$( echo $CLUSTER | tr '[:lower:]' '[:upper:]' )
DELLVSAN=$( govc datastore.info ${CLUSTER}-VSAN | grep Free | sed -e "s/^.*://" -e "s/GB//" -e "s/ //g" )
DELLVSAN=$( echo "${DELLVSAN}/1" | bc )
DELLVSAN=$( expr ${DELLVSAN} )
if [ ${DELLVSAN} -lt 10000 ]; then
echo "No more space!"
exit 1
fi
echo "Ok!"
exit 0