Skip to content

Instantly share code, notes, and snippets.

@mig5
Created July 31, 2014 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mig5/515ffac6e4784614f533 to your computer and use it in GitHub Desktop.
Save mig5/515ffac6e4784614f533 to your computer and use it in GitHub Desktop.
vcloud-vm-lookup
#!/bin/bash
usage() {
cat << EOF
usage: $0 ARGUMENTS
Simple wrapper script to query the vCloud API and return a
YAML object of a specific virtual machine.
Written by mig5 July 2014
This script assumes you have performed the following on
your machine already:
1) gem install vcloud-core vcloud-tools
2) Created a ~/.fog file containing your vCloud API creds
per http://gds-operations.github.io/vcloud-tools/usage
ARGUMENTS:
-c <CREDS> where CREDS is your credentials variable for
vCloud (e.g the first line of your ~/.fog file).
Defaults to 'test_credentials'.
-n <NAME> where NAME is the name of your VM.
-h this help message
If no -n argument is sent, all VMs will be queried for and
displayed.
EOF
}
ARGS=
CREDS="test_credentials"
# Parse arguments
while getopts ":c:n:h" OPTIONS
do
case $OPTIONS in
h)
usage
exit
;;
c)
CREDS=$OPTARG
;;
n)
ARGS="--filter name==${OPTARG}"
;;
esac
done
# Have we got a valid vCloud token? If not, perform the
# authentication in order to get one
if [[ -z $FOG_VCLOUD_TOKEN ]]; then
eval $(FOG_CREDENTIAL=$CREDS vcloud-login)
fi
# Run the task
FOG_CREDENTIAL=$CREDS vcloud-query -o yaml vm $ARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment