Skip to content

Instantly share code, notes, and snippets.

@DavidWittman

DavidWittman/.bashrc

Created May 16, 2012
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@DavidWittman DavidWittman commented May 18, 2012

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
You can’t perform that action at this time.