diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-08-03 00:29:25 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-08-03 00:29:25 +0000 |
commit | 18543b1a46cad3e01613c4b5c933b7dfb68e048b (patch) | |
tree | 459130333a582f680f57821aee45b9532facc878 | |
parent | 61fdefbdd89284b53f60a172d27f8cde6f9223e7 (diff) | |
parent | 2541f3ce840492555160f8f31d775f443628fe9a (diff) | |
download | python-glanceclient-0.3.0.tar.gz |
Merge "Allow CLI opts to override auth token and endpoint"0.3.0
-rw-r--r-- | glanceclient/shell.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 3902d24..6ec6fff 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -271,7 +271,7 @@ class OpenStackImagesShell(object): endpoint = '/'.join(url_bits[:-1]) return endpoint - def _authenticate(self, **kwargs): + def _get_ksclient(self, **kwargs): """Get an endpoint and auth token from Keystone. :param username: name of user @@ -280,19 +280,19 @@ class OpenStackImagesShell(object): :param tenant_name: name of tenant :param auth_url: endpoint to authenticate against """ - _ksclient = ksclient.Client(username=kwargs.get('username'), - password=kwargs.get('password'), - tenant_id=kwargs.get('tenant_id'), - tenant_name=kwargs.get('tenant_name'), - auth_url=kwargs.get('auth_url'), - insecure=kwargs.get('insecure')) - service_type = kwargs.get('service_type') or 'image' - endpoint_type = kwargs.get('endpoint_type') or 'publicURL' - endpoint = _ksclient.service_catalog.url_for( - service_type=service_type, - endpoint_type=endpoint_type) - endpoint = self._strip_version(endpoint) - return (endpoint, _ksclient.auth_token) + return ksclient.Client(username=kwargs.get('username'), + password=kwargs.get('password'), + tenant_id=kwargs.get('tenant_id'), + tenant_name=kwargs.get('tenant_name'), + auth_url=kwargs.get('auth_url'), + insecure=kwargs.get('insecure')) + + def _get_endpoint(self, client, **kwargs): + """Get an endpoint using the provided keystone client.""" + endpoint = client.service_catalog.url_for( + service_type=kwargs.get('service_type') or 'image', + endpoint_type=kwargs.get('endpoint_type') or 'publicURL') + return self._strip_version(endpoint) def _get_image_url(self, args): """Translate the available url-related options into a single string. @@ -369,7 +369,11 @@ class OpenStackImagesShell(object): 'endpoint_type': args.os_endpoint_type, 'insecure': args.insecure } - endpoint, token = self._authenticate(**kwargs) + _ksclient = self._get_ksclient(**kwargs) + token = args.os_auth_token or _ksclient.auth_token + + endpoint = args.os_image_url or \ + self._get_endpoint(_ksclient, **kwargs) client = glanceclient.Client(api_version, endpoint, |