Skip to content

Commit

Permalink
Merge "Add --url option to glance cli."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Dec 2, 2011
2 parents b183f43 + 0e9c16d commit 2da2794
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions bin/glance
Expand Up @@ -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]),
Expand All @@ -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):
Expand Down Expand Up @@ -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))

Expand All @@ -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 "
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2da2794

Please sign in to comment.