From a18209fc994bf008526bb7674be7a3e3b3b2b89e Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Fri, 30 May 2014 16:35:50 -0400 Subject: [PATCH] Update oslo-incubator cliutils Changes - * cliutils: Python 3 support * Fix warnings in doc build for apiclient * Fix i18n support for apiclient Change-Id: I824a0369e702078c73253eb4cc126b26f6c54ca6 --- saharaclient/openstack/common/apiclient/auth.py | 4 ++-- saharaclient/openstack/common/apiclient/base.py | 15 +++++++++++---- .../openstack/common/apiclient/client.py | 16 +++++++++++----- saharaclient/openstack/common/cliutils.py | 7 +++++-- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/saharaclient/openstack/common/apiclient/auth.py b/saharaclient/openstack/common/apiclient/auth.py index a4184b7c..afe53935 100644 --- a/saharaclient/openstack/common/apiclient/auth.py +++ b/saharaclient/openstack/common/apiclient/auth.py @@ -213,8 +213,8 @@ class BaseAuthPlugin(object): :type service_type: string :param endpoint_type: Type of endpoint. Possible values: public or publicURL, - internal or internalURL, - admin or adminURL + internal or internalURL, + admin or adminURL :type endpoint_type: string :returns: tuple of token and endpoint strings :raises: EndpointException diff --git a/saharaclient/openstack/common/apiclient/base.py b/saharaclient/openstack/common/apiclient/base.py index 2301cf35..5b897ccf 100644 --- a/saharaclient/openstack/common/apiclient/base.py +++ b/saharaclient/openstack/common/apiclient/base.py @@ -30,6 +30,7 @@ import six from six.moves.urllib import parse from saharaclient.openstack.common.apiclient import exceptions +from saharaclient.openstack.common.gettextutils import _ from saharaclient.openstack.common import strutils @@ -74,8 +75,8 @@ class HookableMixin(object): :param cls: class that registers hooks :param hook_type: hook type, e.g., '__pre_parse_args__' - :param **args: args to be passed to every hook function - :param **kwargs: kwargs to be passed to every hook function + :param args: args to be passed to every hook function + :param kwargs: kwargs to be passed to every hook function """ hook_funcs = cls._hooks_map.get(hook_type) or [] for hook_func in hook_funcs: @@ -219,7 +220,10 @@ class ManagerWithFind(BaseManager): matches = self.findall(**kwargs) num_matches = len(matches) if num_matches == 0: - msg = "No %s matching %s." % (self.resource_class.__name__, kwargs) + msg = _("No %(name)s matching %(args)s.") % { + 'name': self.resource_class.__name__, + 'args': kwargs + } raise exceptions.NotFound(msg) elif num_matches > 1: raise exceptions.NoUniqueMatch() @@ -373,7 +377,10 @@ class CrudManager(BaseManager): num = len(rl) if num == 0: - msg = "No %s matching %s." % (self.resource_class.__name__, kwargs) + msg = _("No %(name)s matching %(args)s.") % { + 'name': self.resource_class.__name__, + 'args': kwargs + } raise exceptions.NotFound(404, msg) elif num > 1: raise exceptions.NoUniqueMatch diff --git a/saharaclient/openstack/common/apiclient/client.py b/saharaclient/openstack/common/apiclient/client.py index 787fde4c..6d618259 100644 --- a/saharaclient/openstack/common/apiclient/client.py +++ b/saharaclient/openstack/common/apiclient/client.py @@ -36,6 +36,7 @@ except ImportError: import requests from saharaclient.openstack.common.apiclient import exceptions +from saharaclient.openstack.common.gettextutils import _ from saharaclient.openstack.common import importutils @@ -46,6 +47,7 @@ class HTTPClient(object): """This client handles sending HTTP requests to OpenStack servers. Features: + - share authentication information between several clients to different services (e.g., for compute and image clients); - reissue authentication request for expired tokens; @@ -151,7 +153,7 @@ class HTTPClient(object): :param method: method of HTTP request :param url: URL of HTTP request :param kwargs: any other parameter that can be passed to -' requests.Session.request (such as `headers`) or `json` + requests.Session.request (such as `headers`) or `json` that will be encoded as JSON and used as `data` argument """ kwargs.setdefault("headers", kwargs.get("headers", {})) @@ -206,7 +208,7 @@ class HTTPClient(object): :param method: method of HTTP request :param url: URL of HTTP request :param kwargs: any other parameter that can be passed to -' `HTTPClient.request` + `HTTPClient.request` """ filter_args = { @@ -228,7 +230,7 @@ class HTTPClient(object): **filter_args) if not (token and endpoint): raise exceptions.AuthorizationFailure( - "Cannot find endpoint or token for request") + _("Cannot find endpoint or token for request")) old_token_endpoint = (token, endpoint) kwargs.setdefault("headers", {})["X-Auth-Token"] = token @@ -351,8 +353,12 @@ class BaseClient(object): try: client_path = version_map[str(version)] except (KeyError, ValueError): - msg = "Invalid %s client version '%s'. must be one of: %s" % ( - (api_name, version, ', '.join(version_map.keys()))) + msg = _("Invalid %(api_name)s client version '%(version)s'. " + "Must be one of: %(version_map)s") % { + 'api_name': api_name, + 'version': version, + 'version_map': ', '.join(version_map.keys()) + } raise exceptions.UnsupportedVersion(msg) return importutils.import_class(client_path) diff --git a/saharaclient/openstack/common/cliutils.py b/saharaclient/openstack/common/cliutils.py index 736a9e62..657d3802 100644 --- a/saharaclient/openstack/common/cliutils.py +++ b/saharaclient/openstack/common/cliutils.py @@ -56,7 +56,7 @@ def validate_args(fn, *args, **kwargs): required_args = argspec.args[:len(argspec.args) - num_defaults] def isbound(method): - return getattr(method, 'im_self', None) is not None + return getattr(method, '__self__', None) is not None if isbound(fn): required_args.pop(0) @@ -235,7 +235,10 @@ def find_resource(manager, name_or_id, **find_args): # now try to get entity as uuid try: - tmp_id = strutils.safe_encode(name_or_id) + if six.PY2: + tmp_id = strutils.safe_encode(name_or_id) + else: + tmp_id = strutils.safe_decode(name_or_id) if uuidutils.is_uuid_like(tmp_id): return manager.get(tmp_id)