Browse Source

Move old oslo-incubator code out of openstack/common

As part of the first community-wide goal, teams were asked to
remove the openstack/common package of their projects if one
existed. This was a byproduct of the old oslo-incubator form
of syncing common functionality.

Package openstack/common/apiclient is moved to glanceclient/v1
package as it is used by v1 api only.

NOTE:
Removed glanceclient/common/base.py as it is deprecated and not
used anywhere.

Closes-Bug: #1639487
Change-Id: Ib3ac09743ce761ab0186e99e1c9de02517f89510
tags/2.6.0
Abhishek Kekane 2 years ago
parent
commit
c2898998a7

+ 0
- 1
.coveragerc View File

@@ -1,7 +1,6 @@
1 1
 [run]
2 2
 branch = True
3 3
 source = glanceclient
4
-omit = glanceclient/openstack/*
5 4
 
6 5
 [report]
7 6
 ignore_errors = True

+ 0
- 35
glanceclient/common/base.py View File

@@ -1,35 +0,0 @@
1
-# Copyright 2012 OpenStack Foundation
2
-# All Rights Reserved.
3
-#
4
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
-#    not use this file except in compliance with the License. You may obtain
6
-#    a copy of the License at
7
-#
8
-#         http://www.apache.org/licenses/LICENSE-2.0
9
-#
10
-#    Unless required by applicable law or agreed to in writing, software
11
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
-#    License for the specific language governing permissions and limitations
14
-#    under the License.
15
-
16
-"""
17
-Base utilities to build API operation managers and objects on top of.
18
-
19
-DEPRECATED post v.0.12.0. Use 'glanceclient.openstack.common.apiclient.base'
20
-instead of this module."
21
-"""
22
-
23
-import warnings
24
-
25
-from glanceclient.openstack.common.apiclient import base
26
-
27
-
28
-warnings.warn("The 'glanceclient.common.base' module is deprecated post "
29
-              "v.0.12.0. Use 'glanceclient.openstack.common.apiclient.base' "
30
-              "instead of this one.", DeprecationWarning)
31
-
32
-
33
-getid = base.getid
34
-Manager = base.ManagerWithFind
35
-Resource = base.Resource

+ 0
- 0
glanceclient/openstack/common/__init__.py View File


+ 0
- 45
glanceclient/openstack/common/_i18n.py View File

@@ -1,45 +0,0 @@
1
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
2
-#    not use this file except in compliance with the License. You may obtain
3
-#    a copy of the License at
4
-#
5
-#         http://www.apache.org/licenses/LICENSE-2.0
6
-#
7
-#    Unless required by applicable law or agreed to in writing, software
8
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
-#    License for the specific language governing permissions and limitations
11
-#    under the License.
12
-
13
-"""oslo.i18n integration module.
14
-
15
-See http://docs.openstack.org/developer/oslo.i18n/usage.html
16
-
17
-"""
18
-
19
-try:
20
-    import oslo_i18n
21
-
22
-    # NOTE(dhellmann): This reference to o-s-l-o will be replaced by the
23
-    # application name when this module is synced into the separate
24
-    # repository. It is OK to have more than one translation function
25
-    # using the same domain, since there will still only be one message
26
-    # catalog.
27
-    _translators = oslo_i18n.TranslatorFactory(domain='glanceclient')
28
-
29
-    # The primary translation function using the well-known name "_"
30
-    _ = _translators.primary
31
-
32
-    # Translators for log levels.
33
-    #
34
-    # The abbreviated names are meant to reflect the usual use of a short
35
-    # name like '_'. The "L" is for "log" and the other letter comes from
36
-    # the level.
37
-    _LI = _translators.log_info
38
-    _LW = _translators.log_warning
39
-    _LE = _translators.log_error
40
-    _LC = _translators.log_critical
41
-except ImportError:
42
-    # NOTE(dims): Support for cases where a project wants to use
43
-    # code from oslo-incubator, but is not ready to be internationalized
44
-    # (like tempest)
45
-    _ = _LI = _LW = _LE = _LC = lambda x: x

+ 0
- 0
glanceclient/openstack/common/apiclient/__init__.py View File


+ 0
- 234
glanceclient/openstack/common/apiclient/auth.py View File

@@ -1,234 +0,0 @@
1
-# Copyright 2013 OpenStack Foundation
2
-# Copyright 2013 Spanish National Research Council.
3
-# All Rights Reserved.
4
-#
5
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
-#    not use this file except in compliance with the License. You may obtain
7
-#    a copy of the License at
8
-#
9
-#         http://www.apache.org/licenses/LICENSE-2.0
10
-#
11
-#    Unless required by applicable law or agreed to in writing, software
12
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
-#    License for the specific language governing permissions and limitations
15
-#    under the License.
16
-
17
-# E0202: An attribute inherited from %s hide this method
18
-# pylint: disable=E0202
19
-
20
-########################################################################
21
-#
22
-# THIS MODULE IS DEPRECATED
23
-#
24
-# Please refer to
25
-# https://etherpad.openstack.org/p/kilo-glanceclient-library-proposals for
26
-# the discussion leading to this deprecation.
27
-#
28
-# We recommend checking out the python-openstacksdk project
29
-# (https://launchpad.net/python-openstacksdk) instead.
30
-#
31
-########################################################################
32
-
33
-import abc
34
-import argparse
35
-import os
36
-
37
-import six
38
-from stevedore import extension
39
-
40
-from glanceclient.openstack.common.apiclient import exceptions
41
-
42
-
43
-_discovered_plugins = {}
44
-
45
-
46
-def discover_auth_systems():
47
-    """Discover the available auth-systems.
48
-
49
-    This won't take into account the old style auth-systems.
50
-    """
51
-    global _discovered_plugins
52
-    _discovered_plugins = {}
53
-
54
-    def add_plugin(ext):
55
-        _discovered_plugins[ext.name] = ext.plugin
56
-
57
-    ep_namespace = "glanceclient.openstack.common.apiclient.auth"
58
-    mgr = extension.ExtensionManager(ep_namespace)
59
-    mgr.map(add_plugin)
60
-
61
-
62
-def load_auth_system_opts(parser):
63
-    """Load options needed by the available auth-systems into a parser.
64
-
65
-    This function will try to populate the parser with options from the
66
-    available plugins.
67
-    """
68
-    group = parser.add_argument_group("Common auth options")
69
-    BaseAuthPlugin.add_common_opts(group)
70
-    for name, auth_plugin in six.iteritems(_discovered_plugins):
71
-        group = parser.add_argument_group(
72
-            "Auth-system '%s' options" % name,
73
-            conflict_handler="resolve")
74
-        auth_plugin.add_opts(group)
75
-
76
-
77
-def load_plugin(auth_system):
78
-    try:
79
-        plugin_class = _discovered_plugins[auth_system]
80
-    except KeyError:
81
-        raise exceptions.AuthSystemNotFound(auth_system)
82
-    return plugin_class(auth_system=auth_system)
83
-
84
-
85
-def load_plugin_from_args(args):
86
-    """Load required plugin and populate it with options.
87
-
88
-    Try to guess auth system if it is not specified. Systems are tried in
89
-    alphabetical order.
90
-
91
-    :type args: argparse.Namespace
92
-    :raises: AuthPluginOptionsMissing
93
-    """
94
-    auth_system = args.os_auth_system
95
-    if auth_system:
96
-        plugin = load_plugin(auth_system)
97
-        plugin.parse_opts(args)
98
-        plugin.sufficient_options()
99
-        return plugin
100
-
101
-    for plugin_auth_system in sorted(six.iterkeys(_discovered_plugins)):
102
-        plugin_class = _discovered_plugins[plugin_auth_system]
103
-        plugin = plugin_class()
104
-        plugin.parse_opts(args)
105
-        try:
106
-            plugin.sufficient_options()
107
-        except exceptions.AuthPluginOptionsMissing:
108
-            continue
109
-        return plugin
110
-    raise exceptions.AuthPluginOptionsMissing(["auth_system"])
111
-
112
-
113
-@six.add_metaclass(abc.ABCMeta)
114
-class BaseAuthPlugin(object):
115
-    """Base class for authentication plugins.
116
-
117
-    An authentication plugin needs to override at least the authenticate
118
-    method to be a valid plugin.
119
-    """
120
-
121
-    auth_system = None
122
-    opt_names = []
123
-    common_opt_names = [
124
-        "auth_system",
125
-        "username",
126
-        "password",
127
-        "tenant_name",
128
-        "token",
129
-        "auth_url",
130
-    ]
131
-
132
-    def __init__(self, auth_system=None, **kwargs):
133
-        self.auth_system = auth_system or self.auth_system
134
-        self.opts = dict((name, kwargs.get(name))
135
-                         for name in self.opt_names)
136
-
137
-    @staticmethod
138
-    def _parser_add_opt(parser, opt):
139
-        """Add an option to parser in two variants.
140
-
141
-        :param opt: option name (with underscores)
142
-        """
143
-        dashed_opt = opt.replace("_", "-")
144
-        env_var = "OS_%s" % opt.upper()
145
-        arg_default = os.environ.get(env_var, "")
146
-        arg_help = "Defaults to env[%s]." % env_var
147
-        parser.add_argument(
148
-            "--os-%s" % dashed_opt,
149
-            metavar="<%s>" % dashed_opt,
150
-            default=arg_default,
151
-            help=arg_help)
152
-        parser.add_argument(
153
-            "--os_%s" % opt,
154
-            metavar="<%s>" % dashed_opt,
155
-            help=argparse.SUPPRESS)
156
-
157
-    @classmethod
158
-    def add_opts(cls, parser):
159
-        """Populate the parser with the options for this plugin.
160
-        """
161
-        for opt in cls.opt_names:
162
-            # use `BaseAuthPlugin.common_opt_names` since it is never
163
-            # changed in child classes
164
-            if opt not in BaseAuthPlugin.common_opt_names:
165
-                cls._parser_add_opt(parser, opt)
166
-
167
-    @classmethod
168
-    def add_common_opts(cls, parser):
169
-        """Add options that are common for several plugins.
170
-        """
171
-        for opt in cls.common_opt_names:
172
-            cls._parser_add_opt(parser, opt)
173
-
174
-    @staticmethod
175
-    def get_opt(opt_name, args):
176
-        """Return option name and value.
177
-
178
-        :param opt_name: name of the option, e.g., "username"
179
-        :param args: parsed arguments
180
-        """
181
-        return (opt_name, getattr(args, "os_%s" % opt_name, None))
182
-
183
-    def parse_opts(self, args):
184
-        """Parse the actual auth-system options if any.
185
-
186
-        This method is expected to populate the attribute `self.opts` with a
187
-        dict containing the options and values needed to make authentication.
188
-        """
189
-        self.opts.update(dict(self.get_opt(opt_name, args)
190
-                              for opt_name in self.opt_names))
191
-
192
-    def authenticate(self, http_client):
193
-        """Authenticate using plugin defined method.
194
-
195
-        The method usually analyses `self.opts` and performs
196
-        a request to authentication server.
197
-
198
-        :param http_client: client object that needs authentication
199
-        :type http_client: HTTPClient
200
-        :raises: AuthorizationFailure
201
-        """
202
-        self.sufficient_options()
203
-        self._do_authenticate(http_client)
204
-
205
-    @abc.abstractmethod
206
-    def _do_authenticate(self, http_client):
207
-        """Protected method for authentication.
208
-        """
209
-
210
-    def sufficient_options(self):
211
-        """Check if all required options are present.
212
-
213
-        :raises: AuthPluginOptionsMissing
214
-        """
215
-        missing = [opt
216
-                   for opt in self.opt_names
217
-                   if not self.opts.get(opt)]
218
-        if missing:
219
-            raise exceptions.AuthPluginOptionsMissing(missing)
220
-
221
-    @abc.abstractmethod
222
-    def token_and_endpoint(self, endpoint_type, service_type):
223
-        """Return token and endpoint.
224
-
225
-        :param service_type: Service type of the endpoint
226
-        :type service_type: string
227
-        :param endpoint_type: Type of endpoint.
228
-                              Possible values: public or publicURL,
229
-                              internal or internalURL,
230
-                              admin or adminURL
231
-        :type endpoint_type: string
232
-        :returns: tuple of token and endpoint strings
233
-        :raises: EndpointException
234
-        """

+ 1
- 1
glanceclient/tests/unit/test_base.py View File

@@ -16,7 +16,7 @@
16 16
 
17 17
 import testtools
18 18
 
19
-from glanceclient.openstack.common.apiclient import base
19
+from glanceclient.v1.apiclient import base
20 20
 
21 21
 
22 22
 class TestBase(testtools.TestCase):

glanceclient/openstack/__init__.py → glanceclient/v1/apiclient/__init__.py View File


glanceclient/openstack/common/apiclient/base.py → glanceclient/v1/apiclient/base.py View File

@@ -45,7 +45,7 @@ import six
45 45
 from six.moves.urllib import parse
46 46
 
47 47
 from glanceclient._i18n import _
48
-from glanceclient.openstack.common.apiclient import exceptions
48
+from glanceclient.v1.apiclient import exceptions
49 49
 
50 50
 
51 51
 def getid(obj):

glanceclient/openstack/common/apiclient/exceptions.py → glanceclient/v1/apiclient/exceptions.py View File


glanceclient/openstack/common/apiclient/utils.py → glanceclient/v1/apiclient/utils.py View File

@@ -29,7 +29,7 @@ from oslo_utils import uuidutils
29 29
 import six
30 30
 
31 31
 from glanceclient._i18n import _
32
-from glanceclient.openstack.common.apiclient import exceptions
32
+from glanceclient.v1.apiclient import exceptions
33 33
 
34 34
 
35 35
 def find_resource(manager, name_or_id, **find_args):
@@ -84,17 +84,15 @@ def find_resource(manager, name_or_id, **find_args):
84 84
             return manager.find(**kwargs)
85 85
         except exceptions.NotFound:
86 86
             msg = _("No %(name)s with a name or "
87
-                    "ID of '%(name_or_id)s' exists.") % \
88
-                {
89
-                    "name": manager.resource_class.__name__.lower(),
90
-                    "name_or_id": name_or_id
91
-                }
92
-            raise exceptions.CommandError(msg)
93
-    except exceptions.NoUniqueMatch:
94
-        msg = _("Multiple %(name)s matches found for "
95
-                "'%(name_or_id)s', use an ID to be more specific.") % \
96
-            {
87
+                    "ID of '%(name_or_id)s' exists.") % {
97 88
                 "name": manager.resource_class.__name__.lower(),
98 89
                 "name_or_id": name_or_id
99 90
             }
91
+            raise exceptions.CommandError(msg)
92
+    except exceptions.NoUniqueMatch:
93
+        msg = _("Multiple %(name)s matches found for "
94
+                "'%(name_or_id)s', use an ID to be more specific.") % {
95
+            "name": manager.resource_class.__name__.lower(),
96
+            "name_or_id": name_or_id
97
+        }
100 98
         raise exceptions.CommandError(msg)

+ 1
- 1
glanceclient/v1/image_members.py View File

@@ -13,7 +13,7 @@
13 13
 #    License for the specific language governing permissions and limitations
14 14
 #    under the License.
15 15
 
16
-from glanceclient.openstack.common.apiclient import base
16
+from glanceclient.v1.apiclient import base
17 17
 
18 18
 
19 19
 class ImageMember(base.Resource):

+ 1
- 1
glanceclient/v1/images.py View File

@@ -21,7 +21,7 @@ import six
21 21
 import six.moves.urllib.parse as urlparse
22 22
 
23 23
 from glanceclient.common import utils
24
-from glanceclient.openstack.common.apiclient import base
24
+from glanceclient.v1.apiclient import base
25 25
 
26 26
 UPDATE_PARAMS = ('name', 'disk_format', 'container_format', 'min_disk',
27 27
                  'min_ram', 'owner', 'size', 'is_public', 'protected',

+ 1
- 1
glanceclient/v1/versions.py View File

@@ -14,7 +14,7 @@
14 14
 #    License for the specific language governing permissions and limitations
15 15
 #    under the License.
16 16
 
17
-from glanceclient.openstack.common.apiclient import base
17
+from glanceclient.v1.apiclient import base
18 18
 
19 19
 
20 20
 class VersionManager(base.ManagerWithFind):

+ 1
- 1
tox.ini View File

@@ -44,7 +44,7 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen
44 44
 [flake8]
45 45
 ignore = F403,F812,F821
46 46
 show-source = True
47
-exclude = .venv*,.tox,dist,*egg,build,.git,doc,*openstack/common*,*lib/python*,.update-venv
47
+exclude = .venv*,.tox,dist,*egg,build,.git,doc,*lib/python*,.update-venv
48 48
 
49 49
 [hacking]
50 50
 import_exceptions = six.moves,glanceclient._i18n

Loading…
Cancel
Save