commands with --filter option accept multiple filters and join them
Fixes bug 1226
Change-Id: I757ec0dc8707bafe41f74e317b1ec7e1e3c07ea6
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py
index 3ef81ac..2cca98d 100755
--- a/osmclient/scripts/osm.py
+++ b/osmclient/scripts/osm.py
@@ -172,7 +172,7 @@
####################
@cli_osm.command(name='ns-list', short_help='list all NS instances')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NS instances matching the filter.')
@click.option('--long', is_flag=True,
help='get more details of the NS (project, vim, deployment status, configuration status.')
@@ -310,6 +310,7 @@
logger.debug("")
if filter:
check_client_version(ctx.obj, '--filter')
+ filter='&'.join(filter)
resp = ctx.obj.ns.list(filter)
else:
resp = ctx.obj.ns.list()
@@ -415,6 +416,7 @@
logger.debug("")
if filter:
check_client_version(ctx.obj, '--filter')
+ filter='&'.join(filter)
resp = ctx.obj.nsd.list(filter)
else:
resp = ctx.obj.nsd.list()
@@ -446,7 +448,7 @@
@cli_osm.command(name='nsd-list', short_help='list all NS packages')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NSD/NSpkg matching the filter')
@click.option('--long', is_flag=True, help='get more details')
@click.pass_context
@@ -457,7 +459,7 @@
@cli_osm.command(name='nspkg-list', short_help='list all NS packages')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NSD/NSpkg matching the filter')
@click.option('--long', is_flag=True, help='get more details')
@click.pass_context
@@ -468,6 +470,8 @@
def pkg_repo_list(ctx, pkgtype, filter, repo, long):
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.osmrepo.pkg_list(pkgtype, filter, repo)
if long:
table = PrettyTable(['nfpkg name', 'vendor', 'version', 'latest', 'description', 'repository'])
@@ -493,6 +497,8 @@
check_client_version(ctx.obj, '--nf_type')
elif filter:
check_client_version(ctx.obj, '--filter')
+ if filter:
+ filter='&'.join(filter)
if nf_type:
if nf_type == "vnf":
nf_filter = "_admin.type=vnfd"
@@ -541,7 +547,7 @@
@cli_osm.command(name='vnfd-list', short_help='list all xNF packages (VNF, HNF, PNF)')
@click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NF pkg matching the filter')
@click.option('--long', is_flag=True, help='get more details')
@click.pass_context
@@ -553,7 +559,7 @@
@cli_osm.command(name='vnfpkg-list', short_help='list all xNF packages (VNF, HNF, PNF)')
@click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NFpkg matching the filter')
@click.option('--long', is_flag=True, help='get more details')
@click.pass_context
@@ -564,7 +570,7 @@
@cli_osm.command(name='nfpkg-list', short_help='list all xNF packages (VNF, HNF, PNF)')
@click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NFpkg matching the filter')
@click.option('--long', is_flag=True, help='get more details')
@click.pass_context
@@ -579,7 +585,7 @@
# exit(1)
@cli_osm.command(name='vnfpkg-repo-list', short_help='list all xNF from OSM repositories')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NFpkg matching the filter')
@click.option('--repo', default=None,
help='restricts the list to a particular OSM repository')
@@ -591,7 +597,7 @@
pkg_repo_list(ctx, pkgtype, filter, repo, long)
@cli_osm.command(name='nfpkg-repo-list', short_help='list all xNF from OSM repositories')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NFpkg matching the filter')
@click.option('--repo', default=None,
help='restricts the list to a particular OSM repository')
@@ -608,6 +614,7 @@
if ns:
check_client_version(ctx.obj, '--ns')
if filter:
+ filter='&'.join(filter)
check_client_version(ctx.obj, '--filter')
resp = ctx.obj.vnf.list(ns, filter)
else:
@@ -655,7 +662,7 @@
@cli_osm.command(name='vnf-list', short_help='list all NF instances')
@click.option('--ns', default=None, help='NS instance id or name to restrict the NF list')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NF instances matching the filter.')
@click.option('--long', is_flag=True, help='get more details')
@click.pass_context
@@ -665,7 +672,7 @@
vnf_list(ctx, ns, filter, long)
@cli_osm.command(name='nsd-repo-list', short_help='list all NS from OSM repositories')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NS matching the filter')
@click.option('--repo', default=None,
help='restricts the list to a particular OSM repository')
@@ -677,7 +684,7 @@
pkg_repo_list(ctx, pkgtype, filter, repo, long)
@cli_osm.command(name='nspkg-repo-list', short_help='list all NS from OSM repositories')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NS matching the filter')
@click.option('--repo', default=None,
help='restricts the list to a particular OSM repository')
@@ -690,7 +697,7 @@
@cli_osm.command(name='nf-list', short_help='list all NF instances')
@click.option('--ns', default=None, help='NS instance id or name to restrict the NF list')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NF instances matching the filter.')
@click.option('--long', is_flag=True, help='get more details')
@click.pass_context
@@ -818,6 +825,8 @@
logger.debug("")
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.nsi.list(filter)
# except ClientException as e:
# print(str(e))
@@ -847,7 +856,7 @@
@cli_osm.command(name='nsi-list', short_help='list all Network Slice Instances (NSI)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the Network Slice Instances matching the filter')
@click.pass_context
def nsi_list1(ctx, filter):
@@ -857,7 +866,7 @@
@cli_osm.command(name='netslice-instance-list', short_help='list all Network Slice Instances (NSI)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the Network Slice Instances matching the filter')
@click.pass_context
def nsi_list2(ctx, filter):
@@ -870,6 +879,8 @@
logger.debug("")
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.nst.list(filter)
# except ClientException as e:
# print(str(e))
@@ -884,7 +895,7 @@
@cli_osm.command(name='nst-list', short_help='list all Network Slice Templates (NST)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NST matching the filter')
@click.pass_context
def nst_list1(ctx, filter):
@@ -894,7 +905,7 @@
@cli_osm.command(name='netslice-template-list', short_help='list all Network Slice Templates (NST)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the NST matching the filter')
@click.pass_context
def nst_list2(ctx, filter):
@@ -944,7 +955,7 @@
@cli_osm.command(name='pdu-list', short_help='list all Physical Deployment Units (PDU)')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the Physical Deployment Units matching the filter')
@click.pass_context
def pdu_list(ctx, filter):
@@ -952,6 +963,8 @@
logger.debug("")
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.pdu.list(filter)
# except ClientException as e:
# print(str(e))
@@ -1053,6 +1066,8 @@
def pkg_repo_show(ctx, pkgtype, name, repo, version, filter, literal):
logger.debug("")
+ if filter:
+ filter='&'.join(filter)
# try:
resp = ctx.obj.osmrepo.pkg_get(pkgtype, name, repo, version, filter)
@@ -1073,6 +1088,7 @@
table.align = 'l'
print(table)
+
@cli_osm.command(name='vnfd-show', short_help='shows the details of a NF package')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
@@ -1100,6 +1116,7 @@
logger.debug("")
vnfd_show(ctx, name, literal)
+
@cli_osm.command(name='vnfpkg-repo-show', short_help='shows the details of a NF package in an OSM repository')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
@@ -1107,7 +1124,7 @@
required=True,
help='Repository name')
@click.argument('name')
-@click.option('--filter',
+@click.option('--filter', default=None, multiple=True,
help='filter by fields')
@click.option('--version',
default='latest',
@@ -1129,7 +1146,7 @@
required=True,
help='Repository name')
@click.argument('name')
-@click.option('--filter',
+@click.option('--filter', default=None, multiple=True,
help='filter by fields')
@click.option('--version',
default='latest',
@@ -1143,6 +1160,7 @@
pkgtype = 'ns'
pkg_repo_show(ctx, pkgtype, name, repo, version, filter, literal)
+
@cli_osm.command(name='nspkg-repo-show', short_help='shows the details of a NS package in an OSM repository')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
@@ -1150,7 +1168,7 @@
required=True,
help='Repository name')
@click.argument('name')
-@click.option('--filter',
+@click.option('--filter', default=None, multiple=True,
help='filter by fields')
@click.option('--version',
default='latest',
@@ -1164,6 +1182,7 @@
pkgtype = 'ns'
pkg_repo_show(ctx, pkgtype, name, repo, version, filter, literal)
+
@cli_osm.command(name='nfpkg-show', short_help='shows the details of a NF package')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
@@ -1185,7 +1204,7 @@
required=True,
help='Repository name')
@click.argument('name')
-@click.option('--filter',
+@click.option('--filter', default=None, multiple=True,
help='filter by fields')
@click.option('--version',
default='latest',
@@ -1204,7 +1223,8 @@
@click.argument('name')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
-@click.option('--filter', default=None)
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.pass_context
def ns_show(ctx, name, literal, filter):
"""shows the info of a NS instance
@@ -1225,7 +1245,7 @@
table = PrettyTable(['field', 'value'])
for k, v in list(ns.items()):
- if filter is None or filter in k:
+ if not filter or k in filter:
table.add_row([k, wrap_text(text=json.dumps(v, indent=2),width=100)])
fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
@@ -1233,7 +1253,7 @@
nsopdata = ctx.obj.ns.get_opdata(ns['id'])
nsr_optdata = nsopdata['nsr:nsr']
for k, v in list(nsr_optdata.items()):
- if filter is None or filter in k:
+ if not filter or k in filter:
table.add_row([k, wrap_text(json.dumps(v, indent=2),width=100)])
table.align = 'l'
print(table)
@@ -1243,7 +1263,8 @@
@click.argument('name')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
-@click.option('--filter', default=None, help='restricts the information to the fields in the filter')
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.option('--kdu', default=None, help='KDU name (whose status will be shown)')
@click.pass_context
def vnf_show(ctx, name, literal, filter, kdu):
@@ -1315,7 +1336,7 @@
table = PrettyTable(['field', 'value'])
for k, v in list(resp.items()):
- if filter is None or filter in k:
+ if not filter or k in filter:
table.add_row([k, wrap_text(text=json.dumps(v,indent=2),width=100)])
table.align = 'l'
print(table)
@@ -1372,7 +1393,8 @@
@cli_osm.command(name='ns-op-show', short_help='shows the info of a NS operation')
@click.argument('id')
-@click.option('--filter', default=None)
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
@click.pass_context
@@ -1395,7 +1417,7 @@
table = PrettyTable(['field', 'value'])
for k, v in list(op_info.items()):
- if filter is None or filter in k:
+ if not filter or k in filter:
table.add_row([k, wrap_text(json.dumps(v, indent=2), 100)])
table.align = 'l'
print(table)
@@ -1466,7 +1488,7 @@
table = PrettyTable(['field', 'value'])
for k, v in list(nsi.items()):
- if filter is None or filter in k:
+ if not filter or k in filter:
table.add_row([k, json.dumps(v, indent=2)])
table.align = 'l'
@@ -1477,7 +1499,8 @@
@click.argument('name')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
-@click.option('--filter', default=None)
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.pass_context
def nsi_show1(ctx, name, literal, filter):
"""shows the content of a Network Slice Instance (NSI)
@@ -1492,7 +1515,8 @@
@click.argument('name')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
-@click.option('--filter', default=None)
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.pass_context
def nsi_show2(ctx, name, literal, filter):
"""shows the content of a Network Slice Instance (NSI)
@@ -1514,7 +1538,7 @@
table = PrettyTable(['field', 'value'])
for k, v in list(op_info.items()):
- if filter is None or filter in k:
+ if not filter or k in filter:
table.add_row([k, json.dumps(v, indent=2)])
table.align = 'l'
print(table)
@@ -1522,7 +1546,8 @@
@cli_osm.command(name='nsi-op-show', short_help='shows the info of an operation over a Network Slice Instance(NSI)')
@click.argument('id')
-@click.option('--filter', default=None)
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.pass_context
def nsi_op_show1(ctx, id, filter):
"""shows the info of an operation over a Network Slice Instance(NSI)
@@ -1535,7 +1560,8 @@
@cli_osm.command(name='netslice-instance-op-show', short_help='shows the info of an operation over a Network Slice Instance(NSI)')
@click.argument('id')
-@click.option('--filter', default=None)
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.pass_context
def nsi_op_show2(ctx, id, filter):
"""shows the info of an operation over a Network Slice Instance(NSI)
@@ -1550,7 +1576,8 @@
@click.argument('name')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
-@click.option('--filter', default=None)
+@click.option('--filter', multiple=True,
+ help='restricts the information to the fields in the filter')
@click.pass_context
def pdu_show(ctx, name, literal, filter):
"""shows the content of a Physical Deployment Unit (PDU)
@@ -1572,7 +1599,7 @@
table = PrettyTable(['field', 'value'])
for k, v in list(pdu.items()):
- if filter is None or filter in k:
+ if not filter or k in filter:
table.add_row([k, json.dumps(v, indent=2)])
table.align = 'l'
@@ -2518,7 +2545,7 @@
#@click.option('--ro_update/--no_ro_update',
# default=False,
# help='update list from RO')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the VIM accounts matching the filter')
@click.option('--long', is_flag=True,
help='get more details of the NS (project, vim, deployment status, configuration status.')
@@ -2527,6 +2554,7 @@
"""list all VIM accounts"""
logger.debug("")
if filter:
+ filter='&'.join(filter)
check_client_version(ctx.obj, '--filter')
# if ro_update:
# check_client_version(ctx.obj, '--ro_update', 'v1')
@@ -2734,7 +2762,7 @@
@cli_osm.command(name='wim-list', short_help='list all WIM accounts')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the WIM accounts matching the filter')
@click.pass_context
def wim_list(ctx, filter):
@@ -2742,6 +2770,8 @@
logger.debug("")
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.wim.list(filter)
table = PrettyTable(['wim name', 'uuid'])
for wim in resp:
@@ -2909,7 +2939,7 @@
@cli_osm.command(name='sdnc-list', short_help='list all SDN controllers')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help="restricts the list to the SDN controllers matching the filter with format: 'k[.k..]=v[&k[.k]=v2]'")
@click.pass_context
def sdnc_list(ctx, filter):
@@ -2917,6 +2947,8 @@
logger.debug("")
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.sdnc.list(filter)
# except ClientException as e:
# print(str(e))
@@ -3082,7 +3114,7 @@
@cli_osm.command(name='k8scluster-list')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the K8s clusters matching the filter')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
@@ -3091,6 +3123,8 @@
"""list all K8s clusters"""
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.k8scluster.list(filter)
if literal:
print(yaml.safe_dump(resp, indent=4, default_flow_style=False))
@@ -3248,7 +3282,7 @@
@cli_osm.command(name='repo-list')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the repos matching the filter')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
@@ -3258,6 +3292,8 @@
# try:
# K8s Repositories
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.repo.list(filter)
resp += ctx.obj.osmrepo.list(filter)
if literal:
@@ -3379,7 +3415,7 @@
@cli_osm.command(name='project-list', short_help='list all projects')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the projects matching the filter')
@click.pass_context
def project_list(ctx, filter):
@@ -3387,6 +3423,8 @@
logger.debug("")
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.project.list(filter)
# except ClientException as e:
# print(str(e))
@@ -3577,13 +3615,15 @@
@cli_osm.command(name='user-list', short_help='list all users')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the users matching the filter')
@click.pass_context
def user_list(ctx, filter):
"""list all users"""
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.user.list(filter)
# except ClientException as e:
# print(str(e))
@@ -4094,7 +4134,7 @@
@cli_osm.command(name='role-list', short_help='list all roles')
-@click.option('--filter', default=None,
+@click.option('--filter', default=None, multiple=True,
help='restricts the list to the projects matching the filter')
@click.pass_context
def role_list(ctx, filter):
@@ -4104,6 +4144,8 @@
logger.debug("")
# try:
check_client_version(ctx.obj, ctx.command.name)
+ if filter:
+ filter='&'.join(filter)
resp = ctx.obj.role.list(filter)
# except ClientException as e:
# print(str(e))