From 71ce1fbb4a46c2da102581c9e1d0384598199ba6 Mon Sep 17 00:00:00 2001 From: tpatil Date: Tue, 6 Nov 2018 16:14:51 +0900 Subject: [PATCH] Fix osc command issue If you have installed openstackclient and masakariclient on your machine, then none of the openstack commands work as it fails to load the masakari plugin. Added 'API_NAME' global constants which osc clientmanager expects during initialization of masakari plugin. Change-Id: Id33bd45ee1625a23ae43090a45d8b0f9ff2bf56a Closes-Bug: #1801689 --- masakariclient/plugin.py | 23 ++++++++++++++++++----- masakariclient/v1/client.py | 22 ++++++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/masakariclient/plugin.py b/masakariclient/plugin.py index 794ab47..6450f92 100644 --- a/masakariclient/plugin.py +++ b/masakariclient/plugin.py @@ -12,20 +12,33 @@ # See the License for the specific language governing permissions and # limitations under the License. -from openstack import connection +import logging + from osc_lib import utils +LOG = logging.getLogger(__name__) DEFAULT_HA_API_VERSION = '1' API_VERSION_OPTION = 'os_ha_api_version' +API_NAME = 'ha' +API_VERSIONS = { + '1': 'masakariclient.v1.client.Client', +} def make_client(instance): """Returns a instance_ha proxy""" - conn = connection.Connection(session=instance.session, - interface=instance.interface, - region_name=instance.region_name) - return conn.instance_ha + version = instance._api_version[API_NAME] + masakari_client = utils.get_client_class( + API_NAME, + version, + API_VERSIONS) + + LOG.debug('Instantiating masakari service client: %s', masakari_client) + client = masakari_client(session=instance.session, + interface=instance.interface, + region_name=instance.region_name) + return client.service def build_option_parser(parser): diff --git a/masakariclient/v1/client.py b/masakariclient/v1/client.py index 559893a..b34c35a 100644 --- a/masakariclient/v1/client.py +++ b/masakariclient/v1/client.py @@ -20,18 +20,20 @@ from openstack import connection class Client(object): def __init__(self, **kwargs): + session = kwargs.get('session') + if session is None: + auth = ks_password.Password( + auth_url=kwargs.get('auth_url'), + username=kwargs.get('username'), + password=kwargs.get('password'), + user_domain_id=kwargs.get('user_domain_id'), + project_name=kwargs.get('project_name'), + project_domain_id=kwargs.get('project_domain_id')) - auth = ks_password.Password( - auth_url=kwargs.get('auth_url'), - username=kwargs.get('username'), - password=kwargs.get('password'), - user_domain_id=kwargs.get('user_domain_id'), - project_name=kwargs.get('project_name'), - project_domain_id=kwargs.get('project_domain_id')) - session = ks_session.Session(auth=auth) + session = ks_session.Session(auth=auth) - self.con = connection.Connection( + con = connection.Connection( session=session, interface=kwargs.get('interface'), region_name=kwargs.get('region_name')) - self.service = self.con.instance_ha + self.service = con.instance_ha