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


Python OpServerUtils.get_query_result方法代码示例

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


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

示例1: post_query_json

# 需要导入模块: from opserver.opserver_util import OpServerUtils [as 别名]
# 或者: from opserver.opserver_util.OpServerUtils import get_query_result [as 别名]
 def post_query_json(self, json_str, sync=True):
     '''
     this module is to support raw query given in json format
     '''
     res = None
     try:
         flows_url = OpServerUtils.opserver_query_url(self._ip, str(self._port))
         print flows_url
         print "query is: ", json_str
         res = []
         resp = OpServerUtils.post_url_http(flows_url, json_str, sync)
         if sync:
             if resp is not None:
                 res = json.loads(resp)
                 res = res['value']
         else: 
             if resp is not None:
                 resp = json.loads(resp)
                 qid = resp['href'].rsplit('/', 1)[1]
                 result = OpServerUtils.get_query_result(self._ip, str(self._port), qid, 30)
                 for item in result:
                     res.append(item)
     except Exception as e:
         print str(e) 
     finally:
         return res        
开发者ID:piotrkasprzyk,项目名称:contrail-controller,代码行数:28,代码来源:opserver_introspect_utils.py

示例2: post_query

# 需要导入模块: from opserver.opserver_util import OpServerUtils [as 别名]
# 或者: from opserver.opserver_util.OpServerUtils import get_query_result [as 别名]
    def post_query(self, table, start_time=None, end_time=None,
                   select_fields=None, where_clause=None,
                   sort_fields=None, sort=None, limit=None,
                   filter=None, sync=True,dir=None):
        res = None
        try:
            flows_url = OpServerUtils.opserver_query_url(
                self._ip, str(self._port))
            print flows_url
            query_dict = OpServerUtils.get_query_dict(
                table, start_time, end_time,
                select_fields,
                where_clause,
                sort_fields, sort, limit, filter, dir)

            print json.dumps(query_dict)
            res = []
            resp = OpServerUtils.post_url_http(
                flows_url, json.dumps(query_dict), sync)
            if sync:
                if resp is not None:
                    res = json.loads(resp)
                    res = res['value']
            else:
                if resp is not None:
                    resp = json.loads(resp)
                    qid = resp['href'].rsplit('/', 1)[1]
                    result = OpServerUtils.get_query_result(
                        self._ip, str(self._port), qid, 30)
                    for item in result:
                        res.append(item)
        except Exception as e:
            print str(e)
        finally:
            return res
开发者ID:piotrkasprzyk,项目名称:contrail-controller,代码行数:37,代码来源:opserver_introspect_utils.py

示例3: query

# 需要导入模块: from opserver.opserver_util import OpServerUtils [as 别名]
# 或者: from opserver.opserver_util.OpServerUtils import get_query_result [as 别名]

#.........这里部分代码省略.........
                op=OpServerUtils.MatchOp.EQUAL)
            where.append(source_vn_match.__dict__)

        if self._args.destination_vn is not None:
            dest_vn_match = OpServerUtils.Match(
                name=self._DESTINATION_VN,
                value=self._args.destination_vn,
                op=OpServerUtils.MatchOp.EQUAL)
            where.append(dest_vn_match.__dict__)

        if self._args.source_ip is not None:
            source_ip_match = OpServerUtils.Match(
                name=self._SOURCE_IP,
                value=self._args.source_ip,
                op=OpServerUtils.MatchOp.EQUAL)
            where.append(source_ip_match.__dict__)

        if self._args.destination_ip is not None:
            dest_ip_match = OpServerUtils.Match(
                name=self._DESTINATION_IP,
                value=self._args.destination_ip,
                op=OpServerUtils.MatchOp.EQUAL)
            where.append(dest_ip_match.__dict__)

        if self._args.protocol is not None:
            protocol_match = OpServerUtils.Match(
                name=self._PROTOCOL,
                value=self._args.protocol,
                op=OpServerUtils.MatchOp.EQUAL)
            where.append(protocol_match.__dict__)

        if self._args.source_port is not None:
            source_port_match = OpServerUtils.Match(
                name=self._SOURCE_PORT,
                value=self._args.source_port,
                op=OpServerUtils.MatchOp.EQUAL)
            where.append(source_port_match.__dict__)

        if self._args.destination_port is not None:
            dest_port_match = OpServerUtils.Match(
                name=self._DESTINATION_PORT,
                value=self._args.destination_port,
                op=OpServerUtils.MatchOp.EQUAL)
            where.append(dest_port_match.__dict__)

        if self._args.action is not None:
            action_match = OpServerUtils.Match(
                name=self._ACTION,
                value=self._args.action,
                op=OpServerUtils.MatchOp.EQUAL)
            filter.append(action_match.__dict__)

        # Flow Record Table Query
        table = VizConstants.FLOW_TABLE
        if len(where) == 0:
            where = None
        else:
            where = [where]

        select_list = [
            VizConstants.FLOW_TABLE_UUID,
            self._VROUTER,
            self._SETUP_TIME,
            self._TEARDOWN_TIME,
            self._SOURCE_VN,
            self._DESTINATION_VN,
            self._SOURCE_IP,
            self._DESTINATION_IP,
            self._PROTOCOL,
            self._SOURCE_PORT,
            self._DESTINATION_PORT,
            self._ACTION,
            self._DIRECTION,
            VizConstants.FLOW_TABLE_AGG_BYTES,
            VizConstants.FLOW_TABLE_AGG_PKTS,
        ]

        if len(filter) == 0:
            filter = None

        flow_query = OpServerUtils.Query(table,
                                         start_time=start_time,
                                         end_time=end_time,
                                         select_fields=select_list,
                                         where=where,
                                         filter=filter,
                                         dir=self._args.direction)
        if self._args.verbose:
            print 'Performing query: {0}'.format(
                json.dumps(flow_query.__dict__))
        print ''
        resp = OpServerUtils.post_url_http(
            flow_url, json.dumps(flow_query.__dict__))
        result = {}
        if resp is not None:
            resp = json.loads(resp)
            qid = resp['href'].rsplit('/', 1)[1]
            result = OpServerUtils.get_query_result(
                self._args.opserver_ip, self._args.opserver_port, qid)
        return result
开发者ID:Doude,项目名称:contrail-controller,代码行数:104,代码来源:flow.py

示例4: query

# 需要导入模块: from opserver.opserver_util import OpServerUtils [as 别名]
# 或者: from opserver.opserver_util.OpServerUtils import get_query_result [as 别名]

#.........这里部分代码省略.........

            select_list = [
                VizConstants.TIMESTAMP,
                VizConstants.SOURCE,
                VizConstants.MODULE,
                VizConstants.MESSAGE_TYPE,
            ] + obj_sel_field
        elif self._args.trace is not None:
            table = VizConstants.COLLECTOR_GLOBAL_TABLE
            if self._args.source is None:
                print 'Source is required for trace buffer dump'
                return None
            if self._args.module is None:
                print 'Module is required for trace buffer dump'
                return None
            trace_buf_match = OpServerUtils.Match(
                name=VizConstants.CATEGORY,
                value=self._args.trace,
                op=OpServerUtils.MatchOp.EQUAL)
            where_msg.append(trace_buf_match.__dict__)
            where = [where_msg]
            select_list = [
                VizConstants.TIMESTAMP,
                VizConstants.MESSAGE_TYPE,
                VizConstants.SEQUENCE_NUM,
                VizConstants.DATA
            ]
            sandesh_type_filter = OpServerUtils.Match(
                name=VizConstants.SANDESH_TYPE,
                value=str(
                    SandeshType.TRACE),
                op=OpServerUtils.MatchOp.EQUAL)
            filter.append(sandesh_type_filter.__dict__)
        else:
            # Message Table Query
            table = VizConstants.COLLECTOR_GLOBAL_TABLE
            # Message Table contains both systemlog and objectlog.
            # Add a filter to return only systemlogs
            if not self._args.all:
                sandesh_type_filter = OpServerUtils.Match(
                    name=VizConstants.SANDESH_TYPE,
                    value=str(
                        SandeshType.SYSTEM),
                    op=OpServerUtils.MatchOp.EQUAL)
                filter.append(sandesh_type_filter.__dict__)

            if len(where_msg):
                where = [where_msg]
            else:
                where = None

            select_list = [
                VizConstants.TIMESTAMP,
                VizConstants.SOURCE,
                VizConstants.MODULE,
                VizConstants.CATEGORY,
                VizConstants.MESSAGE_TYPE,
                VizConstants.SEQUENCE_NUM,
                VizConstants.DATA,
                VizConstants.SANDESH_TYPE,
                VizConstants.LEVEL,
            ]

        if len(filter) == 0:
            filter = None

        # Add sort by timestamp
        if self._args.reverse:
            sort_op = OpServerUtils.SortOp.DESCENDING
        else:
            sort_op = OpServerUtils.SortOp.ASCENDING
        sort_fields = [VizConstants.TIMESTAMP]

        if self._args.limit:
            limit = int(self._args.limit)
        else:
            limit = None

        messages_query = OpServerUtils.Query(table,
                                             start_time=start_time,
                                             end_time=end_time,
                                             select_fields=select_list,
                                             where=where,
                                             filter=filter,
                                             sort=sort_op,
                                             sort_fields=sort_fields,
                                             limit=limit)
        if self._args.verbose:
            print 'Performing query: {0}'.format(
                json.dumps(messages_query.__dict__))
        print ''
        resp = OpServerUtils.post_url_http(
            messages_url, json.dumps(messages_query.__dict__))
        result = {}
        if resp is not None:
            resp = json.loads(resp)
            qid = resp['href'].rsplit('/', 1)[1]
            result = OpServerUtils.get_query_result(
                self._args.opserver_ip, self._args.opserver_port, qid)
        return result
开发者ID:anju078,项目名称:contrail-controller,代码行数:104,代码来源:log.py


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