Skip to content

Commit e494e35

Browse files
committed
Merge branch 'release-v5.8.14'
2 parents 94044e2 + 4e3a333 commit e494e35

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

netfoundry/ctl.py

+16-20
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
from re import sub
2121
from subprocess import CalledProcessError
2222
from sys import exit as sysexit
23-
from sys import stdin, stdout, stderr
23+
from sys import stderr, stdin, stdout
2424
from xml.sax.xmlreader import InputSource
2525

2626
from jwt.exceptions import PyJWTError
27+
from milc import set_metadata # this function needed to set metadata immediately below
2728
from pygments import highlight
2829
from pygments.formatters import Terminal256Formatter
2930
from pygments.lexers import get_lexer_by_name, load_lexer_from_file
@@ -35,12 +36,11 @@
3536
from netfoundry import __version__ as netfoundry_version
3637

3738
from .exceptions import NeedUserInput, NFAPINoCredentials
38-
from .network import Networks, Network
39+
from .network import Network, Networks
3940
from .network_group import NetworkGroup
4041
from .organization import Organization
41-
from .utility import DC_PROVIDERS, MUTABLE_NET_RESOURCES, MUTABLE_RESOURCE_ABBREV, RESOURCE_ABBREV, RESOURCES, is_jwt, normalize_caseless, plural, singular
42+
from .utility import DC_PROVIDERS, EMBED_NET_RESOURCES, MUTABLE_NET_RESOURCES, MUTABLE_RESOURCE_ABBREV, RESOURCE_ABBREV, RESOURCES, is_jwt, normalize_caseless, plural, singular
4243

43-
from milc import set_metadata # this function needed to set metadata immediately below
4444
set_metadata(version=f"v{netfoundry_version}", author="NetFoundry", name="nfctl") # must precend import milc.cli
4545
from milc import cli, questions # this uses metadata set above
4646
from milc.subcommand import config # this creates the config subcommand
@@ -373,21 +373,21 @@ def edit(cli):
373373
@cli.argument('query', arg_only=True, action=StoreDictKeyPair, nargs='?', help="id=UUIDv4 or query params as k=v,k=v comma-separated pairs")
374374
@cli.argument('-k', '--keys', arg_only=True, action=StoreListKeys, help="list of keys as a,b,c to print only selected keys (columns)")
375375
@cli.argument('-a', '--as', dest='accept', arg_only=True, choices=['create'], help="request the as=create alternative form of the resource")
376+
@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()])
376377
@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])
377378
@cli.subcommand('get a single resource by type and query')
378-
def get(cli, echo: bool = True, embed='all', spinner: object = None):
379+
def get(cli, echo: bool = True, spinner: object = None):
379380
"""
380381
Get a single resource as YAML or JSON.
381382
382-
:param echo: False allows capture instead of print the match
383-
:param embed: False avoids expensive operations when we just need a shallow view
383+
:param echo: False allows the caller to capture the return instead of printing the match
384384
"""
385385
if RESOURCE_ABBREV.get(cli.args.resource_type):
386386
cli.args.resource_type = singular(RESOURCE_ABBREV[cli.args.resource_type].name)
387387
if not cli.config.general.verbose and cli.args.output in ["yaml", "json"]: # don't change level if output=text
388388
cli.log.setLevel(logging.WARN) # don't emit INFO messages to stdout because they will break deserialization
389389
if cli.args.accept and not MUTABLE_NET_RESOURCES.get(plural(cli.args.resource_type)):
390-
logging.warning("ignoring --as=create becuase it is applicable only to mutable resources in the network domain")
390+
logging.warning("ignoring --as=create because it is applicable only to mutable resources in the network domain")
391391
cli.args['accept'] = None
392392
match = {}
393393
matches = []
@@ -458,39 +458,35 @@ def get(cli, echo: bool = True, embed='all', spinner: object = None):
458458
if len(query_keys) > 1:
459459
query_keys.remove('id')
460460
cli.log.warn(f"using 'id' only, ignoring params: '{', '.join(query_keys)}'")
461-
match = organization.get_network(network_id=cli.args.query['id'], embed=embed, accept=cli.args.accept)
461+
match = organization.get_network(network_id=cli.args.query['id'], embed=cli.args.embed, accept=cli.args.accept)
462462
else:
463463
if cli.config.general.network_group and not cli.config.general.network:
464464
network_group = use_network_group(
465465
cli,
466466
organization,
467-
group=cli.config.general.network_group,
468-
)
467+
group=cli.config.general.network_group)
469468
matches = organization.find_networks_by_group(network_group.id, **cli.args.query)
470469
elif cli.config.general.network:
471470
network, network_group = use_network(
472471
cli,
473472
organization=organization,
474-
network_name=cli.config.general.network,
475-
)
476-
match = organization.get_network(network_id=network.id, embed=embed, accept=cli.args.accept)
473+
network_name=cli.config.general.network)
474+
match = organization.get_network(network_id=network.id, embed=cli.args.embed, accept=cli.args.accept)
477475
else:
478476
matches = organization.find_networks_by_organization(**cli.args.query)
479477
if len(matches) == 1:
480478
network, network_group = use_network(
481479
cli,
482480
organization=organization,
483-
network_name=matches[0]['name'],
484-
)
485-
match = organization.get_network(network_id=network.id, embed=embed, accept=cli.args.accept)
481+
network_name=matches[0]['name'])
482+
match = organization.get_network(network_id=network.id, embed=cli.args.embed, accept=cli.args.accept)
486483
else: # is a resource in the network domain
487484
if cli.config.general.network:
488485
network, network_group = use_network(
489486
cli,
490487
organization=organization,
491488
group=cli.config.general.network_group, # None unless configured
492-
network_name=cli.config.general.network,
493-
)
489+
network_name=cli.config.general.network)
494490
else:
495491
cli.log.error("need --network=ACMENet")
496492
sysexit(1)
@@ -707,7 +703,7 @@ def delete(cli):
707703
cli.config.general['wait'] = 0
708704
spinner.text = f"Finding {cli.args.resource_type} {'by' if query_keys else '...'} {', '.join(query_keys)}"
709705
with spinner:
710-
match, network, network_group, organization = get(cli, echo=False, embed=None, spinner=spinner)
706+
match, network, network_group, organization = get(cli, echo=False, spinner=spinner)
711707
if cli.args.resource_type == 'network':
712708
try:
713709
delete_confirmed = False

netfoundry/network.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Use a network and find and manage its resources."""
22

33
import json
4-
import logging
54
import re
65
import time
6+
77
from requests.exceptions import HTTPError, JSONDecodeError
88

9-
from netfoundry.exceptions import UnknownResourceType, NetworkBoundaryViolation
9+
from netfoundry.exceptions import NetworkBoundaryViolation, UnknownResourceType
1010

1111
from .utility import (DC_PROVIDERS, MUTABLE_NET_RESOURCES, NET_RESOURCES, PROCESS_STATUS_SYMBOLS, RESOURCES, STATUS_CODES, VALID_SEPARATORS, VALID_SERVICE_PROTOCOLS, any_in, docstring_parameters, find_generic_resources, get_generic_resource, http,
1212
is_uuidv4, normalize_caseless, plural, singular)

netfoundry/network_group.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
"""Use a network group and find its networks."""
22

3-
from ast import Or
4-
import logging
5-
6-
from .utility import (NET_RESOURCES, RESOURCES, STATUS_CODES,
7-
find_generic_resources, get_generic_resource, http, is_uuidv4,
8-
normalize_caseless, any_in)
93
from .network import Networks
4+
from .utility import NET_RESOURCES, RESOURCES, STATUS_CODES, any_in, find_generic_resources, get_generic_resource, http, is_uuidv4, normalize_caseless
105

116

127
class NetworkGroup:

netfoundry/organization.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def __init__(self,
4747
proxy: str = None):
4848
"""Initialize an instance of organization."""
4949
# set debug and file if specified and let the calling application dictate logging handlers
50+
self.log_file = log_file
51+
self.debug = debug
5052
if logger:
5153
# print(f"using logger '{logger}' from param")
5254
self.logger = logger
@@ -56,11 +58,10 @@ def __init__(self,
5658
# self.logger = logger or logging.getLogger(__name__)
5759
self.logger.addHandler(logging.NullHandler())
5860

59-
if debug:
60-
self.debug = debug
61+
if self.debug:
6162
self.logger.setLevel(logging.DEBUG)
62-
if log_file:
63-
self.log_file = log_file
63+
64+
if self.log_file:
6465
file_handler = logging.FileHandler(log_file, encoding='utf-8')
6566
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
6667
formatter.converter = time.gmtime

0 commit comments

Comments
 (0)