Skip to content

Commit 3efc7d0

Browse files
committed
Merge branch 'release-v5.8.16'
2 parents 51e9ec0 + 04783af commit 3efc7d0

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

netfoundry/ctl.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ def logout(cli):
238238

239239

240240
@cli.argument('query', arg_only=True, action=StoreDictKeyPair, nargs='?', help="id=UUIDv4 or query params as k=v,k=v comma-separated pairs")
241-
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE", choices=[choice for group in [[singular(type), MUTABLE_NET_RESOURCES[type].abbreviation] for type in MUTABLE_NET_RESOURCES.keys()] for choice in group])
241+
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE",
242+
choices=[choice for group in [[singular(type), MUTABLE_NET_RESOURCES[type].abbreviation] for type in MUTABLE_NET_RESOURCES.keys()] for choice in group])
242243
# this allows us to pass the edit subcommand's cli object to function get without further modifying that functions params
243244
@cli.subcommand('duplicate a resource')
244245
def copy(cli):
@@ -269,7 +270,8 @@ def copy(cli):
269270

270271

271272
@cli.argument('-f', '--file', help='JSON or YAML file', type=argparse.FileType('r', encoding='UTF-8'))
272-
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE", choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in MUTABLE_NET_RESOURCES.keys()] for choice in group])
273+
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE",
274+
choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in MUTABLE_NET_RESOURCES.keys()] for choice in group])
273275
@cli.subcommand('create a resource from a file')
274276
def create(cli):
275277
"""Create a resource.
@@ -341,7 +343,8 @@ def create(cli):
341343

342344

343345
@cli.argument('query', arg_only=True, action=StoreDictKeyPair, nargs='?', help="id=UUIDv4 or query params as k=v,k=v comma-separated pairs")
344-
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE", choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in MUTABLE_NET_RESOURCES.keys()] for choice in group])
346+
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE",
347+
choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in MUTABLE_NET_RESOURCES.keys()] for choice in group])
345348
# this allows us to pass the edit subcommand's cli object to function get without further modifying that functions params
346349
@cli.subcommand('edit a resource with EDITOR')
347350
def edit(cli):
@@ -375,8 +378,11 @@ def edit(cli):
375378
@cli.argument('query', arg_only=True, action=StoreDictKeyPair, nargs='?', help="id=UUIDv4 or query params as k=v,k=v comma-separated pairs")
376379
@cli.argument('-k', '--keys', arg_only=True, action=StoreListKeys, help="list of keys as a,b,c to print only selected keys (columns)")
377380
@cli.argument('-a', '--as', dest='accept', arg_only=True, choices=['create'], help="request the as=create alternative form of the resource")
378-
@cli.argument('-e', '--embed', arg_only=True, action=StoreListKeys, default=None, help="applies to 'get network': optionally embed comma-sep list of resource types or 'all' of a network's resource collections", choices=[plural(type) for type in EMBED_NET_RESOURCES.keys()])
379-
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE", choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in RESOURCES.keys()] for choice in group])
381+
@cli.argument('-e', '--embed', arg_only=True, nargs='+',
382+
help="applies to 'get network': optionally embed space-sep list of resource types or 'all' of a network's resource collections",
383+
choices=[plural(type) for type in EMBED_NET_RESOURCES.keys()].extend('all'))
384+
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE",
385+
choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in RESOURCES.keys()] for choice in group])
380386
@cli.subcommand('get a single resource by type and query')
381387
def get(cli, echo: bool = True, spinner: object = None):
382388
"""
@@ -559,7 +565,8 @@ def get(cli, echo: bool = True, spinner: object = None):
559565
@cli.argument('-k', '--keys', arg_only=True, action=StoreListKeys, help="list of keys as a,b,c to print only selected keys (columns)")
560566
@cli.argument('-m', '--my-roles', arg_only=True, action='store_true', help="filter roles by caller identity")
561567
@cli.argument('-a', '--as', dest='accept', arg_only=True, choices=['create'], help="request the as=create alternative form of the resources")
562-
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE", choices=[choice for group in [[type, RESOURCES[type].abbreviation] for type in RESOURCES.keys()] for choice in group])
568+
@cli.argument('resource_type', arg_only=True, help='type of resource', metavar="RESOURCE_TYPE",
569+
choices=[choice for group in [[type, RESOURCES[type].abbreviation] for type in RESOURCES.keys()] for choice in group])
563570
@cli.subcommand(description='find a collection of resources by type and query')
564571
def list(cli, spinner: object = None):
565572
"""Find resources as lists."""
@@ -693,7 +700,8 @@ def list(cli, spinner: object = None):
693700

694701

695702
@cli.argument('query', arg_only=True, action=StoreDictKeyPair, nargs='?', help="query params as k=v,k=v comma-separated pairs")
696-
@cli.argument('resource_type', arg_only=True, help='type of resource', choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in RESOURCES.keys()] for choice in group])
703+
@cli.argument('resource_type', arg_only=True, help='type of resource',
704+
choices=[choice for group in [[singular(type), RESOURCES[type].abbreviation] for type in RESOURCES.keys()] for choice in group])
697705
@cli.subcommand('delete a single resource by type and query')
698706
def delete(cli):
699707
"""Delete a resource in the network domain."""

netfoundry/organization.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def get_network_group(self, network_group_id):
572572
else:
573573
return(network_group)
574574

575-
def get_network(self, network_id: str, embed: str = None, accept: str = None):
575+
def get_network(self, network_id: str, embed: object = None, accept: str = None):
576576
"""Describe a Network by ID.
577577
578578
:param str network_id: UUIDv4 of the network to get
@@ -584,16 +584,18 @@ def get_network(self, network_id: str, embed: str = None, accept: str = None):
584584
headers = dict()
585585
headers["authorization"] = "Bearer " + self.token
586586
params = dict()
587-
if embed == "all":
588-
params['embed'] = ', '.join(EMBED_NET_RESOURCES)
589-
self.logger.debug(f"requesting embed all resource types in network domain: {params['embed']}")
590-
elif embed:
591-
valid_types = [plural(type) for type in embed.split(',') if RESOURCES[plural(type)]['domain'] == "network"]
592-
params['embed'] = ', '.join(valid_types)
593-
self.logger.debug(f"requesting embed some resource types in network domain: {valid_types}")
594-
for type in embed.split(','):
595-
if not NET_RESOURCES.get(type):
596-
self.logger.warn(f"not requesting '{type}', not a resource type in the network domain")
587+
requested_types = list()
588+
valid_types = set()
589+
if embed:
590+
if isinstance(embed, list):
591+
requested_types.extend(embed)
592+
else:
593+
requested_types.extend(embed.split(','))
594+
if 'all' in requested_types:
595+
requested_types.extend(EMBED_NET_RESOURCES.keys())
596+
valid_types = [plural(type) for type in requested_types if EMBED_NET_RESOURCES.get(plural(type))]
597+
params['embed'] = ','.join(valid_types)
598+
self.logger.debug(f"requesting embed of: '{valid_types}'")
597599

598600
url = self.audience+'core/v2/networks/'+network_id
599601
network, status_symbol = get_generic_resource(url=url, headers=headers, accept=accept, proxies=self.proxies, verify=self.verify, **params)

0 commit comments

Comments
 (0)