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