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


Python OpServerUtils.tunnel_type_to_protocol方法代码示例

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


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

示例1: _get_underlay_flow_data

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import tunnel_type_to_protocol [as 别名]
    def _get_underlay_flow_data(self, flow_record_data):
        """Fetch the underlay data from the UFlowData table.

        Construct the Where clause for the UFlowData query from the
        FlowRecord query response. Convert the select clause, sort_fields,
        filter clause in the OverlayToUnderlay query according to the schema
        defined for the UFlowData table.
        """
        if not len(flow_record_data):
            return []

        # populate where clause for Underlay Flow query
        uflow_data_where = []
        for row in flow_record_data:
            uflow_data_where_and_list = []
            ufname = self._flowrecord_to_uflowdata_name(
                FlowRecordNames[FlowRecordFields.FLOWREC_VROUTER_IP])
            val = row[FlowRecordNames[FlowRecordFields.FLOWREC_VROUTER_IP]]
            sip = OpServerUtils.Match(name=ufname, value=val,
                op=OpServerUtils.MatchOp.EQUAL)
            uflow_data_where_and_list.append(sip.__dict__)
            ufname = self._flowrecord_to_uflowdata_name(
                FlowRecordNames[FlowRecordFields.FLOWREC_OTHER_VROUTER_IP])
            val = \
                row[FlowRecordNames[FlowRecordFields.FLOWREC_OTHER_VROUTER_IP]]
            dip = OpServerUtils.Match(name=ufname, value=val,
                op=OpServerUtils.MatchOp.EQUAL)
            uflow_data_where_and_list.append(dip.__dict__)
            ufname = self._flowrecord_to_uflowdata_name(
                FlowRecordNames[FlowRecordFields.FLOWREC_UNDERLAY_SPORT])
            val = row[FlowRecordNames[FlowRecordFields.FLOWREC_UNDERLAY_SPORT]]
            sport = OpServerUtils.Match(name=ufname, value=val,
                    op=OpServerUtils.MatchOp.EQUAL)
            ufname = self._flowrecord_to_uflowdata_name(
                    FlowRecordNames[FlowRecordFields.FLOWREC_UNDERLAY_PROTO])
            val = row[FlowRecordNames[FlowRecordFields.FLOWREC_UNDERLAY_PROTO]]
            # get the protocol from tunnel_type
            val = OpServerUtils.tunnel_type_to_protocol(val)
            protocol = OpServerUtils.Match(name=ufname, value=val,
                    op=OpServerUtils.MatchOp.EQUAL, suffix=sport)
            uflow_data_where_and_list.append(protocol.__dict__)
            uflow_data_where.append(uflow_data_where_and_list)

        # populate UFlowData select
        uflow_data_select = []
        for select in self.query_json['select_fields']:
            uflow_data_select.append(self._underlay_to_uflowdata_name(select))

        # sort_fields specified in the query?
        uflow_data_sort_fields = None
        if self.query_json.get('sort_fields'):
            uflow_data_sort_fields = []
            for field in self.query_json['sort_fields']:
                uflow_data_sort_fields.append(
                    self._underlay_to_uflowdata_name(field))
        uflow_data_sort_type = self.query_json.get('sort')

        # does the query contain limit attribute?
        uflow_data_limit = self.query_json.get('limit')

        # add filter if specified
        uflow_data_filter = None
        if self.query_json.get('filter') is not None:
            uflow_data_filter = list(self.query_json['filter'])
            if len(uflow_data_filter):
                if not isinstance(uflow_data_filter[0], list):
                    uflow_data_filter = [uflow_data_filter]
            for filter_and in uflow_data_filter:
                for match_term in filter_and:
                    match_term['name'] = self._underlay_to_uflowdata_name(
                                            match_term['name'])

        uflow_data_query = OpServerUtils.Query(
                                table='StatTable.UFlowData.flow',
                                start_time=self._start_time,
                                end_time=self._end_time,
                                select_fields=uflow_data_select,
                                where=uflow_data_where,
                                sort=uflow_data_sort_type,
                                sort_fields=uflow_data_sort_fields,
                                limit=uflow_data_limit,
                                filter=uflow_data_filter)
        return self._send_query(json.dumps(uflow_data_query.__dict__))
开发者ID:anbu-enovance,项目名称:contrail-controller,代码行数:85,代码来源:overlay_to_underlay_mapper.py


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