Skip to content

Commit

Permalink
Merge pull request #84 from akarneliuk/0.8.3
Browse files Browse the repository at this point in the history
0.8.3
  • Loading branch information
akarneliuk authored Jul 24, 2022
2 parents 2e7b381 + b2f6cff commit 009bb6f
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 155 deletions.
6 changes: 5 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ setup.py
pygnmi/__init__.py
pygnmi/arg_parser.py
pygnmi/client.py
pygnmi/path_generator.py
pygnmi/create_gnmi_extension.py
pygnmi/create_gnmi_path.py
pygnmi/tools.py
pygnmi/artefacts/messages.py
pygnmi/spec/v080/gnmi_ext_pb2.py
pygnmi/spec/v080/gnmi_pb2.py
pygnmi/spec/v080/gnmi_pb2_grpc.py
scripts/pygnmicli
14 changes: 11 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ Tested Network Operating Systems (NOS)
- Nokia SR OS
- Cisco IOS XR
- Juniper JUNOS
- Nokia SRLinux

Network Operating Systems (NOS) in test
---------------------------------------
- Nokia SRLinux
- Cisco Nexus
- Broadcom SONiC

=======
License
Expand All @@ -79,11 +80,18 @@ Contributors
- `Jeroen van Bemme <https://github.com/jbemmel>`_
- `Frédéric Perrin <https://github.com/fperrin>`_
- `Malanovo <https://github.com/malanovo>`_
- `Sebastian Lohff <https://github.com/sebageek>`_

=======
Dev Log
=======

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>`_.
- Uppdated documentation with examples in GitHub.
- Added support of History extensions to ``pygnmicli``.

Release **0.8.2**:

- Implemented `History Extension <https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-history.md#1-purpose>`_.
Expand Down Expand Up @@ -377,13 +385,13 @@ Release **0.1.0**:

(c)2020-2022, karneliuk.com

.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.2&color=success
.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.8.3&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/
.. |license| image:: https://img.shields.io/static/v1?label=license&message=BSD-3-clause&color=success
.. _license: https://github.com/akarneliuk/pygnmi/blob/master/LICENSE.txt
.. |project| image:: https://img.shields.io/badge/akarneliuk%2Fpygnmi-blueviolet.svg?logo=github&color=success
.. _project: https://github.com/akarneliuk/pygnmi/
.. |coverage| image:: https://img.shields.io/static/v1?label=coverage&message=71%&color=yellow
.. |coverage| image:: https://img.shields.io/static/v1?label=coverage&message=66%&color=yellow
.. _coverage: https://github.com/nedbat/coveragepy
22 changes: 22 additions & 0 deletions examples/pure_python/autehentication_with_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""This example shows how to authenticate against the device
using token instead of username/password"""
# Modules
from pygnmi.client import gNMIclient

# Variables
from inventory import hosts

# Body
if __name__ == "__main__":

# Get Token
with open("token.tok") as f:
TOKEN = f.read().strip('\n')

for host in hosts:
with gNMIclient(target=(host["ip_address"], host["port"]),
token=TOKEN, skip_verify=False) as gc:

result = gc.capabilities()

print(f"{host['ip_address']}: {result}\n\n")
138 changes: 0 additions & 138 deletions examples/pure_python/subscribe_tls.log

This file was deleted.

38 changes: 38 additions & 0 deletions examples/pure_python/subscribe_with_history_extension_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""This example shows how to use the History extension
with range option
Per GNMI spec, /extension/history/range requires
`STREAM` mode of telemetery subscription"""
# Modules
from pygnmi.client import gNMIclient


# Variables
TELEMETRY_REQUEST2 = {
'subscription': [
{
'path': 'openconfig:/interfaces/interface/state/counters',
'mode': 'target_defined'
}
],
'mode': 'stream',
'encoding': 'proto'
}

EXTENSION2 = {
'history': {
'range': {
'start': '2022-07-23T09:47:00Z',
'end': '2022-07-24T8:57:00Z'
}
}
}


# Body
with open("token.tok") as f:
TOKEN = f.read().strip('\n')

with gNMIclient(target=('192.168.0.5', '443'), token=TOKEN, skip_verify=True) as gconn:
for item in gconn.subscribe2(subscribe=TELEMETRY_REQUEST2, target="leaf1", extension=EXTENSION2):
print(item)
35 changes: 35 additions & 0 deletions examples/pure_python/subscribe_with_history_extension_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""This example shows how to use the History extension
with snapshit_time option.
Per GNMI spec, /extension/history/snapshot_time requires
`ONCE` mode of telemetery subscription"""
# Modules
from pygnmi.client import gNMIclient


# Variables

TELEMETRY_REQUEST1 = {
'subscription': [
{
'path': 'openconfig:/interfaces/interface[name=Ethernet2]/state/counters',
'mode': 'target_defined'
}
],
'mode': 'once',
'encoding': 'proto'
}

EXTENSION1 = {
'history': {
'snapshot_time': '2022-07-24T8:57:00Z'
}
}

# Body
with open("token.tok") as f:
TOKEN = f.read().strip('\n')

with gNMIclient(target=('192.168.0.5', '443'), token=TOKEN, skip_verify=True) as gconn:
for item in gconn.subscribe2(subscribe=TELEMETRY_REQUEST1, target="leaf1", extension=EXTENSION1):
print(item)
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.2"
__version__ = "0.8.3"
31 changes: 26 additions & 5 deletions pygnmi/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def parse_args(msg):
dest="password"
)
parser.add_argument(
"-c", "--path_cert",
"-c", "--path-cert",
type=str,
required=False,
help="Path to certificate chain file",
)
parser.add_argument(
"-k", "--path_key",
"-k", "--path-key",
type=str,
required=False,
help="Path to private key file"
)
parser.add_argument(
"-r", "--path_root",
"-r", "--path-root",
type=str,
required=False,
help="Path to root CA file"
Expand Down Expand Up @@ -83,14 +83,14 @@ def parse_args(msg):
help="gNMI Request type",
)
parser.add_argument(
"-x", "--gnmi_path",
"-x", "--gnmi-path",
type=str,
required=False,
default="", nargs="+",
help="gNMI paths of interest in XPath format, space separated"
)
parser.add_argument(
"--gnmi_path_target",
"--gnmi-path-target",
type=str,
required=False,
default="",
Expand Down Expand Up @@ -126,6 +126,27 @@ def parse_args(msg):
default="",
help="Compare the states of the devices before and after change to show difference",
)
parser.add_argument(
"--ext-history-range-start",
type=str,
required=False,
default="",
help="Specify the start timestamp for the GNMI history range",
)
parser.add_argument(
"--ext-history-range-end",
type=str,
required=False,
default="",
help="Specify the end timestamp for the GNMI history range",
)
parser.add_argument(
"--ext-history-snapshot-time",
type=str,
required=False,
default="",
help="Specify the snapshit time for the GNMI history",
)

args = parser.parse_args()

Expand Down
8 changes: 6 additions & 2 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens
raise ValueError('Subscribe subscribe request is specified, but the value is not dict.')

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

# use_alias
if 'use_aliases' not in subscribe:
Expand Down Expand Up @@ -799,7 +799,11 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens
request.subscription.add(path=se_path, mode=se_mode, sample_interval=se_sample_interval,
suppress_redundant=se_suppress_redundant, heartbeat_interval=se_heartbeat_interval)

return SubscribeRequest(subscribe=request, extension=gnmi_extension)
if gnmi_extension:
return SubscribeRequest(subscribe=request, extension=[gnmi_extension])

else:
return SubscribeRequest(subscribe=request)

def subscribe(self, subscribe: dict = None, poll: bool = False, aliases: list = None, timeout: float = 0.0):
"""
Expand Down
Loading

0 comments on commit 009bb6f

Please sign in to comment.