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