From 63b8839741587ed43cbf30411e43c077ee80bcb9 Mon Sep 17 00:00:00 2001 From: tengqm Date: Wed, 30 Sep 2015 04:33:06 -0400 Subject: [PATCH] Fix client constructor for ease of use This patch optimizes the client constructor so that caller doesn't have to provide user_preferences or user_agent arguments. It would be a convenience for projects such as senlin-dashboard. Change-Id: I0e98fb055441a941ad7c9da6e36b4a388ae0a75a --- senlinclient/common/sdk.py | 2 +- senlinclient/shell.py | 5 +++-- senlinclient/v1/client.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/senlinclient/common/sdk.py b/senlinclient/common/sdk.py index 12e28124..e68db4c5 100644 --- a/senlinclient/common/sdk.py +++ b/senlinclient/common/sdk.py @@ -123,7 +123,7 @@ class Resource(base.Resource): return self -def create_connection(preferences, user_agent, **kwargs): +def create_connection(preferences=None, user_agent=None, **kwargs): try: conn = connection.Connection(profile=preferences, user_agent=user_agent, diff --git a/senlinclient/shell.py b/senlinclient/shell.py index 78d43fd9..e2fa630b 100644 --- a/senlinclient/shell.py +++ b/senlinclient/shell.py @@ -233,8 +233,9 @@ class SenlinShell(object): 'token': args.token, 'trust_id': args.trust_id, } - return senlin_client.Client('1', args.user_preferences, - USER_AGENT, **kwargs) + + 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 af606c3b..fa70ae1c 100644 --- a/senlinclient/v1/client.py +++ b/senlinclient/v1/client.py @@ -21,7 +21,7 @@ from senlinclient.common import sdk class Client(object): - def __init__(self, preferences, user_agent, **kwargs): + def __init__(self, preferences=None, user_agent=None, **kwargs): if 'session' in kwargs: session = kwargs['session'] else: