29
29
from six import string_types
30
30
from .client import Client , proto , util
31
31
32
+ logger = logging .getLogger (__name__ )
33
+
32
34
33
35
class XEClient (Client ):
34
36
"""IOS XE-specific wrapper for gNMI functionality.
@@ -93,8 +95,6 @@ def xpath_to_path_elem(self, request):
93
95
module = ''
94
96
if '/Cisco-IOS-' in nspace :
95
97
module = nspace [nspace .rfind ('/' ) + 1 :]
96
- elif '/cisco-nx' in nspace : # NXOS lowercases namespace
97
- module = 'Cisco-NX-OS-device'
98
98
elif '/openconfig.net' in nspace :
99
99
module = 'openconfig-'
100
100
module += nspace [nspace .rfind ('/' ) + 1 :]
@@ -112,8 +112,11 @@ def xpath_to_path_elem(self, request):
112
112
edit_op = node .get ('edit-op' , '' )
113
113
114
114
for pfx , ns in namespace_modules .items ():
115
- xpath = xpath .replace (pfx + ':' , ns + ':' )
116
- value = value .replace (pfx + ':' , ns + ':' )
115
+ if pfx in xpath and 'openconfig' in ns :
116
+ origin = 'openconfig'
117
+ xpath = xpath .replace (pfx + ':' , '' )
118
+ if isinstance (value , string_types ):
119
+ value = value .replace (pfx + ':' , '' )
117
120
if edit_op :
118
121
if edit_op in ['create' , 'merge' , 'replace' ]:
119
122
xpath_lst = xpath .split ('/' )
@@ -144,7 +147,7 @@ def xpath_to_path_elem(self, request):
144
147
message ['delete' ] = set (xpath )
145
148
else :
146
149
message ['get' ].append (xpath )
147
- return namespace_modules , message
150
+ return namespace_modules , message , origin
148
151
149
152
def delete_xpaths (self , xpaths , prefix = None ):
150
153
"""A convenience wrapper for set() which constructs Paths from supplied xpaths
@@ -203,14 +206,14 @@ def set_json(self, update_json_configs=None, replace_json_configs=None, ietf=Tru
203
206
204
207
def check_configs (configs ):
205
208
if isinstance (configs , string_types ):
206
- logging .debug ("Handling as JSON string." )
209
+ logger .debug ("Handling as JSON string." )
207
210
try :
208
211
configs = json .loads (configs )
209
212
except :
210
213
raise Exception ("{0}\n is invalid JSON!" .format (configs ))
211
214
configs = [configs ]
212
215
elif isinstance (configs , dict ):
213
- logging .debug ("Handling already serialized JSON object." )
216
+ logger .debug ("Handling already serialized JSON object." )
214
217
configs = [configs ]
215
218
elif not isinstance (configs , (list , set )):
216
219
raise Exception (
@@ -249,7 +252,7 @@ def create_updates(configs):
249
252
replaces = create_updates (replace_json_configs )
250
253
return self .set (updates = updates , replaces = replaces )
251
254
252
- def get_xpaths (self , xpaths , data_type = "ALL" , encoding = "JSON_IETF" ):
255
+ def get_xpaths (self , xpaths , data_type = "ALL" , encoding = "JSON_IETF" , origin = None ):
253
256
"""A convenience wrapper for get() which forms proto.gnmi_pb2.Path from supplied xpaths.
254
257
255
258
Parameters
@@ -278,13 +281,16 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
278
281
)
279
282
gnmi_path = None
280
283
if isinstance (xpaths , (list , set )):
281
- gnmi_path = map (self .parse_xpath_to_gnmi_path , set (xpaths ))
284
+ gnmi_path = []
285
+ for xpath in set (xpaths ):
286
+ gnmi_path .append (self .parse_xpath_to_gnmi_path (xpath , origin ))
282
287
elif isinstance (xpaths , string_types ):
283
- gnmi_path = [self .parse_xpath_to_gnmi_path (xpaths )]
288
+ gnmi_path = [self .parse_xpath_to_gnmi_path (xpaths , origin )]
284
289
else :
285
290
raise Exception (
286
291
"xpaths must be a single xpath string or iterable of xpath strings!"
287
292
)
293
+ logger .info ('GNMI get:\n {0}\n {1}' .format (9 * '=' , str (gnmi_path )))
288
294
return self .get (gnmi_path , data_type = data_type , encoding = encoding )
289
295
290
296
def subscribe_xpaths (
0 commit comments