def find_data_dependencies(self, data_xpath): ref_list = [] node = self.root try: data_node = self._find_data_node(data_xpath) except Exception as e: print("find_data_dependencies(): Failed to find data node from xpath: {}".format(data_xapth)) return ref_list try: value = str(self._find_data_node_value(data_xpath)) schema_node = ly.Schema_Node_Leaf(data_node.schema()) backlinks = schema_node.backlinks() if backlinks.number() > 0: for link in backlinks.schema(): node_set = node.find_path(link.path()) for data_set in node_set.data(): data_set.schema() casted = data_set.subtype() if value == casted.value_str(): ref_list.append(data_set.path()) except Exception as e: print('Failed to find node or dependencies for {}'.format(data_xpath)) raise SonicYangException("Failed to find node or dependencies for \ {}\n{}".format(data_xpath, str(e))) return ref_list
def deleteNode(self, xpath): # These MACROS used only here, can we get it from Libyang Header ? try: LYS_LEAF = 4 node = self._find_data_node(xpath) if node is None: raise ('Node {} not found'.format(xpath)) snode = node.schema() # check for a leaf if it is a key. If yes delete the parent if (snode.nodetype() == LYS_LEAF): leaf = ly.Schema_Node_Leaf(snode) if leaf.is_key(): # try to delete parent nodeP = self._find_parent_data_node(xpath) xpathP = nodeP.path() if self._deleteNode(xpath=xpathP, node=nodeP) == False: raise Exception('_deleteNode failed') else: return True # delete non key element if self._deleteNode(xpath=xpath, node=node) == False: raise Exception('_deleteNode failed') except Exception as e: raise SonicYangException("Failed to delete node {}\n{}".\ format( xpath, str(e))) return True
def _find_schema_dependencies(self, schema_xpath): ref_list = [] try: schema_node = self._find_schema_node(schema_xpath) except Exception as e: print("Cound not find the schema node from xpath: " + str(schema_xpath)) self.fail(e) return ref_list schema_node = ly.Schema_Node_Leaf(schema_node) backlinks = schema_node.backlinks() if backlinks.number() > 0: for link in backlinks.schema(): print("backlink schema: {}".format(link.path())) ref_list.append(link.path()) return ref_list
def _find_schema_dependencies(self, schema_xpath): ref_list = [] try: schema_node = self._find_schema_node(schema_xpath) except Exception as e: self.sysLog(msg="Cound not find the schema node from xpath: " + str(schema_xpath), debug=syslog.LOG_ERR, doPrint=True) self.fail(e) return ref_list schema_node = ly.Schema_Node_Leaf(schema_node) backlinks = schema_node.backlinks() if backlinks.number() > 0: for link in backlinks.schema(): self.sysLog(msg="backlink schema: {}".format(link.path()), doPrint=True) ref_list.append(link.path()) return ref_list