Skip to content

Instantly share code, notes, and snippets.

@DavidWittman
Created May 16, 2012 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidWittman/2706377 to your computer and use it in GitHub Desktop.
Save DavidWittman/2706377 to your computer and use it in GitHub Desktop.
boot - openstack-compute/nova wrapper for building Cloud Servers
# boot
# openstack-compute/nova wrapper for building Cloud Servers
# usage: boot <image> <flavor> <name>
function boot() {
# API Credentials
local USERNAME=${OPENSTACK_COMPUTE_USERNAME-"username"}
local APIKEY=${OPENSTACK_COMPUTE_APIKEY-"8b843e51cecdae209efd541b6dd52c04"}
# Boot specifics
local FLAVOR=3
local PREFIX="boot-server-"
local KEY="${HOME}/.ssh/id_rsa.pub"
local NOVA="/usr/local/bin/openstack-compute"
# Image IDs
local UBUNTU=216
local CENT=212
local CENT5=200
local LAMP=213
local UBUNTU_LAMP=217
# You probably won't need to change these
local SELF="boot"
local RUN=true
local USAGE="usage: ${SELF} <image> <flavor> <name>"
local AUTH="--username ${USERNAME} --apikey ${APIKEY}"
# Set image based on the first argument
case "${1}" in
# Image aliases
u?(buntu))
IMAGE=${UBUNTU}
;;
c?(ent?(os)))
IMAGE=${CENT}
;;
cent5)
IMAGE=${CENT5}
;;
lamp)
IMAGE=${LAMP}
;;
ul?(amp))
IMAGE=${UBUNTU_LAMP}
;;
# Use the first argument as the image-id
*)
IMAGE=${1}
;;
esac
# Handle arguments
case $# in
# No arguments, list available images and don't run
0)
${NOVA} ${AUTH} image-list
echo ${USAGE}
local RUN=false
;;
# One argument, do nothing
1)
;;
# Two arguments, set flavor to ${2}
2)
FLAVOR=${2}
;;
3)
FLAVOR=${2}
PREFIX=${3}
;;
# Invalid, display usage and don't run
*)
echo ${USAGE}
local RUN=false
;;
esac
# Run (if we should)
if ${RUN}; then
${NOVA} ${AUTH} boot \
--flavor ${FLAVOR} \
--key ${KEY} \
--image ${IMAGE} \
${PREFIX}${RANDOM}
fi
}
@DavidWittman
Copy link
Author

Looks like the extended case matching doesn't work on OSX. Here's a modified version of the case statement if you're running this on a Mac:

    # Set image based on the first argument
    case "${1}" in
        # Image aliases
        ubuntu)
            IMAGE=${UBUNTU}
            ;;
        cent)
            IMAGE=${CENT}
            ;;
        cent5)
            IMAGE=${CENT5}
            ;;
        lamp)
            IMAGE=${LAMP}
            ;;
        ulamp)
            IMAGE=${UBUNTU_LAMP}
            ;;
        # Use the first argument as the image-id
        *)
            IMAGE=${1}
            ;;
    esac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment