blob: d81a5c8dabb3fb255e3bc2de736300bc849baece [file] [log] [blame]
Dean Troyerca0e3d02012-04-13 15:58:37 -05001#!/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
8function 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
18TOOLS_DIR=$(cd $(dirname "$0") && pwd)
19TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
20
21# Import common functions
22source $TOP_DIR/functions
23
24# Import configuration
25source $TOP_DIR/openrc "" "" "" ""
26
27# Find the cache dir
28FILES=$TOP_DIR/files
29
30if [[ -z "$1" ]]; then
31 usage
32fi
33
34# Get a token to authenticate to glance
35TOKEN=$(keystone token-get | grep ' id ' | get_field 2)
DennyZhangacb52e52013-10-11 00:08:29 -050036die_if_not_set $LINENO TOKEN "Keystone fail to get token"
Dean Troyerca0e3d02012-04-13 15:58:37 -050037
38# Glance connection info. Note the port must be specified.
39GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$GLANCE_HOST:9292}
40
41for IMAGE in "$*"; do
42 upload_image $IMAGE $TOKEN
43done