From 256e6302bda822cb0a17efe1b569b884bd0a7741 Mon Sep 17 00:00:00 2001 From: tengqm Date: Wed, 23 Sep 2015 10:44:16 -0400 Subject: [PATCH] Revise client constructor This patch revises the client.Client constructor so that other software can invoke senlinclient in the same way as they do with other client packages. Change-Id: I060e2bf70d51ec381934cfd487a1a6cb44f0edd2 Closes-Bug: #1498906 --- senlinclient/client.py | 4 ++-- senlinclient/shell.py | 7 ++----- senlinclient/v1/client.py | 10 +++++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/senlinclient/client.py b/senlinclient/client.py index ac6a6cb4..a0f584f5 100644 --- a/senlinclient/client.py +++ b/senlinclient/client.py @@ -13,7 +13,7 @@ from senlinclient.common import utils -def Client(api_ver, session, **kwargs): +def Client(api_ver, *args, **kwargs): '''Import versioned client module. :param api_ver: API version required. @@ -21,4 +21,4 @@ def Client(api_ver, session, **kwargs): ''' module = utils.import_versioned_module(api_ver, 'client') cls = getattr(module, 'Client') - return cls(session) + return cls(*args, **kwargs) diff --git a/senlinclient/shell.py b/senlinclient/shell.py index b618aa8c..78d43fd9 100644 --- a/senlinclient/shell.py +++ b/senlinclient/shell.py @@ -29,7 +29,6 @@ from senlinclient import cliargs from senlinclient import client as senlin_client from senlinclient.common import exc from senlinclient.common.i18n import _ -from senlinclient.common import sdk from senlinclient.common import utils osprofiler_profiler = importutils.try_import("osprofiler.profiler") @@ -234,10 +233,8 @@ class SenlinShell(object): 'token': args.token, 'trust_id': args.trust_id, } - conn = sdk.create_connection(args.user_preferences, - USER_AGENT, **kwargs) - - return senlin_client.Client('1', conn.session) + return senlin_client.Client('1', args.user_preferences, + USER_AGENT, **kwargs) def main(self, argv): # Parse args once to find version diff --git a/senlinclient/v1/client.py b/senlinclient/v1/client.py index 405ec696..af606c3b 100644 --- a/senlinclient/v1/client.py +++ b/senlinclient/v1/client.py @@ -16,10 +16,18 @@ from openstack.identity import identity_service from openstack import transport as trans from senlinclient.common import exc as client_exc +from senlinclient.common import sdk class Client(object): - def __init__(self, session): + + def __init__(self, preferences, user_agent, **kwargs): + if 'session' in kwargs: + session = kwargs['session'] + else: + conn = sdk.create_connection(preferences, user_agent, **kwargs) + session = conn.session + self.session = session self.auth = session.authenticator