32
32
33
33
class XEClient (Client ):
34
34
"""IOS XE-specific wrapper for gNMI functionality.
35
+ Assumes IOS XE 16.12+
35
36
36
37
Returns direct responses from base Client methods.
37
38
@@ -62,17 +63,17 @@ class XEClient(Client):
62
63
>>> capabilities = client.capabilities()
63
64
>>> print(capabilities)
64
65
...
65
- >>> get_response = client.get_xpaths('interfaces/interface')
66
+ >>> get_response = client.get_xpaths('/ interfaces/interface')
66
67
>>> print(get_response)
67
68
...
68
- >>> subscribe_response = client.subscribe_xpaths('interfaces/interface')
69
+ >>> subscribe_response = client.subscribe_xpaths('/ interfaces/interface')
69
70
>>> for message in subscribe_response: print(message)
70
71
...
71
- >>> config = '{"Cisco-IOS-XR-shellutil-cfg:host-names ": [{"host-name ": "gnmi_test"}] }'
72
+ >>> config = '{"Cisco-IOS-XE-native:native ": {"hostname ": "gnmi_test"}}'
72
73
>>> set_response = client.set_json(config)
73
74
>>> print(set_response)
74
75
...
75
- >>> delete_response = client.delete_xpaths('Cisco-IOS-XR-shellutil-cfg:host-names/host-name ')
76
+ >>> delete_response = client.delete_xpaths('/ Cisco-IOS-XE-native:native/hostname ')
76
77
"""
77
78
78
79
def delete_xpaths (self , xpaths , prefix = None ):
@@ -200,12 +201,20 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
200
201
[ALL, CONFIG, STATE, OPERATIONAL]
201
202
encoding : proto.gnmi_pb2.GetRequest.Encoding, optional
202
203
A direct value or key from the Encoding enum
203
- [JSON, BYTES, PROTO, ASCII, JSON_IETF]
204
+ [JSON, JSON_IETF]
204
205
205
206
Returns
206
207
-------
207
208
get()
208
209
"""
210
+ supported_encodings = ["JSON" , "JSON_IETF" ]
211
+ encoding = util .validate_proto_enum (
212
+ "encoding" ,
213
+ encoding ,
214
+ "Encoding" ,
215
+ proto .gnmi_pb2 .Encoding ,
216
+ supported_encodings ,
217
+ )
209
218
gnmi_path = None
210
219
if isinstance (xpaths , (list , set )):
211
220
gnmi_path = map (self .parse_xpath_to_gnmi_path , set (xpaths ))
@@ -220,11 +229,8 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
220
229
def subscribe_xpaths (
221
230
self ,
222
231
xpath_subscriptions ,
223
- request_mode = "STREAM" ,
224
- sub_mode = "SAMPLE" ,
225
232
encoding = "JSON_IETF" ,
226
233
sample_interval = Client ._NS_IN_S * 10 ,
227
- suppress_redundant = False ,
228
234
heartbeat_interval = None ,
229
235
):
230
236
"""A convenience wrapper of subscribe() which aids in building of SubscriptionRequest
@@ -242,29 +248,12 @@ def subscribe_xpaths(
242
248
to SubscriptionRequest. Strings are parsed as XPaths and defaulted with the default arguments,
243
249
dictionaries are treated as dicts of args to pass to the Subscribe init, and Subscription is
244
250
treated as simply a pre-made Subscription.
245
- request_mode : proto.gnmi_pb2.SubscriptionList.Mode, optional
246
- Indicates whether STREAM to stream from target,
247
- ONCE to stream once (like a get),
248
- POLL to respond to POLL.
249
- [STREAM]
250
- sub_mode : proto.gnmi_pb2.SubscriptionMode, optional
251
- The default SubscriptionMode on a per Subscription basis in the SubscriptionList.
252
- TARGET_DEFINED indicates that the target (like device/destination) should stream
253
- information however it knows best. This instructs the target to decide between ON_CHANGE
254
- or SAMPLE - e.g. the device gNMI server may understand that we only need RIB updates
255
- as an ON_CHANGE basis as opposed to SAMPLE, and we don't have to explicitly state our
256
- desired behavior.
257
- ON_CHANGE only streams updates when changes occur.
258
- SAMPLE will stream the subscription at a regular cadence/interval.
259
- [SAMPLE]
260
251
encoding : proto.gnmi_pb2.Encoding, optional
261
252
A member of the proto.gnmi_pb2.Encoding enum specifying desired encoding of returned data
262
253
[JSON, JSON_IETF]
263
254
sample_interval : int, optional
264
255
Default nanoseconds for sample to occur.
265
256
Defaults to 10 seconds.
266
- suppress_redundant : bool, optional
267
- Indicates whether values that have not changed should be sent in a SAMPLE subscription.
268
257
heartbeat_interval : int, optional
269
258
Specifies the maximum allowable silent period in nanoseconds when
270
259
suppress_redundant is in use. The target should send a value at least once
@@ -274,9 +263,9 @@ def subscribe_xpaths(
274
263
-------
275
264
subscribe()
276
265
"""
277
- supported_request_modes = [ "STREAM" ]
266
+ request_mode = "STREAM"
278
267
supported_encodings = ["JSON" , "JSON_IETF" ]
279
- supported_sub_modes = [ "SAMPLE" ]
268
+ sub_mode = "SAMPLE"
280
269
subscription_list = proto .gnmi_pb2 .SubscriptionList ()
281
270
subscription_list .mode = util .validate_proto_enum (
282
271
"mode" ,
0 commit comments