Skip to content

Commit

Permalink
0.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
akarneliuk committed Nov 9, 2020
1 parent fcf54db commit 688a48b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ By using the pyGNMI tool you agree with `the license <LICENSE.txt>`_.
Dev Log
=======

Release **0.2.5**:

- Added typing hints

Release **0.2.4**:

- Minor bugfixing
Expand Down Expand Up @@ -117,7 +121,7 @@ Release **0.1.0**:

- The first release.

.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.2.3&color=success
.. |version| image:: https://img.shields.io/static/v1?label=latest&message=v0.2.5&color=success
.. _version: https://pypi.org/project/pygnmi/
.. |tag| image:: https://img.shields.io/static/v1?label=status&message=in%20development&color=yellow
.. _tag: https://pypi.org/project/pygnmi/
Expand Down
Binary file added dist/pygnmi-0.2.4.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion pygnmi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#(c)2020, Anton Karneliuk

__version__ = '0.2.4'
__version__ = '0.2.5'
42 changes: 36 additions & 6 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Modules
import grpc
from pygnmi.spec.gnmi_pb2_grpc import gNMIStub
from pygnmi.spec.gnmi_pb2 import CapabilityRequest, GetRequest, SetRequest, Update, TypedValue
from pygnmi.spec.gnmi_pb2 import CapabilityRequest, GetRequest, SetRequest, Update, TypedValue, SubscribeRequest, Poll, Subscription, SubscriptionList, SubscriptionMode, Alias, AliasList
import re
import sys
import json
Expand All @@ -20,7 +20,8 @@ class gNMIclient(object):
"""
This class instantiates the object, which interacts with the network elements over gNMI.
"""
def __init__(self, target, username=None, password=None, to_print=False, insecure=False, path_cert=None):
def __init__(self, target: tuple, username: str = None, password: str = None,
to_print: bool = False, insecure: bool = False, path_cert: str = None):
"""
Initializing the object
"""
Expand Down Expand Up @@ -65,7 +66,8 @@ def __enter__(self):

def capabilities(self):
"""
Collecting the gNMI capabilities of the network device
Collecting the gNMI capabilities of the network device.
There are no arguments needed for this call
"""
logging.info(f'Collecting Capabilities...')

Expand Down Expand Up @@ -105,10 +107,18 @@ def capabilities(self):
return None


def get(self, path, datatype='all'):
def get(self, path: list, datatype: str = 'all'):
"""
Collecting the information about the resources from defined paths.
Path is provided as a list in format: ['yang-module:container/container[key=value]', 'yang-module:container/container[key=value]', ..]
Path is provided as a list in the following format:
path = ['yang-module:container/container[key=value]', 'yang-module:container/container[key=value]', ..]
The datatype argument may have the following value per gNMI specification:
- all
- config
- state
- operational
"""
logging.info(f'Collecting info from requested paths (Get opertaion)...')

Expand Down Expand Up @@ -204,10 +214,21 @@ def get(self, path, datatype='all'):
return None


def set(self, delete=None, replace=None, update=None):
def set(self, delete: list = None, replace: list = None, update: list = None):
"""
Changing the configuration on the destination network elements.
Could provide a single attribute or multiple attributes.
delete:
- list of paths with the resources to delete. The format is the same as for get() request
replace:
- list of tuples where the first entry path provided as a string, and the second entry
is a dictionary with the configuration to be configured
replace:
- list of tuples where the first entry path provided as a string, and the second entry
is a dictionary with the configuration to be configured
"""
del_protobuf_paths = []
replace_msg = []
Expand Down Expand Up @@ -319,5 +340,14 @@ def set(self, delete=None, replace=None, update=None):
return None


def subscribe(self, subscribe: list = None, poll: bool = False, aliases: list = None):
"""
Implentation of the subsrcibe gNMI RPC to pool
"""
logging.info(f'Collecting Capabilities...')

raise NotImplementedError


def __exit__(self, type, value, traceback):
self.__channel.close()
2 changes: 1 addition & 1 deletion pygnmi/path_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re

# User-defined functions
def gnmi_path_generator(path_in_question):
def gnmi_path_generator(path_in_question: list):
gnmi_path = Path()
keys = []
temp_path = ''
Expand Down
3 changes: 3 additions & 0 deletions pygnmicli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@

result = GC.set(delete=deletes, update=updates, replace=replaces)

elif DD.operation == 'subscribe':
GC.subscribe()

if result:
print(result)

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', 'pygnmi.artefacts'],
version = '0.2.4',
version = '0.2.5',
license='bsd-3-clause',
description = 'This repository contains pure Python implementation of the gNMI client to interact with the network functions.',
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.2.4.tar.gz',
download_url = 'https://github.com/akarneliuk/pygnmi/archive/v0.2.5.tar.gz',
keywords = ['gnmi', 'automation', 'grpc', 'network'],
install_requires=[
'grpcio',
Expand Down

0 comments on commit 688a48b

Please sign in to comment.