Skip to content

Commit

Permalink
Merge pull request #86 from akarneliuk/0.8.4
Browse files Browse the repository at this point in the history
0.8.4
  • Loading branch information
akarneliuk authored Jul 28, 2022
2 parents 009bb6f + ea7f615 commit 886b63d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

=======
Expand All @@ -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 <https://github.com/akarneliuk/pygnmi/issues/83>`_.
Expand Down Expand Up @@ -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/
Expand Down
11 changes: 9 additions & 2 deletions pygnmi/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
Expand Down Expand Up @@ -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
12 changes: 9 additions & 3 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
"""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scripts/pygnmicli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 886b63d

Please sign in to comment.