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


Python OpServerUtils.get_query_result方法代码示例

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


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

示例1: post_query

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_query_result [as 别名]
    def post_query(self, table, start_time=None, end_time=None,
                   select_fields=None,
                   where_clause='',
                   sort_fields=None, sort=None, limit=None, filter=None, 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))
            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)
                for item in result:
                    res.append(item)
        except Exception as e:
            print str(e)
        finally:
            return res
开发者ID:ganeshahv,项目名称:contrail-test,代码行数:32,代码来源:opserver_introspect_utils.py

示例2: query

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_query_result [as 别名]
    def query(self, table, start_time=None, end_time=None,
              select_fields=None,
              where_clause="",
              sort_fields=None, sort=None, limit=None, filter=None):
        """
        This function takes in the query parameters,
        format appropriately and calls
        ReST API to the :mod:`opserver` to get data

        :param table: table to do the query on
        :type table: str
        :param start_time: start_time of the query's timeperiod
        :type start_time: int
        :param end_time: end_time of the query's timeperiod
        :type end_time: int
        :param select_fields: list of columns to be returned in the
         final result
        :type select_fields: list of str
        :param where_clause: list of match conditions for the query
        :type where_clause: list of match, which is a pair of str ANDed
        :returns: str -- json formatted result
        :raises: Error

        """

        flows_url = OpServerUtils.opserver_query_url(self._args.opserver_ip,
                                                     self._args.opserver_port)
        print flows_url

        query_dict = OpServerUtils.get_query_dict(table, start_time, end_time,
                                                  select_fields, where_clause,
                                                  sort_fields, sort, limit,
                                                  filter)

        print json.dumps(query_dict)
        resp = OpServerUtils.post_url_http(flows_url, json.dumps(query_dict))
        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)
            for item in result:
                print item

        return
开发者ID:Doude,项目名称:contrail-controller,代码行数:48,代码来源:opserver_client.py

示例3: post_query

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_query_result [as 别名]
    def post_query(self, table, start_time=None, end_time=None,
                   select_fields=None,
                   where_clause='',
                   sort_fields=None, sort=None, limit=None, filter=None, dir=None,
                   session_type=None):
        res = None
        try:
            self._drv._auth()
            headers = self._drv._headers
        except Exception as e:
            headers = None #vcenter case where openstack not available

        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,
                session_type)

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

示例4: query

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

#.........这里部分代码省略.........
                return -1
            if self._args.module is None:
                print 'Module is required for trace buffer dump'
                return -1
            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,
                VizConstants.SANDESH_TYPE
            ]
            sandesh_type_filter = OpServerUtils.Match(
                name=VizConstants.SANDESH_TYPE,
                value=str(
                    SandeshType.TRACE),
                op=OpServerUtils.MatchOp.EQUAL)
            and_filter.append(sandesh_type_filter.__dict__)
        else:
            # Message Table Query
            table = VizConstants.COLLECTOR_GLOBAL_TABLE

            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,
                VizConstants.NODE_TYPE,
                VizConstants.INSTANCE_ID,
            ]

        filter = None
        if len(or_filter):
            filter = [and_filter+[filt] for filt in or_filter]
        elif len(and_filter):
            filter = [and_filter]

        if self._args.keywords is not None:
            p = re.compile('\s*,\s*|\s+')
            if where is None:
                where = [[]]
            for kwd in p.split(self._args.keywords):
                message_type_match = OpServerUtils.Match(
                    name=VizConstants.KEYWORD,
                    value=kwd,
                    op=OpServerUtils.MatchOp.EQUAL)
                for wc in where:
                    wc.append(message_type_match.__dict__)

        # Add sort by timestamp for non object value queries
        sort_op = None
        sort_fields = None
        if self._args.object_values is False:
            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__))
        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.analytics_api_ip, self._args.analytics_api_port, qid)
        return result
开发者ID:bokuden,项目名称:contrail-controller,代码行数:104,代码来源:log.py

示例5: query

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

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

        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__)

        if self._args.vrouter_ip is not None:
            vrouter_ip_match = OpServerUtils.Match(
                name=self._VROUTER_IP,
                value=self._args.vrouter_ip,
                op=OpServerUtils.MatchOp.EQUAL)
            filter.append(vrouter_ip_match.__dict__)

        if self._args.other_vrouter_ip is not None:
            other_vrouter_ip_match = OpServerUtils.Match(
                name=self._OTHER_VROUTER_IP,
                value=self._args.other_vrouter_ip,
                op=OpServerUtils.MatchOp.EQUAL)
            filter.append(other_vrouter_ip_match.__dict__)

        if self._args.vmi_uuid is not None:
            vmi_match = OpServerUtils.Match(
                name=self._VMI_UUID,
                value=uuid.UUID(self._args.vmi_uuid),
                op=OpServerUtils.MatchOp.EQUAL)
            filter.append(vmi_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,
            self._SG_RULE_UUID,
            self._NW_ACE_UUID,
            self._VROUTER_IP,
            self._OTHER_VROUTER_IP,
            self._VMI_UUID,
            self._DROP_REASON
        ]
        if self._args.tunnel_info:
            select_list.append(self._UNDERLAY_PROTO)
            select_list.append(self._UNDERLAY_SPORT)

        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.analytics_api_ip, self._args.analytics_api_port, qid)
        return result
开发者ID:Pojen-Huang,项目名称:contrail-controller,代码行数:104,代码来源:flow.py

示例6: query

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

#.........这里部分代码省略.........
                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,
                VizConstants.NODE_TYPE,
                VizConstants.INSTANCE_ID,
            ]

        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:jarimura,项目名称:contrail-controller,代码行数:104,代码来源:log.py

示例7: query

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

#.........这里部分代码省略.........
            else:
                where = None

        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 -1
            if self._args.module is None:
                print 'Module is required for trace buffer dump'
                return -1
            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,
                VizConstants.NODE_TYPE,
                VizConstants.INSTANCE_ID,
            ]

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

        # Add sort by timestamp for non object value queries
        sort_op = None
        sort_fields = None
        if self._args.object_values is False:
            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__))
        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:shengxinking,项目名称:contrail-controller,代码行数:104,代码来源:log.py

示例8: query

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

#.........这里部分代码省略.........
                    VizConstants.MODULE,
                    VizConstants.MESSAGE_TYPE,
                ] + obj_sel_field
            else:
                if self._args.object_select_field:
                    print "Plesae specify either object-id with " + "object-select-field or only object-values"
                    return None
                select_list = [OpServerUtils.OBJECT_ID]
        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,
                VizConstants.NODE_TYPE,
                VizConstants.INSTANCE_ID,
            ]

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

        # Add sort by timestamp for non object value queries
        sort_op = None
        sort_fields = None
        if self._args.object_values is False:
            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:nati,项目名称:contrail-controller,代码行数:104,代码来源:log.py


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