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:
@@ -70,10 +70,24 @@ class List(base.MistralLister):
|
|||||||
def _get_format_function(self):
|
def _get_format_function(self):
|
||||||
return format_list
|
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):
|
def _get_resources(self, parsed_args):
|
||||||
mistral_client = self.app.client_manager.workflow_engine
|
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):
|
class Get(command.ShowOne):
|
||||||
|
@@ -65,3 +65,18 @@ def wrap(string, width=25):
|
|||||||
return textwrap.fill(string, width)
|
return textwrap.fill(string, width)
|
||||||
else:
|
else:
|
||||||
return string
|
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',
|
default='asc',
|
||||||
nargs='?'
|
nargs='?'
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--filter',
|
||||||
|
dest='filters',
|
||||||
|
action='append',
|
||||||
|
help='Filters. Can be repeated.'
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def _get_resources(self, parsed_args):
|
def _get_resources(self, parsed_args):
|
||||||
mistral_client = self.app.client_manager.workflow_engine
|
mistral_client = self.app.client_manager.workflow_engine
|
||||||
|
|
||||||
return mistral_client.executions.list(
|
return mistral_client.executions.list(
|
||||||
task=parsed_args.task,
|
task=parsed_args.task,
|
||||||
marker=parsed_args.marker,
|
marker=parsed_args.marker,
|
||||||
limit=parsed_args.limit,
|
limit=parsed_args.limit,
|
||||||
sort_keys=parsed_args.sort_keys,
|
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(
|
parser.add_argument(
|
||||||
'workflow_execution',
|
'workflow_execution',
|
||||||
nargs='?',
|
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
|
return parser
|
||||||
|
|
||||||
@@ -82,7 +89,10 @@ class List(base.MistralLister):
|
|||||||
def _get_resources(self, parsed_args):
|
def _get_resources(self, parsed_args):
|
||||||
mistral_client = self.app.client_manager.workflow_engine
|
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):
|
class Get(command.ShowOne):
|
||||||
|
@@ -65,9 +65,24 @@ class List(base.MistralLister):
|
|||||||
def _get_format_function(self):
|
def _get_format_function(self):
|
||||||
return format_list
|
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):
|
def _get_resources(self, parsed_args):
|
||||||
mistral_client = self.app.client_manager.workflow_engine
|
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):
|
class Get(show.ShowOne):
|
||||||
|
Reference in New Issue
Block a user