@@ -222,7 +222,7 @@ def subscribe_xpaths(
222
222
xpath_subscriptions ,
223
223
request_mode = "STREAM" ,
224
224
sub_mode = "SAMPLE" ,
225
- encoding = "PROTO " ,
225
+ encoding = "JSON_IETF " ,
226
226
sample_interval = Client ._NS_IN_S * 10 ,
227
227
suppress_redundant = False ,
228
228
heartbeat_interval = None ,
@@ -246,7 +246,7 @@ def subscribe_xpaths(
246
246
Indicates whether STREAM to stream from target,
247
247
ONCE to stream once (like a get),
248
248
POLL to respond to POLL.
249
- [STREAM, ONCE, POLL ]
249
+ [STREAM]
250
250
sub_mode : proto.gnmi_pb2.SubscriptionMode, optional
251
251
The default SubscriptionMode on a per Subscription basis in the SubscriptionList.
252
252
TARGET_DEFINED indicates that the target (like device/destination) should stream
@@ -256,10 +256,10 @@ def subscribe_xpaths(
256
256
desired behavior.
257
257
ON_CHANGE only streams updates when changes occur.
258
258
SAMPLE will stream the subscription at a regular cadence/interval.
259
- [TARGET_DEFINED, ON_CHANGE, SAMPLE]
259
+ [SAMPLE]
260
260
encoding : proto.gnmi_pb2.Encoding, optional
261
261
A member of the proto.gnmi_pb2.Encoding enum specifying desired encoding of returned data
262
- [JSON, BYTES, PROTO, ASCII, JSON_IETF]
262
+ [JSON, JSON_IETF]
263
263
sample_interval : int, optional
264
264
Default nanoseconds for sample to occur.
265
265
Defaults to 10 seconds.
@@ -274,15 +274,23 @@ def subscribe_xpaths(
274
274
-------
275
275
subscribe()
276
276
"""
277
+ supported_request_modes = ["STREAM" ]
278
+ supported_encodings = ["JSON" , "JSON_IETF" ]
279
+ supported_sub_modes = ["SAMPLE" ]
277
280
subscription_list = proto .gnmi_pb2 .SubscriptionList ()
278
281
subscription_list .mode = util .validate_proto_enum (
279
282
"mode" ,
280
283
request_mode ,
281
284
"SubscriptionList.Mode" ,
282
285
proto .gnmi_pb2 .SubscriptionList .Mode ,
286
+ supported_request_modes ,
283
287
)
284
288
subscription_list .encoding = util .validate_proto_enum (
285
- "encoding" , encoding , "Encoding" , proto .gnmi_pb2 .Encoding
289
+ "encoding" ,
290
+ encoding ,
291
+ "Encoding" ,
292
+ proto .gnmi_pb2 .Encoding ,
293
+ supported_encodings ,
286
294
)
287
295
if isinstance (xpath_subscriptions , string_types ):
288
296
xpath_subscriptions = [xpath_subscriptions ]
@@ -298,28 +306,24 @@ def subscribe_xpaths(
298
306
sub_mode ,
299
307
"SubscriptionMode" ,
300
308
proto .gnmi_pb2 .SubscriptionMode ,
309
+ supported_sub_modes ,
301
310
)
302
311
subscription .sample_interval = sample_interval
303
- subscription .suppress_redundant = suppress_redundant
304
- if heartbeat_interval :
305
- subscription .heartbeat_interval = heartbeat_interval
306
312
elif isinstance (xpath_subscription , dict ):
307
313
path = self .parse_xpath_to_gnmi_path (xpath_subscription ["path" ])
308
314
arg_dict = {
309
315
"path" : path ,
310
316
"mode" : sub_mode ,
311
317
"sample_interval" : sample_interval ,
312
- "suppress_redundant" : suppress_redundant ,
313
318
}
314
- if heartbeat_interval :
315
- arg_dict ["heartbeat_interval" ] = heartbeat_interval
316
319
arg_dict .update (xpath_subscription )
317
320
if "mode" in arg_dict :
318
321
arg_dict ["mode" ] = util .validate_proto_enum (
319
322
"sub_mode" ,
320
323
arg_dict ["mode" ],
321
324
"SubscriptionMode" ,
322
325
proto .gnmi_pb2 .SubscriptionMode ,
326
+ supported_sub_modes ,
323
327
)
324
328
subscription = proto .gnmi_pb2 .Subscription (** arg_dict )
325
329
elif isinstance (xpath_subscription , proto .gnmi_pb2 .Subscription ):
@@ -330,15 +334,14 @@ def subscribe_xpaths(
330
334
return self .subscribe ([subscription_list ])
331
335
332
336
def parse_xpath_to_gnmi_path (self , xpath , origin = None ):
333
- """No origin specified implies openconfig
334
- Otherwise origin is expected to be the module name
337
+ """Naievely tries to intelligently (non-sequitur!) origin
338
+ Otherwise assume rfc7951
339
+ legacy is not considered
335
340
"""
336
341
if origin is None :
337
342
# naive but effective
338
- if xpath .startswith ("openconfig" ) or ":" not in xpath :
339
- # openconfig
340
- origin = None
343
+ if ":" not in xpath :
344
+ origin = "openconfig"
341
345
else :
342
- # module name
343
- origin = xpath .split (":" )[0 ]
346
+ origin = "rfc7951"
344
347
return super (XEClient , self ).parse_xpath_to_gnmi_path (xpath , origin )
0 commit comments