当前位置: 首页>>代码示例>>Python>>正文


Python Context.add_vrouter方法代码示例

本文整理汇总了Python中context.Context.add_vrouter方法的典型用法代码示例。如果您正苦于以下问题:Python Context.add_vrouter方法的具体用法?Python Context.add_vrouter怎么用?Python Context.add_vrouter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在context.Context的用法示例。


在下文中一共展示了Context.add_vrouter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: baseVertex

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import add_vrouter [as 别名]
class baseVertex(object):
    '''Abstract Base Class for Vertex'''
    __metaclass__ = ABCMeta
    non_config_obj = False
    def __init__(self, context=None, **kwargs):
        self.logger = get_logger(name=self.get_class_name(), **kwargs)
        self.config = None
        self.control = None
        self.analytics = None
        self.vrouter = dict()
        self.vertexes = []
        self.ref_vertexes = []
        self.config_objs = {}
        self.dependent_vertex_objs = list()
        if not context:
            self.context = Context(vertex_type=self.vertex_type, **kwargs)
        else:
            self.context = context
        if self._is_vertex_type_exists_in_path():
            return
        self.config_ip = self.context.config_ip
        self.config_port = self.context.config_port
        self.element = kwargs.get('element', None)
        self.depth = self.element['depth'] if self.element else 0
        self.uuid = kwargs.get('uuid', None)
        self.fq_name = kwargs.get('fqname', None)
        if isinstance(self.fq_name, str):
            self.fq_name = self.fq_name.split(':')
        self.display_name = kwargs.get('display_name', None)
        self.obj_type = kwargs.get('obj_type', None) or self.vertex_type
        self.token = self.context.token
        if not self.token:
            self.logger.warn('Authentication failed: Unable to fetch token from keystone')
        self._set_contrail_control_objs()
        self.schema_dict = self.get_schema()
        if not self.element:
            if not hasattr(self, 'match_kv') or not any(self.match_kv.itervalues()):
                self.match_kv = {'uuid': self.uuid, 'fq_name': self.fq_name,
                                 'display_name': self.display_name}
            if not any(self.match_kv.itervalues()):
                raise Exception('Nothing to match, please check match args')
        self._process_vertexes(self.locate_obj())

    @abstractmethod
    def process_self(self, vertex):
        pass

    @abstractmethod
    def get_schema(self, context, **kwargs):
        pass

    def _set_contrail_control_objs(self):
        self.config = self.context.config
        self.control = self.context.control
        self.analytics = self.context.analytics
        self.schema = self.context.schema
        #self.context.get_cluster_status()

    def get_vrouter_info(self, vertex):
        contrail_info = ContrailUtils(token=self.token).get_contrail_info(
                                                        vertex['uuid'],
                                                        vertex['vertex_type'],
                                                        config_ip=self.config_ip,
                                                        config_port=self.config_port,
                                                        analytics_ip=self.context.analytics_ip,
                                                        analytics_port=self.context.analytics_port,
                                                        context_path=self.context.get_path(),
                                                        fq_name=vertex['fq_name'])
        vrouter = Vrouter(contrail_info['vrouter'], port=self.context.agent_port)
        return vrouter

    def get_context(self):
        return self.context

    def get_class_name(self):
        return self.__class__.__name__

    def _process_vertexes(self, objs):
        vertex_type = self.vertex_type
        for obj in objs or []:
            if not obj:
                continue
            uuid = obj[vertex_type]['uuid']
            if self.context.is_visited_vertex(uuid):
                self.ref_vertexes.append(self.context.get_vertex_of_uuid(uuid))
                continue
            vertex = self._store_vertex(vertex_type, uuid, obj)
            self.store_config(vertex)
            self._store_config_schema(vertex)
            self.store_control_config(vertex)
            self.store_analytics_uves(vertex)
            if self.non_config_obj == False:
                self.vrouter[uuid] = self.get_vrouter_info(vertex)
                vrouter_nodes = self.vrouter[uuid].get_nodes()
                if not vrouter_nodes:
                    self.logger.error('Unable to find vrouter for %s:%s' % (self.vertex_type,
                                                                       uuid))
                self.context.add_vrouter(vrouter_nodes, self.vertex_type, 
                                         uuid, obj[vertex_type]['fq_name'])
                self.store_agent_config(vertex)
#.........这里部分代码省略.........
开发者ID:smurugap,项目名称:debug_infra,代码行数:103,代码来源:basevertex.py


注:本文中的context.Context.add_vrouter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。