Skip to content

Commit

Permalink
Merge pull request #97 from akarneliuk/0.8.9
Browse files Browse the repository at this point in the history
0.8.9
  • Loading branch information
akarneliuk committed Aug 21, 2022
2 parents 3e006c3 + a6d05e5 commit 4e00513
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ Contributors
Dev Log
=======

Release **0.8.9**:

- Default value for ``encoding`` everywhere is set to ``None``.
- Method ``capabilities()`` now is called as part of ``connect()`` to collect supported encoding as part of session establishing.
- If ``encoding`` is not specified by user, then it is auto-set based on the list collected via ``capabilites()`` with ``json`` having the first priority follwed by ``json_ietf``.

Release **0.8.8**:

- Added new argument ``-e / --encoding`` to ``pygnmicli`` to specify the encoding, which overrides the default one. Fix for `Issue 58 <https://github.com/akarneliuk/pygnmi/issues/58>`_.
Expand Down Expand Up @@ -411,7 +417,7 @@ Release **0.1.0**:

(c)2020-2022, karneliuk.com

.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.7&color=success
.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.9&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
2 changes: 1 addition & 1 deletion pygnmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
pyGNMI module to manage network devices with gNMI
(c)2020-2022, Karneliuk
"""
__version__ = "0.8.8"
__version__ = "0.8.9"
6 changes: 6 additions & 0 deletions pygnmi/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ def parse_args(msg):
required=False,
help="Specify the snapshit time for the GNMI history",
)
parser.add_argument(
"--gnmi-timeout",
type=int,
required=False,
help="Specify the timeout for GNMI session",
)

args = parser.parse_args()

Expand Down
29 changes: 21 additions & 8 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def connect(self, timeout: int = None):

# Set empty override if neither CN ans SARs exist
if not ssl_cert_common_name and not self.__cert_sans:
self.__options.append(("grpc.ssl_target_name_override", "".encode(encoding="utf-8")))
self.__options.append(("grpc.ssl_target_name_override", ""))

logger.warning('ssl_target_name_override is applied, should be used for testing only!')

Expand Down Expand Up @@ -225,6 +225,8 @@ def connect(self, timeout: int = None):
self.wait_for_connect(timeout)
self.__stub = gNMIStub(self.__channel)

self.__capabilities = self.capabilities()

return self

def wait_for_connect(self, timeout: int):
Expand Down Expand Up @@ -293,7 +295,6 @@ def capabilities(self):

logger.info(f'Collection of Capabilities is successfull')

self.__capabilities = response
return response

except grpc._channel._InactiveRpcError as err:
Expand All @@ -307,7 +308,7 @@ def capabilities(self):

def get(self, prefix: str = "", path: list = None,
target: str = None, datatype: str = 'all',
encoding: str = 'json'):
encoding: str = None):
"""
Collecting the information about the resources from defined paths.
Expand Down Expand Up @@ -468,7 +469,7 @@ def get(self, prefix: str = "", path: list = None,
raise gNMIException(f'Collection of Get information failed: {e}', e)

def set(self, delete: list = None, replace: list = None,
update: list = None, encoding: str = 'json',
update: list = None, encoding: str = None,
prefix: str = "", target: str = None):
"""
Changing the configuration on the destination network elements.
Expand Down Expand Up @@ -497,9 +498,21 @@ def set(self, delete: list = None, replace: list = None,
update_msg = []
diff_list = []

if encoding.upper() not in Encoding.keys():
logger.error(f'The encoding {encoding} is not supported. The allowed are: {", ".join(Encoding.keys())}.')
raise gNMIException(f'The encoding {encoding} is not supported. The allowed are: {", ".join(Encoding.keys())}.')
# Set the encoding
if encoding:
if encoding.upper() not in Encoding.keys():
logger.error(f'The encoding {encoding} is not supported. The allowed are: {", ".join(Encoding.keys())}.')
raise gNMIException(f'The encoding {encoding} is not supported. The allowed are: {", ".join(Encoding.keys())}.')

else:
if "supported_encodings" in self.__capabilities and "json" in self.__capabilities['supported_encodings']:
encoding = "json"

elif "supported_encodings" in self.__capabilities and "json_ietf" in self.__capabilities['supported_encodings']:
encoding = "json_ietf"

else:
raise gNMIException('It is impossible to automtically detect encoding')

# Gnmi PREFIX
try:
Expand Down Expand Up @@ -611,7 +624,7 @@ def set(self, delete: list = None, replace: list = None,
raise gNMIException(f"Set failed: {e}", e)


def set_with_retry(self, delete: list = None, replace: list = None, update: list = None, encoding: str = 'json', retry_delay: int = 3):
def set_with_retry(self, delete: list = None, replace: list = None, update: list = None, encoding: str = None, retry_delay: int = 3):
"""
Performs a set and retries (once) after a temporary failure with StatusCode.FAILED_PRECONDITION
"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/pygnmicli
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
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
show_diff=args.compare, skip_verify=args.skip_verify, gnmi_timeout=args.gnmi_timeout
) as GC:

result = None
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
setup(
name='pygnmi',
packages=['pygnmi', 'pygnmi.spec.v080', 'pygnmi.artefacts'],
version='0.8.8',
version='0.8.9',
license='bsd-3-clause',
description='Pure Python gNMI client to manage network functions and collect telemetry.',
long_description=long_description,
long_description_content_type='text/x-rst',
author='Anton Karneliuk',
author_email='[email protected]',
url='https://github.com/akarneliuk/pygnmi',
download_url='https://github.com/akarneliuk/pygnmi/archive/v0.8.8.tar.gz',
download_url='https://github.com/akarneliuk/pygnmi/archive/v0.8.9.tar.gz',
keywords=['gnmi', 'automation', 'grpc', 'network'],
install_requires=[
'grpcio',
Expand Down

0 comments on commit 4e00513

Please sign in to comment.