Add filters to client Python APIs
* A number of Mistral REST API endpoints support parameters that allow to filter colections. For example, we can pass do 'GET /v2/actions?name=in:std.' in a query string and Mistral will return only actions containing 'std.' in their name. This capability was missing in the client APIs, this patch adds corresponding parameters in the APIs for actions, workflows, executions (workflow executions) and tasks (task executions). TODO: - Add required tests Partially implements: blueprint mistral-client-api-filters Change-Id: Ic49f58626cf129f9c9399268c3cd12cc93eee039
This commit is contained in:
@@ -67,7 +67,8 @@ class ActionManager(base.ResourceManager):
|
||||
return [self.resource_class(self, resource_data)
|
||||
for resource_data in base.extract_json(resp, 'actions')]
|
||||
|
||||
def list(self, marker='', limit=None, sort_keys='', sort_dirs=''):
|
||||
def list(self, marker='', limit=None, sort_keys='', sort_dirs='',
|
||||
**filters):
|
||||
qparams = {}
|
||||
|
||||
if marker:
|
||||
@@ -82,6 +83,9 @@ class ActionManager(base.ResourceManager):
|
||||
if sort_dirs:
|
||||
qparams['sort_dirs'] = sort_dirs
|
||||
|
||||
for name, val in filters.items():
|
||||
qparams[name] = val
|
||||
|
||||
query_string = ("?%s" % urlparse.urlencode(list(qparams.items()))
|
||||
if qparams else "")
|
||||
|
||||
|
@@ -70,7 +70,7 @@ class ExecutionManager(base.ResourceManager):
|
||||
return self._update('/executions/%s' % id, data)
|
||||
|
||||
def list(self, task=None, marker='', limit=None, sort_keys='',
|
||||
sort_dirs=''):
|
||||
sort_dirs='', **filters):
|
||||
qparams = {}
|
||||
|
||||
if task:
|
||||
@@ -88,6 +88,9 @@ class ExecutionManager(base.ResourceManager):
|
||||
if sort_dirs:
|
||||
qparams['sort_dirs'] = sort_dirs
|
||||
|
||||
for name, val in filters.items():
|
||||
qparams[name] = val
|
||||
|
||||
query_string = ("?%s" % urlparse.urlencode(list(qparams.items()))
|
||||
if qparams else "")
|
||||
|
||||
|
@@ -14,9 +14,12 @@
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import six
|
||||
|
||||
from mistralclient.api import base
|
||||
|
||||
urlparse = six.moves.urllib.parse
|
||||
|
||||
|
||||
class Task(base.Resource):
|
||||
resource_name = 'Task'
|
||||
@@ -25,13 +28,36 @@ class Task(base.Resource):
|
||||
class TaskManager(base.ResourceManager):
|
||||
resource_class = Task
|
||||
|
||||
def list(self, workflow_execution_id=None):
|
||||
def list(self, workflow_execution_id=None, marker='', limit=None,
|
||||
sort_keys='', sort_dirs='', **filters):
|
||||
url = '/tasks'
|
||||
|
||||
if workflow_execution_id:
|
||||
url = '/executions/%s/tasks' % workflow_execution_id
|
||||
|
||||
return self._list(url, response_key='tasks')
|
||||
url += '%s'
|
||||
|
||||
qparams = {}
|
||||
|
||||
if marker:
|
||||
qparams['marker'] = marker
|
||||
|
||||
if limit:
|
||||
qparams['limit'] = limit
|
||||
|
||||
if sort_keys:
|
||||
qparams['sort_keys'] = sort_keys
|
||||
|
||||
if sort_dirs:
|
||||
qparams['sort_dirs'] = sort_dirs
|
||||
|
||||
for name, val in filters.items():
|
||||
qparams[name] = val
|
||||
|
||||
query_string = ("?%s" % urlparse.urlencode(list(qparams.items()))
|
||||
if qparams else "")
|
||||
|
||||
return self._list(url % query_string, response_key='tasks')
|
||||
|
||||
def get(self, id):
|
||||
self._ensure_not_empty(id=id)
|
||||
|
@@ -72,7 +72,8 @@ class WorkflowManager(base.ResourceManager):
|
||||
return [self.resource_class(self, resource_data)
|
||||
for resource_data in base.extract_json(resp, 'workflows')]
|
||||
|
||||
def list(self, marker='', limit=None, sort_keys='', sort_dirs=''):
|
||||
def list(self, marker='', limit=None, sort_keys='', sort_dirs='',
|
||||
**filters):
|
||||
qparams = {}
|
||||
|
||||
if marker:
|
||||
@@ -87,6 +88,9 @@ class WorkflowManager(base.ResourceManager):
|
||||
if sort_dirs:
|
||||
qparams['sort_dirs'] = sort_dirs
|
||||
|
||||
for name, val in filters.items():
|
||||
qparams[name] = val
|
||||
|
||||
query_string = ("?%s" % urlparse.urlencode(list(qparams.items()))
|
||||
if qparams else "")
|
||||
|
||||
|
Reference in New Issue
Block a user