Add --url option to glance cli.

Adds ability to select between http/https protocols.

Fixes bug 898097.

Change-Id: I1d20f314fb7dd8c5462c1f1ff22161ab59c35016
This commit is contained in:
Stuart McLaren 2011-12-01 17:32:44 +00:00
parent 1ab63ff5c9
commit 0e9c16dccf

View File

@ -30,6 +30,8 @@ import re
import sys
import time
from urlparse import urlparse
# If ../glance/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
@ -49,6 +51,8 @@ from glance.common import utils
SUCCESS = 0
FAILURE = 1
DEFAULT_PORT = 9292
#TODO(sirp): make more of the actions use this decorator
def catch_error(action):
@ -739,7 +743,7 @@ def get_client(options):
auth_url=os.getenv('OS_AUTH_URL'),
strategy=os.getenv('OS_AUTH_STRATEGY', 'noauth'))
use_ssl = (options.host.find('https') != -1 or (
use_ssl = (options.use_ssl or (
creds['auth_url'] is not None and
creds['auth_url'].find('https') != -1))
@ -763,9 +767,15 @@ def create_options(parser):
help="Address of Glance API host. "
"Default: %default")
parser.add_option('-p', '--port', dest="port", metavar="PORT",
type=int, default=9292,
type=int, default=DEFAULT_PORT,
help="Port the Glance API host listens on. "
"Default: %default")
parser.add_option('-U', '--url', metavar="URL", default=None,
help="URL of Glance service. This option can be used "
"to specify the hostname, port and protocol "
"(http/https) of the glance server, for example "
"-U https://localhost:" + str(DEFAULT_PORT) +
"/v1 Default: None")
parser.add_option('-A', '--auth_token', dest="auth_token",
metavar="TOKEN", default=None,
help="Authentication token to use to identify the "
@ -802,6 +812,12 @@ def parse_options(parser, cli_args):
cli_args.append('-h') # Show options in usage output...
(options, args) = parser.parse_args(cli_args)
if options.url is not None:
u = urlparse(options.url)
options.port = u.port
options.host = u.hostname
options.use_ssl = (options.url is not None and u.scheme == 'https')
# HACK(sirp): Make the parser available to the print_help method
# print_help is a command, so it only accepts (options, args); we could