Merge "Pass httpclient to managers"
This commit is contained in:
commit
5438b20c46
@ -65,8 +65,8 @@ def extract_json(response, response_key):
|
||||
class ResourceManager(object):
|
||||
resource_class = None
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
def __init__(self, http_client):
|
||||
self.http_client = http_client
|
||||
|
||||
def find(self, **kwargs):
|
||||
return [i for i in self.list() if _check_items(i, kwargs.items())]
|
||||
@ -89,7 +89,7 @@ class ResourceManager(object):
|
||||
if dump_json:
|
||||
data = json.dumps(data)
|
||||
|
||||
resp = self.client.http_client.post(url, data)
|
||||
resp = self.http_client.post(url, data)
|
||||
|
||||
if resp.status_code != 201:
|
||||
self._raise_api_exception(resp)
|
||||
@ -100,7 +100,7 @@ class ResourceManager(object):
|
||||
if dump_json:
|
||||
data = json.dumps(data)
|
||||
|
||||
resp = self.client.http_client.put(url, data)
|
||||
resp = self.http_client.put(url, data)
|
||||
|
||||
if resp.status_code != 200:
|
||||
self._raise_api_exception(resp)
|
||||
@ -108,7 +108,7 @@ class ResourceManager(object):
|
||||
return self.resource_class(self, extract_json(resp, response_key))
|
||||
|
||||
def _list(self, url, response_key=None):
|
||||
resp = self.client.http_client.get(url)
|
||||
resp = self.http_client.get(url)
|
||||
|
||||
if resp.status_code != 200:
|
||||
self._raise_api_exception(resp)
|
||||
@ -117,7 +117,7 @@ class ResourceManager(object):
|
||||
for resource_data in extract_json(resp, response_key)]
|
||||
|
||||
def _get(self, url, response_key=None):
|
||||
resp = self.client.http_client.get(url)
|
||||
resp = self.http_client.get(url)
|
||||
|
||||
if resp.status_code == 200:
|
||||
return self.resource_class(self, extract_json(resp, response_key))
|
||||
@ -125,7 +125,7 @@ class ResourceManager(object):
|
||||
self._raise_api_exception(resp)
|
||||
|
||||
def _delete(self, url):
|
||||
resp = self.client.http_client.delete(url)
|
||||
resp = self.http_client.delete(url)
|
||||
|
||||
if resp.status_code != 204:
|
||||
self._raise_api_exception(resp)
|
||||
|
@ -35,7 +35,7 @@ class ActionExecutionManager(base.ResourceManager):
|
||||
if params:
|
||||
data['params'] = json.dumps(params)
|
||||
|
||||
resp = self.client.http_client.post(
|
||||
resp = self.http_client.post(
|
||||
'/action_executions',
|
||||
json.dumps(data)
|
||||
)
|
||||
|
@ -34,7 +34,7 @@ class ActionManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.post(
|
||||
resp = self.http_client.post(
|
||||
'/actions?scope=%s' % scope,
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
@ -55,7 +55,7 @@ class ActionManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.put(
|
||||
resp = self.http_client.put(
|
||||
'%s?scope=%s' % (url_pre, scope),
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
@ -107,7 +107,7 @@ class ActionManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.post(
|
||||
resp = self.http_client.post(
|
||||
'/actions/validate',
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
|
@ -117,7 +117,7 @@ class Client(object):
|
||||
target_insecure
|
||||
)
|
||||
|
||||
self.http_client = httpclient.HTTPClient(
|
||||
http_client = httpclient.HTTPClient(
|
||||
mistral_url,
|
||||
auth_token,
|
||||
project_id,
|
||||
@ -130,13 +130,14 @@ class Client(object):
|
||||
)
|
||||
|
||||
# Create all resource managers.
|
||||
self.workbooks = workbooks.WorkbookManager(self)
|
||||
self.executions = executions.ExecutionManager(self)
|
||||
self.tasks = tasks.TaskManager(self)
|
||||
self.actions = actions.ActionManager(self)
|
||||
self.workflows = workflows.WorkflowManager(self)
|
||||
self.cron_triggers = cron_triggers.CronTriggerManager(self)
|
||||
self.environments = environments.EnvironmentManager(self)
|
||||
self.action_executions = action_executions.ActionExecutionManager(self)
|
||||
self.services = services.ServiceManager(self)
|
||||
self.members = members.MemberManager(self)
|
||||
self.workbooks = workbooks.WorkbookManager(http_client)
|
||||
self.executions = executions.ExecutionManager(http_client)
|
||||
self.tasks = tasks.TaskManager(http_client)
|
||||
self.actions = actions.ActionManager(http_client)
|
||||
self.workflows = workflows.WorkflowManager(http_client)
|
||||
self.cron_triggers = cron_triggers.CronTriggerManager(http_client)
|
||||
self.environments = environments.EnvironmentManager(http_client)
|
||||
self.action_executions = action_executions.ActionExecutionManager(
|
||||
http_client)
|
||||
self.services = services.ServiceManager(http_client)
|
||||
self.members = members.MemberManager(http_client)
|
||||
|
@ -40,7 +40,7 @@ class MemberManager(base.ResourceManager):
|
||||
def update(self, resource_id, resource_type, member_id='',
|
||||
status='accepted'):
|
||||
if not member_id:
|
||||
member_id = self.client.http_client.project_id
|
||||
member_id = self.http_client.project_id
|
||||
|
||||
url = '/%ss/%s/members/%s' % (resource_type, resource_id, member_id)
|
||||
|
||||
@ -58,7 +58,7 @@ class MemberManager(base.ResourceManager):
|
||||
)
|
||||
|
||||
if not member_id:
|
||||
member_id = self.client.http_client.project_id
|
||||
member_id = self.http_client.project_id
|
||||
|
||||
url = '/%ss/%s/members/%s' % (resource_type, resource_id, member_id)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class WorkbookManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.post(
|
||||
resp = self.http_client.post(
|
||||
'/workbooks',
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
@ -49,7 +49,7 @@ class WorkbookManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.put(
|
||||
resp = self.http_client.put(
|
||||
'/workbooks',
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
@ -80,7 +80,7 @@ class WorkbookManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.post(
|
||||
resp = self.http_client.post(
|
||||
'/workbooks/validate',
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
|
@ -36,7 +36,7 @@ class WorkflowManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.post(
|
||||
resp = self.http_client.post(
|
||||
'/workflows?scope=%s' % scope,
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
@ -57,7 +57,7 @@ class WorkflowManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.put(
|
||||
resp = self.http_client.put(
|
||||
'%s?scope=%s' % (url_pre, scope),
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
@ -112,7 +112,7 @@ class WorkflowManager(base.ResourceManager):
|
||||
# definition file
|
||||
definition = utils.get_contents_if_file(definition)
|
||||
|
||||
resp = self.client.http_client.post(
|
||||
resp = self.http_client.post(
|
||||
'/workflows/validate',
|
||||
definition,
|
||||
headers={'content-type': 'text/plain'}
|
||||
|
@ -54,7 +54,7 @@ class BaseClientTests(base.BaseTestCase):
|
||||
|
||||
self.assertEqual(
|
||||
'http://mistral_host:8989/v2',
|
||||
mistralclient.http_client.base_url
|
||||
mistralclient.actions.http_client.base_url
|
||||
)
|
||||
|
||||
@mock.patch('keystoneclient.v3.client.Client')
|
||||
@ -77,7 +77,7 @@ class BaseClientTests(base.BaseTestCase):
|
||||
|
||||
self.assertEqual(
|
||||
'http://mistral_host:8989/v2',
|
||||
mistralclient.http_client.base_url
|
||||
mistralclient.actions.http_client.base_url
|
||||
)
|
||||
|
||||
@mock.patch('keystoneclient.v3.client.Client')
|
||||
|
Loading…
Reference in New Issue
Block a user