@@ -215,6 +215,31 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
215215 )
216216 return self .get (gnmi_path , data_type = data_type , encoding = encoding )
217217
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+
218243 def subscribe_xpaths (
219244 self ,
220245 xpath_subscriptions ,
@@ -342,3 +367,17 @@ def parse_xpath_to_gnmi_path(self, xpath, origin=None):
342367 # module name
343368 origin , xpath = xpath .split (":" , 1 )
344369 return super (XRClient , self ).parse_xpath_to_gnmi_path (xpath , origin )
370+
371+ def parse_cli_to_gnmi_path (self , command ):
372+ """Parses a CLI command to proto.gnmi_pb2.Path.
373+ IOS XR appears to be the only OS with this functionality.
374+
375+ The CLI command becomes a path element.
376+ """
377+ if not isinstance (command , string_types ):
378+ raise Exception ("command must be a string!" )
379+ path = proto .gnmi_pb2 .Path ()
380+ curr_elem = proto .gnmi_pb2 .PathElem ()
381+ curr_elem .name = command
382+ path .elem .extend ([curr_elem ])
383+ return path
0 commit comments