Wrap mistralclient code in api.py

All mistralclient specific code should be wrapped in api.py,
see discusstion on:
https://review.openstack.org/#/c/198056/1/mistraldashboard/executions/views.py

Change-Id: Idcf94f523473bdb31c257ca2054942fe79ea54ba
This commit is contained in:
Zhenguo Niu 2015-07-03 18:00:51 +08:00
parent c9375086d5
commit 3ea61da17f
6 changed files with 39 additions and 8 deletions

View File

@ -38,3 +38,36 @@ def mistralclient(request):
),
service_type=SERVICE_TYPE
)
def execution_create(request, **data):
"""Creates new execution."""
return mistralclient(request).executions.create(**data)
def execution_list(request):
"""Returns all executions."""
return mistralclient(request).executions.list()
def task_list(request, execution_id=None):
"""Returns all tasks.
:param execution_id: Workflow execution ID associated with list of Tasks
"""
return mistralclient(request).tasks.list(execution_id)
def workflow_list(request):
"""Returns all workflows."""
return mistralclient(request).workflows.list()
def workbook_list(request):
"""Returns all workbooks."""
return mistralclient(request).workbooks.list()

View File

@ -26,7 +26,7 @@ class IndexView(tables.DataTableView):
template_name = 'mistral/executions/index.html'
def get_data(self):
return api.mistralclient(self.request).executions.list()
return api.execution_list(self.request)
class TaskView(tables.DataTableView):
@ -34,6 +34,4 @@ class TaskView(tables.DataTableView):
template_name = 'mistral/executions/index.html'
def get_data(self):
return api.mistralclient(self.request).tasks.list(
self.kwargs['execution_id']
)
return api.task_list(self.kwargs['execution_id'])

View File

@ -25,4 +25,4 @@ class IndexView(tables.DataTableView):
template_name = 'mistral/tasks/index.html'
def get_data(self):
return api.mistralclient(self.request).tasks.list()
return api.task_list(self.request)

View File

@ -25,4 +25,4 @@ class IndexView(tables.DataTableView):
template_name = 'mistral/workbooks/index.html'
def get_data(self):
return api.mistralclient(self.request).workbooks.list()
return api.workbook_list(self.request)

View File

@ -44,7 +44,7 @@ class ExecuteForm(forms.SelfHandlingForm):
def handle(self, request, data):
try:
ex = api.mistralclient(request).executions.create(**data)
ex = api.execution_create(request, **data)
msg = _('Execution has been created with id "%s".') % ex.id
messages.success(request, msg)

View File

@ -29,7 +29,7 @@ class IndexView(tables.DataTableView):
template_name = 'mistral/workflows/index.html'
def get_data(self):
return api.mistralclient(self.request).workflows.list()
return api.workflow_list(self.request)
class ExecuteView(forms.ModalFormView):