Skip to content

Commit

Permalink
Merge pull request #77 from cisco-ie/revert-76-revert-75-rel-v1.0.12
Browse files Browse the repository at this point in the history
Release v1.0.13 (Fixed v1.0.12)
  • Loading branch information
remingtonc authored Jul 17, 2020
2 parents 1b4c0ea + a8f59bf commit 5aa1aab
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/cisco_gnmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
from .xe import XEClient
from .builder import ClientBuilder

__version__ = "1.0.11"
__version__ = "1.0.13"
8 changes: 8 additions & 0 deletions src/cisco_gnmi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def gnmi_subscribe():
default="SAMPLE",
choices=proto.gnmi_pb2.SubscriptionMode.keys(),
)
parser.add_argument(
"-req_mode",
help="SubscriptionList.Mode mode for Subscriptions. Defaults to STREAM.",
default="STREAM",
choices=proto.gnmi_pb2.SubscriptionList.Mode.keys(),
)
parser.add_argument(
"-suppress_redundant",
help="Suppress redundant information in Subscription.",
Expand Down Expand Up @@ -159,6 +165,8 @@ def gnmi_subscribe():
kwargs["sample_interval"] = args.interval * int(1e9)
if args.mode:
kwargs["sub_mode"] = args.mode
if args.req_mode:
kwargs["request_mode"] = args.req_mode
if args.suppress_redundant:
kwargs["suppress_redundant"] = args.suppress_redundant
if args.heartbeat_interval:
Expand Down
5 changes: 3 additions & 2 deletions src/cisco_gnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def subscribe_xpaths(
sample_interval=_NS_IN_S * 10,
suppress_redundant=False,
heartbeat_interval=None,
prefix=None
prefix=None,
):
"""A convenience wrapper of subscribe() which aids in building of SubscriptionRequest
with request as subscribe SubscriptionList. This method accepts an iterable of simply xpath strings,
Expand Down Expand Up @@ -408,7 +408,8 @@ def subscribe_xpaths(
subscription_list.subscription.extend(subscriptions)
return self.subscribe([subscription_list])

def parse_xpath_to_gnmi_path(self, xpath, origin=None):
@classmethod
def parse_xpath_to_gnmi_path(cls, xpath, origin=None):
"""Parses an XPath to proto.gnmi_pb2.Path.
This function should be overridden by any child classes for origin logic.
Expand Down
28 changes: 20 additions & 8 deletions src/cisco_gnmi/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class NXClient(Client):
>>> capabilities = client.capabilities()
>>> print(capabilities)
"""

def delete_xpaths(self, xpaths, prefix=None):
"""A convenience wrapper for set() which constructs Paths from supplied xpaths
to be passed to set() as the delete parameter.
Expand Down Expand Up @@ -90,7 +91,13 @@ def delete_xpaths(self, xpaths, prefix=None):
paths.append(self.parse_xpath_to_gnmi_path(xpath))
return self.set(deletes=paths)

def set_json(self, update_json_configs=None, replace_json_configs=None, ietf=False, prefix=None):
def set_json(
self,
update_json_configs=None,
replace_json_configs=None,
ietf=False,
prefix=None,
):
"""A convenience wrapper for set() which assumes JSON payloads and constructs desired messages.
All parameters are optional, but at least one must be present.
Expand Down Expand Up @@ -289,20 +296,25 @@ def subscribe_xpaths(
heartbeat_interval,
)

def parse_xpath_to_gnmi_path(self, xpath, origin=None):
@classmethod
def parse_xpath_to_gnmi_path(cls, xpath, origin=None):
"""Attempts to determine whether origin should be YANG (device) or DME.
"""
if origin is None:
if any(
map(xpath.startswith, [
"Cisco-NX-OS-device",
"/Cisco-NX-OS-device",
"cisco-nx-os-device",
"/cisco-nx-os-device"])
map(
xpath.startswith,
[
"Cisco-NX-OS-device",
"/Cisco-NX-OS-device",
"cisco-nx-os-device",
"/cisco-nx-os-device",
],
)
):
origin = "device"
# Remove the module
xpath = xpath.split(":", 1)[1]
else:
origin = "openconfig"
return super(NXClient, self).parse_xpath_to_gnmi_path(xpath, origin)
return super(NXClient, cls).parse_xpath_to_gnmi_path(xpath, origin)
9 changes: 5 additions & 4 deletions src/cisco_gnmi/xe.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def subscribe_xpaths(
sample_interval=Client._NS_IN_S * 10,
suppress_redundant=False,
heartbeat_interval=None,
prefix=None
prefix=None,
):
"""A convenience wrapper of subscribe() which aids in building of SubscriptionRequest
with request as subscribe SubscriptionList. This method accepts an iterable of simply xpath strings,
Expand Down Expand Up @@ -309,10 +309,11 @@ def subscribe_xpaths(
sample_interval,
suppress_redundant,
heartbeat_interval,
prefix
prefix,
)

def parse_xpath_to_gnmi_path(self, xpath, origin=None):
@classmethod
def parse_xpath_to_gnmi_path(cls, xpath, origin=None):
"""Naively tries to intelligently (non-sequitur!) origin
Otherwise assume rfc7951
legacy is not considered
Expand All @@ -323,4 +324,4 @@ def parse_xpath_to_gnmi_path(self, xpath, origin=None):
origin = "openconfig"
else:
origin = "rfc7951"
return super(XEClient, self).parse_xpath_to_gnmi_path(xpath, origin)
return super(XEClient, cls).parse_xpath_to_gnmi_path(xpath, origin)
8 changes: 5 additions & 3 deletions src/cisco_gnmi/xr.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def subscribe_xpaths(
heartbeat_interval,
)

def parse_xpath_to_gnmi_path(self, xpath, origin=None):
@classmethod
def parse_xpath_to_gnmi_path(cls, xpath, origin=None):
"""No origin specified implies openconfig
Otherwise origin is expected to be the module name
"""
Expand All @@ -351,9 +352,10 @@ def parse_xpath_to_gnmi_path(self, xpath, origin=None):
# module name
origin, xpath = xpath.split(":", 1)
origin = origin.strip("/")
return super(XRClient, self).parse_xpath_to_gnmi_path(xpath, origin)
return super(XRClient, cls).parse_xpath_to_gnmi_path(xpath, origin)

def parse_cli_to_gnmi_path(self, command):
@classmethod
def parse_cli_to_gnmi_path(cls, command):
"""Parses a CLI command to proto.gnmi_pb2.Path.
IOS XR appears to be the only OS with this functionality.
Expand Down

0 comments on commit 5aa1aab

Please sign in to comment.