2013-08-27 16:57:30 -05:00
|
|
|
# Copyright 2012-2013 OpenStack Foundation
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# 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
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# 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.
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
|
|
|
|
2013-01-31 13:31:41 -06:00
|
|
|
"""Manage access to the clients, including authenticating when needed."""
|
2012-05-02 17:02:08 -04:00
|
|
|
|
|
|
|
import logging
|
2013-11-20 18:02:09 -06:00
|
|
|
import pkg_resources
|
|
|
|
import sys
|
2012-05-02 17:02:08 -04:00
|
|
|
|
2016-05-13 16:53:44 -05:00
|
|
|
from osc_lib import clientmanager
|
2012-05-02 17:02:08 -04:00
|
|
|
|
2013-01-31 13:31:41 -06:00
|
|
|
|
2012-05-02 17:02:08 -04:00
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
2014-10-13 11:13:48 -05:00
|
|
|
PLUGIN_MODULES = []
|
|
|
|
|
2015-05-11 16:48:21 -07:00
|
|
|
USER_AGENT = 'python-openstackclient'
|
|
|
|
|
2012-05-02 17:02:08 -04:00
|
|
|
|
2016-05-13 16:53:44 -05:00
|
|
|
class ClientManager(clientmanager.ClientManager):
|
|
|
|
"""Manages access to API clients, including authentication
|
2012-05-02 17:02:08 -04:00
|
|
|
|
2016-05-13 16:53:44 -05:00
|
|
|
Wrap osc_lib's ClientManager to maintain compatibility for the existing
|
|
|
|
plugin V2 interface. Some currently private attributes become public
|
|
|
|
in osc-lib so we need to maintain a transition period.
|
|
|
|
"""
|
2015-07-22 10:51:07 -05:00
|
|
|
|
|
|
|
# A simple incrementing version for the plugin to know what is available
|
|
|
|
PLUGIN_INTERFACE_VERSION = "2"
|
|
|
|
|
2014-10-20 18:53:10 -05:00
|
|
|
def __init__(
|
|
|
|
self,
|
2015-03-02 17:05:35 -06:00
|
|
|
cli_options=None,
|
2014-10-20 18:53:10 -05:00
|
|
|
api_version=None,
|
|
|
|
pw_func=None,
|
|
|
|
):
|
2016-05-13 16:53:44 -05:00
|
|
|
super(ClientManager, self).__init__(
|
|
|
|
cli_options=cli_options,
|
|
|
|
api_version=api_version,
|
|
|
|
pw_func=pw_func,
|
2014-10-22 11:12:47 -05:00
|
|
|
)
|
|
|
|
|
2016-05-13 16:53:44 -05:00
|
|
|
# TODO(dtroyer): For compatibility; mark this for removal when plugin
|
|
|
|
# interface v2 is removed
|
|
|
|
self._region_name = self.region_name
|
|
|
|
self._interface = self.interface
|
|
|
|
self._cacert = self.cacert
|
|
|
|
self._insecure = not self.verify
|
2014-10-20 18:53:10 -05:00
|
|
|
|
2015-12-02 14:43:01 -06:00
|
|
|
def is_network_endpoint_enabled(self):
|
|
|
|
"""Check if the network endpoint is enabled"""
|
2013-11-20 18:02:09 -06:00
|
|
|
|
2016-05-13 16:53:44 -05:00
|
|
|
# NOTE(dtroyer): is_service_available() can also return None if
|
|
|
|
# there is no Service Catalog, callers here are
|
|
|
|
# not expecting that so fold None into True to
|
|
|
|
# use Network API by default
|
|
|
|
return self.is_service_available('network') is not False
|
2015-07-19 12:15:04 -06:00
|
|
|
|
2013-11-20 18:02:09 -06:00
|
|
|
|
2014-10-13 11:13:48 -05:00
|
|
|
# Plugin Support
|
|
|
|
|
|
|
|
def get_plugin_modules(group):
|
|
|
|
"""Find plugin entry points"""
|
2013-11-20 18:02:09 -06:00
|
|
|
mod_list = []
|
|
|
|
for ep in pkg_resources.iter_entry_points(group):
|
2014-10-13 11:13:48 -05:00
|
|
|
LOG.debug('Found plugin %r', ep.name)
|
2013-11-20 18:02:09 -06:00
|
|
|
|
|
|
|
__import__(ep.module_name)
|
|
|
|
module = sys.modules[ep.module_name]
|
|
|
|
mod_list.append(module)
|
|
|
|
init_func = getattr(module, 'Initialize', None)
|
|
|
|
if init_func:
|
|
|
|
init_func('x')
|
|
|
|
|
2014-10-13 11:13:48 -05:00
|
|
|
# Add the plugin to the ClientManager
|
2013-11-20 18:02:09 -06:00
|
|
|
setattr(
|
|
|
|
ClientManager,
|
2014-05-08 22:42:21 -05:00
|
|
|
module.API_NAME,
|
2016-05-13 16:53:44 -05:00
|
|
|
clientmanager.ClientCache(
|
2013-11-20 18:02:09 -06:00
|
|
|
getattr(sys.modules[ep.module_name], 'make_client', None)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
return mod_list
|
2014-10-13 11:13:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
def build_plugin_option_parser(parser):
|
|
|
|
"""Add plugin options to the parser"""
|
|
|
|
|
|
|
|
# Loop through extensions to get parser additions
|
|
|
|
for mod in PLUGIN_MODULES:
|
|
|
|
parser = mod.build_option_parser(parser)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
# Get list of base plugin modules
|
|
|
|
PLUGIN_MODULES = get_plugin_modules(
|
|
|
|
'openstack.cli.base',
|
|
|
|
)
|
|
|
|
# Append list of external plugin modules
|
|
|
|
PLUGIN_MODULES.extend(get_plugin_modules(
|
|
|
|
'openstack.cli.extension',
|
|
|
|
))
|