@@ -128,12 +128,12 @@ def load_schema_modules_ctx(self, yang_dir=None):
128
128
"""
129
129
def load_data_file (self , data_file ):
130
130
try :
131
- node = self .ctx .parse_data_path (data_file , ly .LYD_JSON , ly .LYD_OPT_CONFIG | ly .LYD_OPT_STRICT )
131
+ data_node = self .ctx .parse_data_path (data_file , ly .LYD_JSON , ly .LYD_OPT_CONFIG | ly .LYD_OPT_STRICT )
132
132
except Exception as e :
133
133
print ("Failed to load data file: " + str (data_file ))
134
134
self .fail (e )
135
135
else :
136
- self .root = node
136
+ self .root = data_node
137
137
138
138
"""
139
139
get module name from xpath
@@ -169,7 +169,7 @@ def load_data_model (self, yang_dir, yang_files, data_files, output=None):
169
169
170
170
self .load_data_file (data_files [0 ])
171
171
172
- for i in range (2 , len (data_files )):
172
+ for i in range (1 , len (data_files )):
173
173
self .merge_data (data_files [i ])
174
174
except Exception as e :
175
175
print ("Failed to load data files" )
@@ -256,59 +256,59 @@ def validate_data_tree (self):
256
256
self .fail (e )
257
257
258
258
"""
259
- find_parent_node (): find the parent node object
259
+ find_parent_data_node (): find the parent node object
260
260
input: data_xpath - xpath of the data node
261
261
returns: parent node
262
262
"""
263
- def find_parent_node (self , data_xpath ):
263
+ def find_parent_data_node (self , data_xpath ):
264
264
if (self .root is None ):
265
265
print ("data not loaded" )
266
266
return None
267
267
try :
268
- node = self .find_data_node (data_xpath )
268
+ data_node = self .find_data_node (data_xpath )
269
269
except Exception as e :
270
270
print ("Failed to find data node from xpath: " + str (data_xpath ))
271
271
self .fail (e )
272
272
else :
273
- if node is not None :
274
- return node .parent ()
273
+ if data_node is not None :
274
+ return data_node .parent ()
275
275
276
276
return None
277
277
278
278
"""
279
- get_parent_xpath (): find the parent node xpath
279
+ get_parent_data_xpath (): find the parent data node's xpath
280
280
input: data_xpath - xpathof the data node
281
- returns: - xpath of parent node
281
+ returns: - xpath of parent data node
282
282
- Exception if error
283
283
"""
284
- def get_parent_xpath (self , data_xpath ):
284
+ def get_parent_data_xpath (self , data_xpath ):
285
285
path = ""
286
286
try :
287
- node = self .find_parent_node (data_xpath )
287
+ data_node = self .find_parent_data_node (data_xpath )
288
288
except Exception as e :
289
289
print ("Failed to find parent node from xpath: " + str (data_xpath ))
290
290
self .fail (e )
291
291
else :
292
- if (node is not None ):
293
- path = node .path ()
292
+ if (data_node is not None ):
293
+ path = data_node .path ()
294
294
return path
295
295
296
296
"""
297
- new_node (): create a new data node in the data tree
297
+ new_data_node (): create a new data node in the data tree
298
298
input:
299
299
xpath: xpath of the new node
300
300
value: value of the new node
301
301
returns: new Data_Node object if success, Exception if falied
302
302
"""
303
- def new_node (self , xpath , value ):
303
+ def new_data_node (self , xpath , value ):
304
304
val = str (value )
305
305
try :
306
- node = self .root .new_path (self .ctx , xpath , val , 0 , 0 )
306
+ data_node = self .root .new_path (self .ctx , xpath , val , 0 , 0 )
307
307
except Exception as e :
308
308
print ("Failed to add data node for path: " + str (xpath ))
309
309
self .fail (e )
310
310
else :
311
- return node
311
+ return data_node
312
312
313
313
"""
314
314
find_data_node(): find the data node from xpath
@@ -325,9 +325,9 @@ def find_data_node(self, data_xpath):
325
325
self .fail (e )
326
326
else :
327
327
if set is not None :
328
- for node in set .data ():
329
- if (data_xpath == node .path ()):
330
- return node
328
+ for data_node in set .data ():
329
+ if (data_xpath == data_node .path ()):
330
+ return data_node
331
331
return None
332
332
"""
333
333
find_schema_node(): find the schema node from schema xpath
@@ -339,47 +339,47 @@ def find_data_node(self, data_xpath):
339
339
def find_schema_node (self , schema_xpath ):
340
340
try :
341
341
schema_set = self .ctx .find_path (schema_xpath )
342
- for snode in schema_set .schema ():
343
- if (schema_xpath == snode .path ()):
344
- return snode
342
+ for schema_node in schema_set .schema ():
343
+ if (schema_xpath == schema_node .path ()):
344
+ return schema_node
345
345
except Exception as e :
346
346
self .fail (e )
347
347
return None
348
348
else :
349
- for snode in schema_set .schema ():
350
- if schema_xapth == snode .path ():
351
- return snode
349
+ for schema_node in schema_set .schema ():
350
+ if schema_xapth == schema_node .path ():
351
+ return schema_node
352
352
return None
353
353
"""
354
- find_node_schema_xpath (): find the xpath of the schema node from data xpath
354
+ find_data_node_schema_xpath (): find the xpath of the schema node from data xpath
355
355
data xpath example:
356
356
"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet0']/port_name"
357
357
input: data_xpath - xpath of the data node
358
358
returns: - xpath of the schema node if success
359
359
- Exception if error
360
360
"""
361
- def find_node_schema_xpath (self , data_xpath ):
361
+ def find_data_node_schema_xpath (self , data_xpath ):
362
362
path = ""
363
363
try :
364
364
set = self .root .find_path (data_xpath )
365
365
except Exception as e :
366
366
self .fail (e )
367
367
else :
368
- for node in set .data ():
369
- if data_xpath == node .path ():
370
- return node .schema ().path ()
368
+ for data_node in set .data ():
369
+ if data_xpath == data_node .path ():
370
+ return data_node .schema ().path ()
371
371
return path
372
372
373
373
"""
374
374
add_node(): add a node to Yang schema or data tree
375
375
input: xpath and value of the node to be added
376
376
returns: Exception if failed
377
377
"""
378
- def add_node (self , xpath , value ):
378
+ def add_data_node (self , data_xpath , value ):
379
379
try :
380
- node = self .new_node ( xpath , value )
380
+ data_node = self .new_data_node ( data_xpath , value )
381
381
#check if the node added to the data tree
382
- self .find_data_node (xpath )
382
+ self .find_data_node (data_xpath )
383
383
except Exception as e :
384
384
print ("add_node(): Failed to add data node for xpath: " + str (data_xpath ))
385
385
self .fail (e )
@@ -429,20 +429,20 @@ def _delete_node(self, xpath=None, node=None):
429
429
return False
430
430
431
431
"""
432
- find_node_value (): find the value of a node from the schema/ data tree
432
+ find_data_node_value (): find the value of a node from the data tree
433
433
input: data_xpath of the data node
434
434
returns: value string of the node
435
435
"""
436
- def find_node_value (self , data_xpath ):
436
+ def find_data_node_value (self , data_xpath ):
437
437
output = ""
438
438
try :
439
- node = self .find_data_node (data_xpath )
439
+ data_node = self .find_data_node (data_xpath )
440
440
except Exception as e :
441
- print ("find_node_value (): Failed to find data node from xpath: {}" .format (data_xpath ))
441
+ print ("find_data_node_value (): Failed to find data node from xpath: {}" .format (data_xpath ))
442
442
self .fail (e )
443
443
else :
444
- if (node is not None ):
445
- subtype = node .subtype ()
444
+ if (data_node is not None ):
445
+ subtype = data_node .subtype ()
446
446
if (subtype is not None ):
447
447
value = subtype .value_str ()
448
448
return value
@@ -453,9 +453,9 @@ def find_node_value(self, data_xpath):
453
453
input: xpath of the data node
454
454
returns: Exception if failed
455
455
"""
456
- def set_dnode_value (self , data_xpath , value ):
456
+ def set_data_node_value (self , data_xpath , value ):
457
457
try :
458
- node = self .root .new_path (self .ctx , data_xpath , str (value ), ly .LYD_ANYDATA_STRING , ly .LYD_PATH_OPT_UPDATE )
458
+ data_node = self .root .new_path (self .ctx , data_xpath , str (value ), ly .LYD_ANYDATA_STRING , ly .LYD_PATH_OPT_UPDATE )
459
459
except Exception as e :
460
460
print ("set data node value failed for xpath: " + str (data_xpath ))
461
461
self .fail (e )
@@ -497,8 +497,8 @@ def find_schema_dependencies (self, schema_xpath):
497
497
self .fail (e )
498
498
return ref_list
499
499
500
- snode = ly .Schema_Node_Leaf (schema_node )
501
- backlinks = snode .backlinks ()
500
+ schema_node = ly .Schema_Node_Leaf (schema_node )
501
+ backlinks = schema_node .backlinks ()
502
502
if backlinks .number () > 0 :
503
503
for link in backlinks .schema ():
504
504
print ("backlink schema: {}" .format (link .path ()))
0 commit comments