From ea7f615724adea1fedf77619f426ce10e5f9afca Mon Sep 17 00:00:00 2001 From: akarneliuk Date: Thu, 28 Jul 2022 09:28:51 +0100 Subject: [PATCH] 0.8.4 --- README.rst | 9 +++++++-- pygnmi/arg_parser.py | 11 +++++++++-- pygnmi/client.py | 12 +++++++++--- scripts/pygnmicli | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 272f042..f8a258e 100644 --- a/README.rst +++ b/README.rst @@ -58,10 +58,10 @@ Tested Network Operating Systems (NOS) - Cisco IOS XR - Juniper JUNOS - Nokia SRLinux +- Cisco NX-OS Network Operating Systems (NOS) in test --------------------------------------- -- Cisco Nexus - Broadcom SONiC ======= @@ -86,6 +86,11 @@ Contributors Dev Log ======= +Release **0.8.4**: + +- Change logic of setting default values for some parameters to improve user experience. +- Added ``token`` authentication to ``pygnmicli``. + Release **0.8.3**: - Changed behaviour of ``subscribe2()`` to RPC to avoid adding the empty ``Extension`` field for no extensions presenting. Fix for `Issue 83 `_. @@ -385,7 +390,7 @@ Release **0.1.0**: (c)2020-2022, karneliuk.com -.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.3&color=success +.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.4&color=success .. _version: https://pypi.org/project/pygnmi/ .. |tag| image:: https://img.shields.io/static/v1?label=status&message=stable&color=success .. _tag: https://pypi.org/project/pygnmi/ diff --git a/pygnmi/arg_parser.py b/pygnmi/arg_parser.py index b7a4bdd..8a39f2d 100644 --- a/pygnmi/arg_parser.py +++ b/pygnmi/arg_parser.py @@ -24,7 +24,7 @@ def parse_args(msg): parser.add_argument( "-u", "--user", type=str, - required=True, + required=False, help="Username to use when connecting", dest="username" ) @@ -35,6 +35,13 @@ def parse_args(msg): help="Password to use when connecting", dest="password" ) + parser.add_argument( + "--token", + type=str, + required=False, + default="", + help="Specify the token for token-based authentication", + ) parser.add_argument( "-c", "--path-cert", type=str, @@ -169,7 +176,7 @@ def parse_args(msg): if len(args.gnmi_path) > 1: parser.error(f"Only one path supported when doing a {args.operation} operation") - if not args.password: + if not args.password and not args.token: args.password = getpass("Device password: ") return args diff --git a/pygnmi/client.py b/pygnmi/client.py index aa842f2..0976eb1 100644 --- a/pygnmi/client.py +++ b/pygnmi/client.py @@ -300,7 +300,7 @@ def capabilities(self): return None - def get(self, prefix: str = "", path: list = [], + def get(self, prefix: str = "", path: list = None, target: str = None, datatype: str = 'all', encoding: str = 'json'): """ @@ -335,6 +335,8 @@ def get(self, prefix: str = "", path: list = [], type_dict = {'all', 'config', 'state', 'operational'} encoding_set = {'json', 'bytes', 'proto', 'ascii', 'json_ietf'} + # Set Protobuf value for information type + pb_datatype = 0 if datatype in type_dict: if datatype == 'all': pb_datatype = 0 @@ -344,9 +346,11 @@ def get(self, prefix: str = "", path: list = [], pb_datatype = 2 elif datatype == 'operational': pb_datatype = 3 - else: - logger.error('The GetRequst data type is not within the defined range') + else: + logger.error('The GetRequst data type is not within the defined range. Using default type \'all\'.') + # Set Protobuf value for encoding + pb_encoding = 4 if encoding in encoding_set: if encoding.lower() == 'json': pb_encoding = 0 @@ -358,6 +362,8 @@ def get(self, prefix: str = "", path: list = [], pb_encoding = 3 else: pb_encoding = 4 + else: + logger.error('The GetRequst encoding is not within the defined range. Using default type \'json_ietf\'.') # Gnmi PREFIX try: diff --git a/scripts/pygnmicli b/scripts/pygnmicli index 0c25f45..4c61eb9 100644 --- a/scripts/pygnmicli +++ b/scripts/pygnmicli @@ -36,7 +36,7 @@ def main(): # gNMI operation with gNMIclient( - target=args.target, username=args.username, password=args.password, + target=args.target, username=args.username, password=args.password, token=args.token, path_cert=args.path_cert, path_key=args.path_key, path_root=args.path_root, override=args.override, insecure=args.insecure, debug=args.debug, show_diff=args.compare, skip_verify=args.skip_verify