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. The package, apiclient, was moved to a top level location and cliutils was moved to the common module. There are no oslo specific libraries, the recommended solution is to move it in tree and maintain it there. Change-Id: Iee52004bd33c19d63133577ff466164b85fd6ca6
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[run]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
source = cinderclient
|
source = cinderclient
|
||||||
omit = cinderclient/openstack/*,cinderclient/tests/*
|
omit = cinderclient/tests/*
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
ignore_errors = True
|
ignore_errors = True
|
||||||
|
@@ -30,7 +30,7 @@ from requests import Response
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse
|
from six.moves.urllib import parse
|
||||||
|
|
||||||
from cinderclient.openstack.common.apiclient import exceptions
|
from cinderclient.apiclient import exceptions
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
|
|
||||||
|
|
@@ -36,7 +36,7 @@ except ImportError:
|
|||||||
import hashlib
|
import hashlib
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from cinderclient.openstack.common.apiclient import exceptions
|
from cinderclient.apiclient import exceptions
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ class HTTPClient(object):
|
|||||||
into terminal and send the same request with curl.
|
into terminal and send the same request with curl.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user_agent = "cinderclient.openstack.common.apiclient"
|
user_agent = "cinderclient.apiclient"
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
auth_plugin,
|
auth_plugin,
|
@@ -30,7 +30,7 @@ import requests
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse
|
from six.moves.urllib import parse
|
||||||
|
|
||||||
from cinderclient.openstack.common.apiclient import client
|
from cinderclient.apiclient import client
|
||||||
|
|
||||||
|
|
||||||
def assert_has_keys(dct, required=None, optional=None):
|
def assert_has_keys(dct, required=None, optional=None):
|
@@ -26,8 +26,8 @@ import os
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse
|
from six.moves.urllib import parse
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import exceptions
|
from cinderclient import exceptions
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
from cinderclient import utils
|
from cinderclient import utils
|
||||||
|
|
||||||
|
|
||||||
|
@@ -13,8 +13,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
from cinderclient import utils
|
from cinderclient import utils
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,221 +0,0 @@
|
|||||||
# Copyright 2013 OpenStack Foundation
|
|
||||||
# Copyright 2013 Spanish National Research Council.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
# E0202: An attribute inherited from %s hide this method
|
|
||||||
# pylint: disable=E0202
|
|
||||||
|
|
||||||
import abc
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
|
|
||||||
import six
|
|
||||||
from stevedore import extension
|
|
||||||
|
|
||||||
from cinderclient.openstack.common.apiclient import exceptions
|
|
||||||
|
|
||||||
|
|
||||||
_discovered_plugins = {}
|
|
||||||
|
|
||||||
|
|
||||||
def discover_auth_systems():
|
|
||||||
"""Discover the available auth-systems.
|
|
||||||
|
|
||||||
This won't take into account the old style auth-systems.
|
|
||||||
"""
|
|
||||||
global _discovered_plugins
|
|
||||||
_discovered_plugins = {}
|
|
||||||
|
|
||||||
def add_plugin(ext):
|
|
||||||
_discovered_plugins[ext.name] = ext.plugin
|
|
||||||
|
|
||||||
ep_namespace = "cinderclient.openstack.common.apiclient.auth"
|
|
||||||
mgr = extension.ExtensionManager(ep_namespace)
|
|
||||||
mgr.map(add_plugin)
|
|
||||||
|
|
||||||
|
|
||||||
def load_auth_system_opts(parser):
|
|
||||||
"""Load options needed by the available auth-systems into a parser.
|
|
||||||
|
|
||||||
This function will try to populate the parser with options from the
|
|
||||||
available plugins.
|
|
||||||
"""
|
|
||||||
group = parser.add_argument_group("Common auth options")
|
|
||||||
BaseAuthPlugin.add_common_opts(group)
|
|
||||||
for name, auth_plugin in six.iteritems(_discovered_plugins):
|
|
||||||
group = parser.add_argument_group(
|
|
||||||
"Auth-system '%s' options" % name,
|
|
||||||
conflict_handler="resolve")
|
|
||||||
auth_plugin.add_opts(group)
|
|
||||||
|
|
||||||
|
|
||||||
def load_plugin(auth_system):
|
|
||||||
try:
|
|
||||||
plugin_class = _discovered_plugins[auth_system]
|
|
||||||
except KeyError:
|
|
||||||
raise exceptions.AuthSystemNotFound(auth_system)
|
|
||||||
return plugin_class(auth_system=auth_system)
|
|
||||||
|
|
||||||
|
|
||||||
def load_plugin_from_args(args):
|
|
||||||
"""Load required plugin and populate it with options.
|
|
||||||
|
|
||||||
Try to guess auth system if it is not specified. Systems are tried in
|
|
||||||
alphabetical order.
|
|
||||||
|
|
||||||
:type args: argparse.Namespace
|
|
||||||
:raises: AuthorizationFailure
|
|
||||||
"""
|
|
||||||
auth_system = args.os_auth_system
|
|
||||||
if auth_system:
|
|
||||||
plugin = load_plugin(auth_system)
|
|
||||||
plugin.parse_opts(args)
|
|
||||||
plugin.sufficient_options()
|
|
||||||
return plugin
|
|
||||||
|
|
||||||
for plugin_auth_system in sorted(six.iterkeys(_discovered_plugins)):
|
|
||||||
plugin_class = _discovered_plugins[plugin_auth_system]
|
|
||||||
plugin = plugin_class()
|
|
||||||
plugin.parse_opts(args)
|
|
||||||
try:
|
|
||||||
plugin.sufficient_options()
|
|
||||||
except exceptions.AuthPluginOptionsMissing:
|
|
||||||
continue
|
|
||||||
return plugin
|
|
||||||
raise exceptions.AuthPluginOptionsMissing(["auth_system"])
|
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
|
||||||
class BaseAuthPlugin(object):
|
|
||||||
"""Base class for authentication plugins.
|
|
||||||
|
|
||||||
An authentication plugin needs to override at least the authenticate
|
|
||||||
method to be a valid plugin.
|
|
||||||
"""
|
|
||||||
|
|
||||||
auth_system = None
|
|
||||||
opt_names = []
|
|
||||||
common_opt_names = [
|
|
||||||
"auth_system",
|
|
||||||
"username",
|
|
||||||
"password",
|
|
||||||
"tenant_name",
|
|
||||||
"token",
|
|
||||||
"auth_url",
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self, auth_system=None, **kwargs):
|
|
||||||
self.auth_system = auth_system or self.auth_system
|
|
||||||
self.opts = dict((name, kwargs.get(name))
|
|
||||||
for name in self.opt_names)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _parser_add_opt(parser, opt):
|
|
||||||
"""Add an option to parser in two variants.
|
|
||||||
|
|
||||||
:param opt: option name (with underscores)
|
|
||||||
"""
|
|
||||||
dashed_opt = opt.replace("_", "-")
|
|
||||||
env_var = "OS_%s" % opt.upper()
|
|
||||||
arg_default = os.environ.get(env_var, "")
|
|
||||||
arg_help = "Defaults to env[%s]." % env_var
|
|
||||||
parser.add_argument(
|
|
||||||
"--os-%s" % dashed_opt,
|
|
||||||
metavar="<%s>" % dashed_opt,
|
|
||||||
default=arg_default,
|
|
||||||
help=arg_help)
|
|
||||||
parser.add_argument(
|
|
||||||
"--os_%s" % opt,
|
|
||||||
metavar="<%s>" % dashed_opt,
|
|
||||||
help=argparse.SUPPRESS)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def add_opts(cls, parser):
|
|
||||||
"""Populate the parser with the options for this plugin.
|
|
||||||
"""
|
|
||||||
for opt in cls.opt_names:
|
|
||||||
# use `BaseAuthPlugin.common_opt_names` since it is never
|
|
||||||
# changed in child classes
|
|
||||||
if opt not in BaseAuthPlugin.common_opt_names:
|
|
||||||
cls._parser_add_opt(parser, opt)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def add_common_opts(cls, parser):
|
|
||||||
"""Add options that are common for several plugins.
|
|
||||||
"""
|
|
||||||
for opt in cls.common_opt_names:
|
|
||||||
cls._parser_add_opt(parser, opt)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_opt(opt_name, args):
|
|
||||||
"""Return option name and value.
|
|
||||||
|
|
||||||
:param opt_name: name of the option, e.g., "username"
|
|
||||||
:param args: parsed arguments
|
|
||||||
"""
|
|
||||||
return (opt_name, getattr(args, "os_%s" % opt_name, None))
|
|
||||||
|
|
||||||
def parse_opts(self, args):
|
|
||||||
"""Parse the actual auth-system options if any.
|
|
||||||
|
|
||||||
This method is expected to populate the attribute `self.opts` with a
|
|
||||||
dict containing the options and values needed to make authentication.
|
|
||||||
"""
|
|
||||||
self.opts.update(dict(self.get_opt(opt_name, args)
|
|
||||||
for opt_name in self.opt_names))
|
|
||||||
|
|
||||||
def authenticate(self, http_client):
|
|
||||||
"""Authenticate using plugin defined method.
|
|
||||||
|
|
||||||
The method usually analyses `self.opts` and performs
|
|
||||||
a request to authentication server.
|
|
||||||
|
|
||||||
:param http_client: client object that needs authentication
|
|
||||||
:type http_client: HTTPClient
|
|
||||||
:raises: AuthorizationFailure
|
|
||||||
"""
|
|
||||||
self.sufficient_options()
|
|
||||||
self._do_authenticate(http_client)
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def _do_authenticate(self, http_client):
|
|
||||||
"""Protected method for authentication.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def sufficient_options(self):
|
|
||||||
"""Check if all required options are present.
|
|
||||||
|
|
||||||
:raises: AuthPluginOptionsMissing
|
|
||||||
"""
|
|
||||||
missing = [opt
|
|
||||||
for opt in self.opt_names
|
|
||||||
if not self.opts.get(opt)]
|
|
||||||
if missing:
|
|
||||||
raise exceptions.AuthPluginOptionsMissing(missing)
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def token_and_endpoint(self, endpoint_type, service_type):
|
|
||||||
"""Return token and endpoint.
|
|
||||||
|
|
||||||
:param service_type: Service type of the endpoint
|
|
||||||
:type service_type: string
|
|
||||||
:param endpoint_type: Type of endpoint.
|
|
||||||
Possible values: public or publicURL,
|
|
||||||
internal or internalURL,
|
|
||||||
admin or adminURL
|
|
||||||
:type endpoint_type: string
|
|
||||||
:returns: tuple of token and endpoint strings
|
|
||||||
:raises: EndpointException
|
|
||||||
"""
|
|
@@ -14,10 +14,10 @@
|
|||||||
from requests import Response
|
from requests import Response
|
||||||
|
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.v3 import client
|
from cinderclient.v3 import client
|
||||||
from cinderclient import exceptions
|
from cinderclient import exceptions
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
from cinderclient.v1 import volumes
|
from cinderclient.v1 import volumes
|
||||||
from cinderclient.tests.unit import utils
|
from cinderclient.tests.unit import utils
|
||||||
from cinderclient.tests.unit import test_utils
|
from cinderclient.tests.unit import test_utils
|
||||||
|
@@ -18,10 +18,10 @@ import mock
|
|||||||
from six import moves
|
from six import moves
|
||||||
|
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import exceptions
|
from cinderclient import exceptions
|
||||||
from cinderclient import utils
|
from cinderclient import utils
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
from cinderclient.tests.unit import utils as test_utils
|
from cinderclient.tests.unit import utils as test_utils
|
||||||
from cinderclient.tests.unit.v2 import fakes
|
from cinderclient.tests.unit.v2 import fakes
|
||||||
|
|
||||||
|
@@ -18,8 +18,8 @@
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib.parse import urlencode
|
from six.moves.urllib.parse import urlencode
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class Cgsnapshot(base.Resource):
|
class Cgsnapshot(base.Resource):
|
||||||
|
@@ -18,8 +18,8 @@
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib.parse import urlencode
|
from six.moves.urllib.parse import urlencode
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class Consistencygroup(base.Resource):
|
class Consistencygroup(base.Resource):
|
||||||
|
@@ -18,8 +18,8 @@
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib.parse import urlencode
|
from six.moves.urllib.parse import urlencode
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class GroupSnapshot(base.Resource):
|
class GroupSnapshot(base.Resource):
|
||||||
|
@@ -18,8 +18,8 @@
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib.parse import urlencode
|
from six.moves.urllib.parse import urlencode
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class Group(base.Resource):
|
class Group(base.Resource):
|
||||||
|
@@ -19,8 +19,8 @@
|
|||||||
QoS Specs interface.
|
QoS Specs interface.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class QoSSpecs(base.Resource):
|
class QoSSpecs(base.Resource):
|
||||||
|
@@ -17,8 +17,8 @@
|
|||||||
Volume Backups interface (v3 extension).
|
Volume Backups interface (v3 extension).
|
||||||
"""
|
"""
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeBackup(base.Resource):
|
class VolumeBackup(base.Resource):
|
||||||
|
@@ -18,8 +18,8 @@
|
|||||||
Volume Encryption Type interface
|
Volume Encryption Type interface
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeEncryptionType(base.Resource):
|
class VolumeEncryptionType(base.Resource):
|
||||||
|
@@ -16,8 +16,8 @@
|
|||||||
"""Volume snapshot interface (v3 extension)."""
|
"""Volume snapshot interface (v3 extension)."""
|
||||||
|
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class Snapshot(base.Resource):
|
class Snapshot(base.Resource):
|
||||||
|
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
"""Volume type access interface."""
|
"""Volume type access interface."""
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeTypeAccess(base.Resource):
|
class VolumeTypeAccess(base.Resource):
|
||||||
|
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
"""Volume Type interface."""
|
"""Volume Type interface."""
|
||||||
|
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeType(base.Resource):
|
class VolumeType(base.Resource):
|
||||||
|
@@ -16,8 +16,8 @@
|
|||||||
"""Volume interface (v3 extension)."""
|
"""Volume interface (v3 extension)."""
|
||||||
|
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
|
from cinderclient.apiclient import base as common_base
|
||||||
from cinderclient import base
|
from cinderclient import base
|
||||||
from cinderclient.openstack.common.apiclient import base as common_base
|
|
||||||
|
|
||||||
|
|
||||||
class Volume(base.Resource):
|
class Volume(base.Resource):
|
||||||
|
Reference in New Issue
Block a user