Beispiel #1
0
def test():
    pre, tag = yc.getPrefixAndTag('vlan-tag-match-type')
    if pre:
        print 'sth'
    else:
        print tag
    pass
Beispiel #2
0
    def __handle_augments_by_module(self, srcMod):
        all_handled = True
        for aug in srcMod.augments:
            if aug.not_handled():
                all_handled = False
            else:
                continue
            
            #Step1: Split namespace, find root module of xpath
            _aug_tar_node = aug.yinNode.augTarNode
            path_list = []
            for piece in _aug_tar_node.split('/'):
                if len(piece) > 0:
                    path_list.append(piece)

            root_node = path_list[0]
            root_prefix, root_ident = yc.getPrefixAndTag(root_node)
            aug_root = None
            if root_prefix:
                if root_prefix == srcMod.prefix:
                    aug_root = srcMod.find_augment_tree_root(root_ident)
                else:
                    import_mod_name = srcMod.find_import_module_name(root_prefix)
                    temp_mod = self.modules[import_mod_name]
                    aug_root = temp_mod.find_augment_tree_root(root_ident)
            else:
                aug_root = srcMod.find_augment_tree_root(root_ident)
            if not aug_root:
                # The root haven't been generated yet, skip this loop
                continue
            
            #Step2: Check the target-node's xpath has been generated or not
            internal_aug_path = srcMod.convert_internal_augment_path(_aug_tar_node)
            external_aug_path = self.__convert_external_augment_path(internal_aug_path)
            iutil.DEBUG('Trying to find aug<%s> with path...' % _aug_tar_node)
            #for nn in external_aug_path:
            #    iutil.DEBUG(nn)
            tar_yinNode = aug_root.find_by_xpath(external_aug_path)
            if not tar_yinNode:
                # The target node haven't been generated yet, skip this loop
                iutil.DEBUG('Failed!')
                continue
            
            iutil.DEBUG('Success on insert augment<%s>! ' % _aug_tar_node)
            #Step3: Insert augment node
            new_node = yc.clone(aug.yinNode)
            new_node.invisible = False
            tar_yinNode.insertSubNode(new_node)
            #tar_yinNode.stmts = new_node.stmts
            
            # Step4: Target module make a record for source module, should be useless
            #if srcMod.get_name() not in root_mod.beAugmentedBy:
            #    root_mod.beAugmentedBy[srcMod.get_name()] = srcMod
            
            iutil.DEBUG('Success on inserting augment from module<%s> to target-node<%s>' % (srcMod.get_name(), aug.yinNode.augTarNode))
            aug.set_handled()
            
        #End of augment iteration of each module
        return all_handled
Beispiel #3
0
 def __convert_external_augment_path(self, internal_aug_path):
     path_list = list()
     for node in internal_aug_path:
         if len(node) < 1:
             continue
         internal_mod_name, node_identifier = yc.getPrefixAndTag(node)
         external_mod_name = None
         if internal_mod_name:
             in_mod = self.modules[internal_mod_name]
             ex_mod = in_mod.find_root_module()
             external_mod_name = ex_mod.get_name()
         else:
             iutil.ERROR('None exsist internal module name!')
             
         new_node = (external_mod_name + ':' + node_identifier)
         path_list.append(new_node)
     return path_list
Beispiel #4
0
 def __recursive_convert(self, srcMod_, type_ident):
     # Will circular definition occur here? Seems that we should use yang compiler to prevent it.
     iutil.DEBUG('Convert type<%s> from module<%s>' % (type_ident, srcMod_.get_name()))
     if yc.isYangBuiltinType(type_ident):
         return type_ident
     else:
         prefix, ident = yc.getPrefixAndTag(type_ident)
         if not prefix:
             new_type, tarMod = srcMod_.find_type_with_mod(ident)
             if new_type:
                 return self.__recursive_convert(tarMod, new_type)
             else:
                 iutil.ERROR('Unkonw type <%s> from module<%s>' % (ident, srcMod_.get_name()))
                 return ident
         else:
             tarMod = self.__find_module_by_prefix(srcMod_, prefix)
             if not tarMod:
                 return type_ident
             return self.__recursive_convert(tarMod, ident)
Beispiel #5
0
 def convert_internal_augment_path(self, target_path):
     path_list = list()
     for node in target_path.split('/'):
         if len(node) < 1:
             continue
         prefix, tag = yc.getPrefixAndTag(node)
         mod_name = None
         if prefix:
             if prefix == self.get_prefix():
                 mod_name = self.get_name()
             elif prefix in self.imports:
                 mod_name = self.find_import_module_name(prefix)
             else:
                 iutil.ERROR('Bad node<%s> in augment path <%s> from module<%s>' % (node, target_path, self.get_name()))
         else:
             mod_name = self.get_name()
             
         new_node = (mod_name + ':' + tag)
         path_list.append(new_node)
     return path_list
Beispiel #6
0
 def __init__(self, mod_prefix, yinNode):
     object.__init__(self)
     self.prefix, self.identifier = yin_common.getPrefixAndTag(yinNode.identifier)
     self.yinNode = yinNode
     self.tarGroup = None
     self.__handled = False