Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # upload_image.sh - Retrieve and upload an image into Glance |
| 3 | # |
| 4 | # upload_image.sh <image-url> |
| 5 | # |
| 6 | # Assumes credentials are set via OS_* environment variables |
| 7 | |
| 8 | function usage { |
| 9 | echo "$0 - Retrieve and upload an image into Glance" |
| 10 | echo "" |
| 11 | echo "Usage: $0 <image-url> [...]" |
| 12 | echo "" |
| 13 | echo "Assumes credentials are set via OS_* environment variables" |
| 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | # Keep track of the current directory |
| 18 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
| 19 | TOP_DIR=$(cd $TOOLS_DIR/..; pwd) |
| 20 | |
| 21 | # Import common functions |
| 22 | source $TOP_DIR/functions |
| 23 | |
| 24 | # Import configuration |
| 25 | source $TOP_DIR/openrc "" "" "" "" |
| 26 | |
| 27 | # Find the cache dir |
| 28 | FILES=$TOP_DIR/files |
| 29 | |
| 30 | if [[ -z "$1" ]]; then |
| 31 | usage |
| 32 | fi |
| 33 | |
| 34 | # Get a token to authenticate to glance |
| 35 | TOKEN=$(keystone token-get | grep ' id ' | get_field 2) |
| 36 | |
| 37 | # Glance connection info. Note the port must be specified. |
| 38 | GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$GLANCE_HOST:9292} |
| 39 | |
| 40 | for IMAGE in "$*"; do |
| 41 | upload_image $IMAGE $TOKEN |
| 42 | done |