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 |
Peter Stachowski | 9a80892 | 2015-04-08 19:48:09 +0000 | [diff] [blame] | 35 | TOKEN=$(openstack token issue -c id -f value) |
DennyZhang | acb52e5 | 2013-10-11 00:08:29 -0500 | [diff] [blame] | 36 | die_if_not_set $LINENO TOKEN "Keystone fail to get token" |
Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 37 | |
| 38 | # Glance connection info. Note the port must be specified. |
| 39 | GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$GLANCE_HOST:9292} |
Gary Kotton | ffc1f8d | 2014-11-26 04:00:33 -0800 | [diff] [blame] | 40 | GLANCE_SERVICE_PROTOCOL=${GLANCE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
Dean Troyer | ca0e3d0 | 2012-04-13 15:58:37 -0500 | [diff] [blame] | 41 | |
| 42 | for IMAGE in "$*"; do |
| 43 | upload_image $IMAGE $TOKEN |
| 44 | done |