diff --git a/src/cisco_gnmi/__init__.py b/src/cisco_gnmi/__init__.py index e0105ed..aa9fe07 100644 --- a/src/cisco_gnmi/__init__.py +++ b/src/cisco_gnmi/__init__.py @@ -30,4 +30,4 @@ from .xe import XEClient from .builder import ClientBuilder -__version__ = "1.0.11" +__version__ = "1.0.13" diff --git a/src/cisco_gnmi/cli.py b/src/cisco_gnmi/cli.py index bacfa8d..0ef42ab 100644 --- a/src/cisco_gnmi/cli.py +++ b/src/cisco_gnmi/cli.py @@ -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.", @@ -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: diff --git a/src/cisco_gnmi/client.py b/src/cisco_gnmi/client.py index 97949c0..8a32b3c 100755 --- a/src/cisco_gnmi/client.py +++ b/src/cisco_gnmi/client.py @@ -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, @@ -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. diff --git a/src/cisco_gnmi/nx.py b/src/cisco_gnmi/nx.py index 182b31e..7aa3655 100644 --- a/src/cisco_gnmi/nx.py +++ b/src/cisco_gnmi/nx.py @@ -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. @@ -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. @@ -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) diff --git a/src/cisco_gnmi/xe.py b/src/cisco_gnmi/xe.py index 139f9cd..3f63077 100644 --- a/src/cisco_gnmi/xe.py +++ b/src/cisco_gnmi/xe.py @@ -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, @@ -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 @@ -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) diff --git a/src/cisco_gnmi/xr.py b/src/cisco_gnmi/xr.py index e7cfb4d..c55d6e4 100644 --- a/src/cisco_gnmi/xr.py +++ b/src/cisco_gnmi/xr.py @@ -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 """ @@ -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.