diff options
author | Tomas Sedovic <tomas@sedovic.cz> | 2012-06-11 12:27:35 +0200 |
---|---|---|
committer | Tomas Sedovic <tomas@sedovic.cz> | 2012-06-11 13:34:37 +0200 |
commit | 66ba60d4b11eda81b7ffb55c3019a772a812bee7 (patch) | |
tree | 54c5e6967b4c531124681295b91dcf538f0034ee /bin | |
parent | d9c15b22d162cb74a8070a47538c9dd2fc13b7ec (diff) | |
download | heat-cfntools-66ba60d4b11eda81b7ffb55c3019a772a812bee7.tar.gz |
Make Glance hostname and port configurable
Fixes #128
Signed-off-by: Tomas Sedovic <tomas@sedovic.cz>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/heat-jeos | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/bin/heat-jeos b/bin/heat-jeos index 0a3adc2..0b8ad00 100755 --- a/bin/heat-jeos +++ b/bin/heat-jeos @@ -117,22 +117,50 @@ def command_register(options, arguments): dsk_path, qcow2_path, image_name = target_image_paths(options, distro, arch, instance_type) - logging.info('Registering JEOS image (%s) ' - 'with OpenStack Glance.' % image_name) + logging.info('Registering JEOS image (%s) with OpenStack Glance.' % + image_name) creds = dict(username=options.username, password=options.password, tenant=options.tenant, auth_url=options.auth_url, strategy=options.auth_strategy) - client = glance_client.Client(host="0.0.0.0", port=9292, - use_ssl=False, auth_tok=None, creds=creds) + # When neither host nor port are specified and we're using Keystone auth, + # let it tell us the Glance entrypoint + configure_via_auth = (options.auth_strategy == 'keystone' and + not (options.glance_host or options.glance_port)) + + # NOTE: these are ignored by the client when `configure_via_auth` is True + glance_host = options.glance_host if options.glance_host else '0.0.0.0' + try: + glance_port = int(options.glance_port) if options.glance_port else 9292 + except: + logging.error('Port must be a number.') + sys.exit(1) + + if configure_via_auth: + logging.debug('Using Glance entry point received by Keystone.') + else: + logging.debug('Connecting to Glance at host: %s, port: %d' % + (glance_host, glance_port)) + + client = glance_client.Client(host=glance_host, + port=glance_port, + use_ssl=False, + auth_tok=None, + configure_via_auth=configure_via_auth, + creds=creds) parameters = { "filters": {}, "limit": 10, } - images = client.get_images(**parameters) + + try: + images = client.get_images(**parameters) + except exception.ClientConnectionError, e: + logging.error('Failed to connect to the Glance API server.') + sys.exit(1) try: image = [i for i in images if i['name'] == image_name][0] @@ -374,6 +402,12 @@ def create_options(parser): parser.add_option('-y', '--yes', default=False, action="store_true", help="Don't prompt for user input; assume the answer to " "every question is 'yes'.") + parser.add_option('-H', '--glance-host', + default=None, + help="Glance hostname") + parser.add_option('-P', '--glance-port', + default=None, + help="Glance port number") parser.add_option('-A', '--auth_token', dest="auth_token", metavar="TOKEN", default=None, help="Authentication token to use to identify the " |