@@ -215,6 +215,31 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
215
215
)
216
216
return self .get (gnmi_path , data_type = data_type , encoding = encoding )
217
217
218
+ def get_cli (self , commands ):
219
+ """A convenience wrapper for get() which forms proto.gnmi_pb2.Path from supplied CLI commands.
220
+ IOS XR appears to be the only OS with this functionality.
221
+
222
+ Parameters
223
+ ----------
224
+ commands : iterable of str or str
225
+ An iterable of CLI commands as strings to request data of
226
+ If simply a str, wraps as a list for convenience
227
+
228
+ Returns
229
+ -------
230
+ get()
231
+ """
232
+ gnmi_path = None
233
+ if isinstance (commands , (list , set )):
234
+ gnmi_path = list (map (self .parse_cli_to_gnmi_path , commands ))
235
+ elif isinstance (commands , string_types ):
236
+ gnmi_path = [self .parse_cli_to_gnmi_path (commands )]
237
+ else :
238
+ raise Exception (
239
+ "commands must be a single CLI command string or iterable of CLI commands as strings!"
240
+ )
241
+ return self .get (gnmi_path , encoding = "ASCII" )
242
+
218
243
def subscribe_xpaths (
219
244
self ,
220
245
xpath_subscriptions ,
@@ -343,43 +368,16 @@ def parse_xpath_to_gnmi_path(self, xpath, origin=None):
343
368
origin , xpath = xpath .split (":" , 1 )
344
369
return super (XRClient , self ).parse_xpath_to_gnmi_path (xpath , origin )
345
370
346
- def get_cli_commands (self , cli_commands ):
347
- """A convenience wrapper for get() which forms proto.gnmi_pb2.Path from supplied CLI commands.
348
-
349
- Parameters
350
- ----------
351
- cli_commands : iterable of str or str
352
- An iterable of CLI commands as strings to request data of
353
- If simply a str, wraps as a list for convenience
354
-
355
- Returns
356
- -------
357
- get()
358
- """
359
- gnmi_path = None
360
- if isinstance (cli_commands , (list , set )):
361
- gnmi_path = map (self .parse_cli_command_to_gnmi_path , set (cli_commands ))
362
- elif isinstance (cli_commands , string_types ):
363
- gnmi_path = [self .parse_cli_command_to_gnmi_path (cli_commands )]
364
- else :
365
- raise Exception (
366
- "cli_commands must be a single CLI command string or iterable of CLI commands as strings!"
367
- )
368
- return self .get (gnmi_path , encoding = 'ASCII' )
369
-
370
- def parse_cli_command_to_gnmi_path (self , cli_command ):
371
+ def parse_cli_to_gnmi_path (self , command ):
371
372
"""Parses a CLI command to proto.gnmi_pb2.Path.
372
- This function should be overridden by any child classes for origin logic .
373
+ IOS XR appears to be the only OS with this functionality .
373
374
374
375
The CLI command becomes a path element.
375
376
"""
376
- if not isinstance (cli_command , string_types ):
377
- raise Exception ("cli_command must be a string!" )
378
-
377
+ if not isinstance (command , string_types ):
378
+ raise Exception ("command must be a string!" )
379
379
path = proto .gnmi_pb2 .Path ()
380
380
curr_elem = proto .gnmi_pb2 .PathElem ()
381
- curr_elem .name = cli_command
381
+ curr_elem .name = command
382
382
path .elem .extend ([curr_elem ])
383
-
384
383
return path
385
-
0 commit comments