Add '--filter' parameter to list commands in CLI
* This patch adds filtering capabilities into CLI after the previous patch. TODO: * Functional tests Change-Id: Icfce86be0fa1c9e585f626ee2e3a95772c7104f0
This commit is contained in:
parent
fdda862e7c
commit
ecf5876021
|
@ -70,10 +70,24 @@ class List(base.MistralLister):
|
|||
def _get_format_function(self):
|
||||
return format_list
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(List, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'--filter',
|
||||
dest='filters',
|
||||
action='append',
|
||||
help='Filters. Can be repeated.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def _get_resources(self, parsed_args):
|
||||
mistral_client = self.app.client_manager.workflow_engine
|
||||
|
||||
return mistral_client.actions.list()
|
||||
return mistral_client.actions.list(
|
||||
**base.get_filters(parsed_args)
|
||||
)
|
||||
|
||||
|
||||
class Get(command.ShowOne):
|
||||
|
|
|
@ -65,3 +65,18 @@ def wrap(string, width=25):
|
|||
return textwrap.fill(string, width)
|
||||
else:
|
||||
return string
|
||||
|
||||
|
||||
def get_filters(parsed_args):
|
||||
filters = {}
|
||||
|
||||
if parsed_args.filters:
|
||||
for f in parsed_args.filters:
|
||||
arr = f.split('=')
|
||||
|
||||
if len(arr) != 2:
|
||||
raise ValueError('Invalid filter: %s' % f)
|
||||
|
||||
filters[arr[0]] = arr[1]
|
||||
|
||||
return filters
|
||||
|
|
|
@ -112,17 +112,25 @@ class List(base.MistralLister):
|
|||
default='asc',
|
||||
nargs='?'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--filter',
|
||||
dest='filters',
|
||||
action='append',
|
||||
help='Filters. Can be repeated.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def _get_resources(self, parsed_args):
|
||||
mistral_client = self.app.client_manager.workflow_engine
|
||||
|
||||
return mistral_client.executions.list(
|
||||
task=parsed_args.task,
|
||||
marker=parsed_args.marker,
|
||||
limit=parsed_args.limit,
|
||||
sort_keys=parsed_args.sort_keys,
|
||||
sort_dirs=parsed_args.sort_dirs
|
||||
sort_dirs=parsed_args.sort_dirs,
|
||||
**base.get_filters(parsed_args)
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -72,7 +72,14 @@ class List(base.MistralLister):
|
|||
parser.add_argument(
|
||||
'workflow_execution',
|
||||
nargs='?',
|
||||
help='Workflow execution ID associated with list of Tasks.')
|
||||
help='Workflow execution ID associated with list of Tasks.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--filter',
|
||||
dest='filters',
|
||||
action='append',
|
||||
help='Filters. Can be repeated.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
@ -82,7 +89,10 @@ class List(base.MistralLister):
|
|||
def _get_resources(self, parsed_args):
|
||||
mistral_client = self.app.client_manager.workflow_engine
|
||||
|
||||
return mistral_client.tasks.list(parsed_args.workflow_execution)
|
||||
return mistral_client.tasks.list(
|
||||
parsed_args.workflow_execution,
|
||||
**base.get_filters(parsed_args)
|
||||
)
|
||||
|
||||
|
||||
class Get(command.ShowOne):
|
||||
|
|
|
@ -65,9 +65,24 @@ class List(base.MistralLister):
|
|||
def _get_format_function(self):
|
||||
return format_list
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(List, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'--filter',
|
||||
dest='filters',
|
||||
action='append',
|
||||
help='Filters. Can be repeated.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def _get_resources(self, parsed_args):
|
||||
mistral_client = self.app.client_manager.workflow_engine
|
||||
return mistral_client.workflows.list()
|
||||
|
||||
return mistral_client.workflows.list(
|
||||
**base.get_filters(parsed_args)
|
||||
)
|
||||
|
||||
|
||||
class Get(show.ShowOne):
|
||||
|
|
Loading…
Reference in New Issue