Skip to content

Commit

Permalink
Merge pull request #91 from akarneliuk/0.8.6
Browse files Browse the repository at this point in the history
0.8.6
  • Loading branch information
akarneliuk authored Aug 9, 2022
2 parents 5739126 + 18337c7 commit 569f667
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 38 deletions.
11 changes: 9 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ Contributors
Dev Log
=======

Release **0.8.6**:

- Fixed minor issue with establishing ``insecure`` channel.
- Fixed bug with inabillity to specify ``prefix`` in Subscribe messages for ``subscribe2()`` method.
- **Important**: It is recommended to use method ``subscribe2()`` instead of ``subscribe()`` for building telemetry collectors with ``pygnmi`` as this method is further developed and throroughle tested. The method ``subscribe()`` will be deprecated in future releases.
- Functionality ``qos`` is now properly supported in ``subscribe2()`` method.

Release **0.8.5**:

- Fixed some issues with telemetry represenation with ``pygnmicli``.
- Fixed some issues with telemetry representation with ``pygnmicli``.

Release **0.8.4**:

Expand Down Expand Up @@ -394,7 +401,7 @@ Release **0.1.0**:

(c)2020-2022, karneliuk.com

.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.4&color=success
.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.6&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.5"
__version__ = "0.8.6"
72 changes: 40 additions & 32 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import grpc
from pygnmi.spec.v080.gnmi_pb2_grpc import gNMIStub
from pygnmi.spec.v080.gnmi_pb2 import (CapabilityRequest, Encoding, GetRequest,\
SetRequest, Update, TypedValue, SubscribeRequest, Poll, SubscriptionList,\
SetRequest, Subscription, Update, TypedValue, SubscribeRequest, Poll, SubscriptionList,\
SubscriptionMode, AliasList, UpdateResult)


Expand Down Expand Up @@ -234,13 +234,17 @@ def wait_for_connect(self, timeout: int):
grpc.channel_ready_future(self.__channel).result(timeout=timeout)

except grpc.FutureTimeoutError:
logger.error("Failed to setup gRPC channel, trying change cipher")
if not self.__insecure:
logger.error("Failed to setup gRPC channel, trying change cipher")

try:
os.environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH"
grpc.channel_ready_future(self.__channel).result(timeout=timeout)
try:
os.environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH"
grpc.channel_ready_future(self.__channel).result(timeout=timeout)

except grpc.FutureTimeoutError:
raise

except grpc.FutureTimeoutError:
else:
raise

def capabilities(self):
Expand Down Expand Up @@ -693,16 +697,13 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens
if not isinstance(subscribe, dict):
raise ValueError('Subscribe subscribe request is specified, but the value is not dict.')

request = SubscriptionList()
gnmi_extension = get_gnmi_extension(ext=extension)

# use_alias
if 'use_aliases' not in subscribe:
subscribe.update({'use_aliases': False})

if isinstance(subscribe['use_aliases'], bool):
request.use_aliases = subscribe['use_aliases']
else:
if not isinstance(subscribe['use_aliases'], bool):
raise ValueError('Subsricbe use_aliases should have boolean type.')

# mode
Expand All @@ -711,47 +712,45 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens

if subscribe['mode'].lower() in {'stream', 'once', 'poll'}:
if subscribe['mode'].lower() == 'stream':
request.mode = 0
subscribe_mode = 0
elif subscribe['mode'].lower() == 'once':
request.mode = 1
subscribe_mode = 1
elif subscribe['mode'].lower() == 'poll':
request.mode = 2
subscribe_mode = 2
else:
raise ValueError('Subscribe mode is out of allowed ranges.')

# allow_aggregation
if 'allow_aggregation' not in subscribe:
subscribe.update({'allow_aggregation': False})

if isinstance(subscribe['allow_aggregation'], bool):
request.allow_aggregation = subscribe['allow_aggregation']
else:
if not isinstance(subscribe['allow_aggregation'], bool):
raise ValueError('Subsricbe allow_aggregation should have boolean type.')

# updates_only
if 'updates_only' not in subscribe:
subscribe.update({'updates_only': False})

if isinstance(subscribe['updates_only'], bool):
request.updates_only = subscribe['updates_only']
else:
if not isinstance(subscribe['updates_only'], bool):
raise ValueError('Subsricbe updates_only should have boolean type.')

# encoding
if 'encoding' not in subscribe:
subscribe.update({'encoding': 'proto'})

if subscribe['encoding'].upper() in Encoding.keys():
request.encoding = Encoding.Value(subscribe['encoding'].upper())
else:
if subscribe['encoding'].upper() not in Encoding.keys():
raise ValueError(f'Subscribe encoding {subscribe["encoding"]} is out of allowed ranges.')

# qos
if 'qos' not in subscribe:
subscribe.update({'qos': 0})
if 'qos' not in subscribe or not subscribe["qos"]:
subscribe.update({'qos': {'marking': 0}})

# if subscribe['qos'] >= 0 and subscribe['qos'] <= 64:
# request.qos = QOSMarking(marking=subscribe['qos'])
else:
if not (isinstance(subscribe["qos"], dict) and\
"marking" in subscribe["qos"] and\
isinstance(subscribe["qos"]["marking"], int) and\
subscribe["qos"]["marking"] in list(range(0, 65))):
raise ValueError(f'Subscribe qos/marking {subscribe["qos"]["marking"]} is out of allowed ranges.')

# use_models
if 'use_models' not in subscribe:
Expand All @@ -764,9 +763,15 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens
if 'prefix' not in subscribe:
subscribe.update({'prefix': ""})

# It is weird that it is not possible to assign prefix directly as earlier
request.prefix.target = gnmi_path_generator(subscribe['prefix'], target).target
request.prefix.origin = gnmi_path_generator(subscribe['prefix'], target).origin
# Create message for eveyrhting besides subscriptions
request = SubscriptionList(prefix=gnmi_path_generator(subscribe['prefix'], target),
use_aliases=subscribe['use_aliases'],
qos=subscribe['qos'],
mode=subscribe_mode,
allow_aggregation=subscribe['allow_aggregation'],
use_models=subscribe['use_models'],
encoding=Encoding.Value(subscribe['encoding'].upper()),
updates_only=subscribe['updates_only'])

# subscription
if 'subscription' not in subscribe or not subscribe['subscription']:
Expand Down Expand Up @@ -802,8 +807,11 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens
else:
se_heartbeat_interval = 0

request.subscription.add(path=se_path, mode=se_mode, sample_interval=se_sample_interval,
suppress_redundant=se_suppress_redundant, heartbeat_interval=se_heartbeat_interval)
request.subscription.add(path=se_path,
mode=se_mode,
sample_interval=se_sample_interval,
suppress_redundant=se_suppress_redundant,
heartbeat_interval=se_heartbeat_interval)

if gnmi_extension:
return SubscribeRequest(subscribe=request, extension=[gnmi_extension])
Expand Down Expand Up @@ -886,7 +894,7 @@ def subscribe_poll(self, subscribe: dict, target: str = None, extension: list =
subscribe['mode'] = 'POLL'
gnmi_message_request = self._build_subscriptionrequest(subscribe, target, extension)
debug_gnmi_msg(self.__debug, gnmi_message_request, "gNMI request")

return PollSubscriber(self.__channel, gnmi_message_request, self.__metadata)

def subscribe_once(self, subscribe: dict, target: str = None, extension: list = 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.5',
version='0.8.6',
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.5.tar.gz',
download_url='https://github.com/akarneliuk/pygnmi/archive/v0.8.6.tar.gz',
keywords=['gnmi', 'automation', 'grpc', 'network'],
install_requires=[
'grpcio',
Expand Down
5 changes: 4 additions & 1 deletion tests/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
'sample_interval': 10000000000,
'heartbeat_interval': 30000000000
}
],
],
'qos': {
'marking': 32
},
'use_aliases': False,
'mode': 'once',
'encoding': 'proto'
Expand Down

0 comments on commit 569f667

Please sign in to comment.