Skip to content

Commit 569f667

Browse files
authored
Merge pull request #91 from akarneliuk/0.8.6
0.8.6
2 parents 5739126 + 18337c7 commit 569f667

File tree

5 files changed

+56
-38
lines changed

5 files changed

+56
-38
lines changed

README.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ Contributors
8686
Dev Log
8787
=======
8888

89+
Release **0.8.6**:
90+
91+
- Fixed minor issue with establishing ``insecure`` channel.
92+
- Fixed bug with inabillity to specify ``prefix`` in Subscribe messages for ``subscribe2()`` method.
93+
- **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.
94+
- Functionality ``qos`` is now properly supported in ``subscribe2()`` method.
95+
8996
Release **0.8.5**:
9097

91-
- Fixed some issues with telemetry represenation with ``pygnmicli``.
98+
- Fixed some issues with telemetry representation with ``pygnmicli``.
9299

93100
Release **0.8.4**:
94101

@@ -394,7 +401,7 @@ Release **0.1.0**:
394401

395402
(c)2020-2022, karneliuk.com
396403

397-
.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.4&color=success
404+
.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.6&color=success
398405
.. _version: https://pypi.org/project/pygnmi/
399406
.. |tag| image:: https://img.shields.io/static/v1?label=status&message=stable&color=success
400407
.. _tag: https://pypi.org/project/pygnmi/

pygnmi/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
pyGNMI module to manage network devices with gNMI
33
(c)2020-2022, Karneliuk
44
"""
5-
__version__ = "0.8.5"
5+
__version__ = "0.8.6"

pygnmi/client.py

+40-32
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import grpc
1515
from pygnmi.spec.v080.gnmi_pb2_grpc import gNMIStub
1616
from pygnmi.spec.v080.gnmi_pb2 import (CapabilityRequest, Encoding, GetRequest,\
17-
SetRequest, Update, TypedValue, SubscribeRequest, Poll, SubscriptionList,\
17+
SetRequest, Subscription, Update, TypedValue, SubscribeRequest, Poll, SubscriptionList,\
1818
SubscriptionMode, AliasList, UpdateResult)
1919

2020

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

236236
except grpc.FutureTimeoutError:
237-
logger.error("Failed to setup gRPC channel, trying change cipher")
237+
if not self.__insecure:
238+
logger.error("Failed to setup gRPC channel, trying change cipher")
238239

239-
try:
240-
os.environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH"
241-
grpc.channel_ready_future(self.__channel).result(timeout=timeout)
240+
try:
241+
os.environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH"
242+
grpc.channel_ready_future(self.__channel).result(timeout=timeout)
243+
244+
except grpc.FutureTimeoutError:
245+
raise
242246

243-
except grpc.FutureTimeoutError:
247+
else:
244248
raise
245249

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

696-
request = SubscriptionList()
697700
gnmi_extension = get_gnmi_extension(ext=extension)
698701

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

703-
if isinstance(subscribe['use_aliases'], bool):
704-
request.use_aliases = subscribe['use_aliases']
705-
else:
706+
if not isinstance(subscribe['use_aliases'], bool):
706707
raise ValueError('Subsricbe use_aliases should have boolean type.')
707708

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

712713
if subscribe['mode'].lower() in {'stream', 'once', 'poll'}:
713714
if subscribe['mode'].lower() == 'stream':
714-
request.mode = 0
715+
subscribe_mode = 0
715716
elif subscribe['mode'].lower() == 'once':
716-
request.mode = 1
717+
subscribe_mode = 1
717718
elif subscribe['mode'].lower() == 'poll':
718-
request.mode = 2
719+
subscribe_mode = 2
719720
else:
720721
raise ValueError('Subscribe mode is out of allowed ranges.')
721722

722723
# allow_aggregation
723724
if 'allow_aggregation' not in subscribe:
724725
subscribe.update({'allow_aggregation': False})
725726

726-
if isinstance(subscribe['allow_aggregation'], bool):
727-
request.allow_aggregation = subscribe['allow_aggregation']
728-
else:
727+
if not isinstance(subscribe['allow_aggregation'], bool):
729728
raise ValueError('Subsricbe allow_aggregation should have boolean type.')
730729

731730
# updates_only
732731
if 'updates_only' not in subscribe:
733732
subscribe.update({'updates_only': False})
734733

735-
if isinstance(subscribe['updates_only'], bool):
736-
request.updates_only = subscribe['updates_only']
737-
else:
734+
if not isinstance(subscribe['updates_only'], bool):
738735
raise ValueError('Subsricbe updates_only should have boolean type.')
739736

740737
# encoding
741738
if 'encoding' not in subscribe:
742739
subscribe.update({'encoding': 'proto'})
743740

744-
if subscribe['encoding'].upper() in Encoding.keys():
745-
request.encoding = Encoding.Value(subscribe['encoding'].upper())
746-
else:
741+
if subscribe['encoding'].upper() not in Encoding.keys():
747742
raise ValueError(f'Subscribe encoding {subscribe["encoding"]} is out of allowed ranges.')
748743

749744
# qos
750-
if 'qos' not in subscribe:
751-
subscribe.update({'qos': 0})
745+
if 'qos' not in subscribe or not subscribe["qos"]:
746+
subscribe.update({'qos': {'marking': 0}})
752747

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

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

767-
# It is weird that it is not possible to assign prefix directly as earlier
768-
request.prefix.target = gnmi_path_generator(subscribe['prefix'], target).target
769-
request.prefix.origin = gnmi_path_generator(subscribe['prefix'], target).origin
766+
# Create message for eveyrhting besides subscriptions
767+
request = SubscriptionList(prefix=gnmi_path_generator(subscribe['prefix'], target),
768+
use_aliases=subscribe['use_aliases'],
769+
qos=subscribe['qos'],
770+
mode=subscribe_mode,
771+
allow_aggregation=subscribe['allow_aggregation'],
772+
use_models=subscribe['use_models'],
773+
encoding=Encoding.Value(subscribe['encoding'].upper()),
774+
updates_only=subscribe['updates_only'])
770775

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

805-
request.subscription.add(path=se_path, mode=se_mode, sample_interval=se_sample_interval,
806-
suppress_redundant=se_suppress_redundant, heartbeat_interval=se_heartbeat_interval)
810+
request.subscription.add(path=se_path,
811+
mode=se_mode,
812+
sample_interval=se_sample_interval,
813+
suppress_redundant=se_suppress_redundant,
814+
heartbeat_interval=se_heartbeat_interval)
807815

808816
if gnmi_extension:
809817
return SubscribeRequest(subscribe=request, extension=[gnmi_extension])
@@ -886,7 +894,7 @@ def subscribe_poll(self, subscribe: dict, target: str = None, extension: list =
886894
subscribe['mode'] = 'POLL'
887895
gnmi_message_request = self._build_subscriptionrequest(subscribe, target, extension)
888896
debug_gnmi_msg(self.__debug, gnmi_message_request, "gNMI request")
889-
897+
890898
return PollSubscriber(self.__channel, gnmi_message_request, self.__metadata)
891899

892900
def subscribe_once(self, subscribe: dict, target: str = None, extension: list = None):

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
setup(
77
name='pygnmi',
88
packages=['pygnmi', 'pygnmi.spec.v080', 'pygnmi.artefacts'],
9-
version='0.8.5',
9+
version='0.8.6',
1010
license='bsd-3-clause',
1111
description='Pure Python gNMI client to manage network functions and collect telemetry.',
1212
long_description=long_description,
1313
long_description_content_type='text/x-rst',
1414
author='Anton Karneliuk',
1515
author_email='anton@karneliuk.com',
1616
url='https://github.com/akarneliuk/pygnmi',
17-
download_url='https://github.com/akarneliuk/pygnmi/archive/v0.8.5.tar.gz',
17+
download_url='https://github.com/akarneliuk/pygnmi/archive/v0.8.6.tar.gz',
1818
keywords=['gnmi', 'automation', 'grpc', 'network'],
1919
install_requires=[
2020
'grpcio',

tests/messages.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
'sample_interval': 10000000000,
4545
'heartbeat_interval': 30000000000
4646
}
47-
],
47+
],
48+
'qos': {
49+
'marking': 32
50+
},
4851
'use_aliases': False,
4952
'mode': 'once',
5053
'encoding': 'proto'

0 commit comments

Comments
 (0)