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


Python OpServerUtils.get_url_http方法代码示例

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


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

示例1: run

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
    def run(self):
        if self.parse_args() != 0:
            return

        if len(self._args.select)==0 and self._args.dtable is None: 
            tab_url = "http://" + self._args.analytics_api_ip + ":" +\
                self._args.analytics_api_port +\
                "/analytics/table/StatTable." + self._args.table
            schematxt = OpServerUtils.get_url_http(tab_url + "/schema",
                self._args.admin_user, self._args.admin_password)
            schema = json.loads(schematxt.text)['columns']
            for pp in schema:
                if pp.has_key('suffixes') and pp['suffixes']:
                    des = "%s %s" % (pp['name'],str(pp['suffixes']))
                else:
                    des = "%s" % pp['name']
                if pp['index']:
                    valuetxt = OpServerUtils.get_url_http(
                        tab_url + "/column-values/" + pp['name'],
                        self._args.admin_user, self._args.admin_password)
                    print "%s : %s %s" % (des,pp['datatype'], valuetxt.text)
                else:
                    print "%s : %s" % (des,pp['datatype'])
        else:
            result = self.query()
            self.display(result)
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:28,代码来源:stats.py

示例2: main

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
def main():
    querier = StatQuerier()
    if querier.parse_args() != 0:
        return


    if len(querier._args.select)==0 and querier._args.dtable is None: 
        tab_url = "http://" + querier._args.analytics_api_ip + ":" +\
            querier._args.analytics_api_port +\
            "/analytics/table/StatTable." + querier._args.table
        schematxt = OpServerUtils.get_url_http(tab_url + "/schema")
        schema = json.loads(schematxt.text)['columns']
        for pp in schema:
            if pp.has_key('suffixes') and pp['suffixes']:
                des = "%s %s" % (pp['name'],str(pp['suffixes']))
            else:
                des = "%s" % pp['name']
            if pp['index']:
                valuetxt = OpServerUtils.get_url_http(tab_url + "/column-values/" + pp['name'])
                print "%s : %s %s" % (des,pp['datatype'], valuetxt.text)
            else:
                print "%s : %s" % (des,pp['datatype'])
    else:
        result = querier.query()
        querier.display(result)
开发者ID:numansiddique,项目名称:contrail-controller,代码行数:27,代码来源:stats.py

示例3: get_dbusage_info

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
    def get_dbusage_info(self, ip, port, user, password):
        """Collects database usage information from all db nodes
        Returns:
        A dictionary with db node name as key and db usage in % as value
        """

        to_return = {}
        try:
            uve_url = "http://" + ip + ":" + str(port) + \
                "/analytics/uves/database-nodes?cfilt=DatabaseUsageInfo"
            data = OpServerUtils.get_url_http(uve_url, user, password)
            node_dburls = json.loads(data.text)

            for node_dburl in node_dburls:
                # calculate disk usage percentage for analytics in each
                # cassandra node
                db_uve_data = OpServerUtils.get_url_http(node_dburl['href'],
                    user, password)
                db_uve_state = json.loads(db_uve_data.text)
                db_usage_in_perc = (100*
                        float(db_uve_state['DatabaseUsageInfo']['database_usage'][0]['analytics_db_size_1k'])/
                        float(db_uve_state['DatabaseUsageInfo']['database_usage'][0]['disk_space_available_1k'] +
                        db_uve_state['DatabaseUsageInfo']['database_usage'][0]['disk_space_used_1k']))
                to_return[node_dburl['name']] = db_usage_in_perc
        except Exception as inst:
            self._logger.error(type(inst))     # the exception instance
            self._logger.error(inst.args)      # arguments stored in .args
            self._logger.error(inst)           # __str__ allows args to be printed directly
            self._logger.error("Could not retrieve db usage information")

        self._logger.info("db usage:" + str(to_return))
        return to_return
开发者ID:eonpatapon,项目名称:contrail-controller,代码行数:34,代码来源:analytics_db.py

示例4: get_pending_compaction_tasks

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
    def get_pending_compaction_tasks(self):
        """Collects pending compaction tasks from all db nodes
        Returns:
        A dictionary with db node name as key and pending compaction
        tasks in % as value
        """

        to_return = {}
        try:
            uve_url = "http://" + self._ip + ":" + str(self._admin_port) + \
                "/analytics/uves/database-nodes?cfilt=" \
                "CassandraStatusData:cassandra_compaction_task"
            data = OpServerUtils.get_url_http(uve_url, self._admin_user,
                    self._admin_password)
            node_dburls = json.loads(data.text)

            for node_dburl in node_dburls:
                # get pending compaction tasks for analytics in each
                # cassandra node
                db_uve_data = OpServerUtils.get_url_http(node_dburl['href'],
                    self._admin_user, self._admin_password)
                db_uve_state = json.loads(db_uve_data.text)
                pending_compaction_tasks = \
                    int(db_uve_state['CassandraStatusData']
                        ['cassandra_compaction_task']
                        ['pending_compaction_tasks'])
                to_return[node_dburl['name']] = pending_compaction_tasks

        except Exception as inst:
            self._logger.error("Exception: Could not retrieve pending"
                               " compaction tasks information %s" %
                               str(type(inst)))

        self._logger.info("pending compaction tasks :" + str(to_return))
        return to_return
开发者ID:nischalsheth,项目名称:contrail-controller,代码行数:37,代码来源:analytics_db.py

示例5: run

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
    def run(self):
        topdir = "/usr/share/doc/contrail-docs/html/messages/"
        extn = ".json"
        stat_schema_files = []
        for dirpath, dirnames, files in os.walk(topdir):
            for name in files:
                if name.lower().endswith(extn):
                    stat_schema_files.append(os.path.join(dirpath, name))
        stat_tables = []
        for schema_file in stat_schema_files:
            with open(schema_file) as data_file:
                data = json.load(data_file)
            for _, tables in data.iteritems():
                for table in tables:
                    if table not in stat_tables:
                        stat_tables.append(table)
        stat_table_list = [xx.stat_type + "." + xx.stat_attr for xx in VizConstants._STAT_TABLES]
        stat_table_list.extend([xx["stat_type"] + "." + xx["stat_attr"] for xx in stat_tables])

        if self.parse_args(stat_table_list) != 0:
            return

        if len(self._args.select) == 0 and self._args.dtable is None:
            tab_url = (
                "http://"
                + self._args.analytics_api_ip
                + ":"
                + self._args.analytics_api_port
                + "/analytics/table/StatTable."
                + self._args.table
            )
            schematxt = OpServerUtils.get_url_http(
                tab_url + "/schema", self._args.admin_user, self._args.admin_password
            )
            schema = json.loads(schematxt.text)["columns"]
            for pp in schema:
                if pp.has_key("suffixes") and pp["suffixes"]:
                    des = "%s %s" % (pp["name"], str(pp["suffixes"]))
                else:
                    des = "%s" % pp["name"]
                if pp["index"]:
                    valuetxt = OpServerUtils.get_url_http(
                        tab_url + "/column-values/" + pp["name"], self._args.admin_user, self._args.admin_password
                    )
                    print "%s : %s %s" % (des, pp["datatype"], valuetxt.text)
                else:
                    print "%s : %s" % (des, pp["datatype"])
        else:
            result = self.query()
            self.display(result)
开发者ID:eonpatapon,项目名称:contrail-controller,代码行数:52,代码来源:stats.py

示例6: run

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
 def run(self):
     try:
         index = 0
         analytics_api_ip = self._defaults['analytics_api_ip']
         analytics_api_port = self._defaults['analytics_api_port']
         username = self._defaults['username']
         password = self._defaults['password']
         for arg in sys.argv:
             index = index + 1
             if arg == "--analytics-api-ip":
                 analytics_api_ip = sys.argv[index]
             elif arg == "--analytics-api-port":
                 analytics_api_port = sys.argv[index]
             elif arg == "--admin-user":
                 username = sys.argv[index]
             elif arg == "--admin-password":
                 password = sys.argv[index]
         tab_url = "http://" + analytics_api_ip + ":" +\
             analytics_api_port + "/analytics/tables"
         tables = OpServerUtils.get_url_http(tab_url,
             username, password)
         if tables != {}:
             table_list = json.loads(tables.text)
             for table in table_list:
                 if table['type'] == 'OBJECT':
                     OBJECT_TYPE_LIST.append(str(table['display_name']))
         if self.parse_args() != 0:
             return
         if self._args.tail:
             start_time = UTCTimestampUsec() - 10*pow(10,6)
             while True:
                 self._start_time = start_time
                 self._end_time = UTCTimestampUsec()
                 start_time = self._end_time + 1
                 time.sleep(3)
                 result = self.query()
                 if result == -1:
                     return
                 self.display(result)
         else:
             start_time = self._args.start_time
             end_time = self._args.end_time
             if not self._args.start_time:
                 start_time = "now-10m"
             if not self._args.end_time:
                 end_time = "now"
             try:
                 self._start_time, self._end_time = \
                     OpServerUtils.parse_start_end_time(
                         start_time = start_time,
                         end_time = end_time,
                         last = self._args.last)
             except:
                 return -1
             result = self.query()
             if result == -1:
                 return
             self.display(result)
     except KeyboardInterrupt:
         return
开发者ID:tcpcloud,项目名称:contrail-controller,代码行数:62,代码来源:log.py

示例7: parse_args

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
    def parse_args(self):
        """
        Eg. python log.py --analytics-api-ip 127.0.0.1
                          --analytics-api-port 8181
                          --source 127.0.0.1
                          --node-type Control
                          --module bgp | cfgm | vnswad
                          --instance-id 0
                          --message-type UveVirtualMachineConfigTrace
                          --category xmpp
                          --level SYS_INFO | SYS_ERROR
                          --object-type virtual-network | virtual-machine
                          --object-id name
                          --object-select-field ObjectLog | SystemLog
                          --reverse
                          --verbose
                          --raw
                          --trace BgpPeerTraceBuf
                          [--start-time now-10m --end-time now] | --last 10m
                          --send-syslog
                          --syslog-server 127.0.0.1
                          --syslog-port 514
                          --keywords comma,seperated,list
        """
        defaults = {
            'analytics_api_ip': '127.0.0.1',
            'analytics_api_port': '8181',
            'admin_user': 'admin',
            'admin_password': 'contrail123',
            'conf_file': '/etc/contrail/contrail-keystone-auth.conf',
        }

        conf_parser = argparse.ArgumentParser(add_help=False)
        conf_parser.add_argument("--admin-user", help="Name of admin user")
        conf_parser.add_argument("--admin-password", help="Password of admin user")
        conf_parser.add_argument("--conf-file", help="Configuration file")
        conf_parser.add_argument("--analytics-api-ip", help="IP address of Analytics API Server")
        conf_parser.add_argument("--analytics-api-port", help="Port of Analytics API Server")
        args, remaining_argv = conf_parser.parse_known_args();

        configfile = defaults['conf_file']
        if args.conf_file:
            configfile = args.conf_file

        config = ConfigParser.SafeConfigParser()
        config.read(configfile)
        if 'KEYSTONE' in config.sections():
            if args.admin_user == None:
                args.admin_user = config.get('KEYSTONE', 'admin_user')
            if args.admin_password == None:
                args.admin_password = config.get('KEYSTONE','admin_password')

        if args.admin_user == None:
            args.admin_user = defaults['admin_user']
        if args.admin_password == None:
            args.admin_password = defaults['admin_password']

        if args.analytics_api_ip == None:
            args.analytics_api_ip = defaults['analytics_api_ip']
        if args.analytics_api_port == None:
            args.analytics_api_port = defaults['analytics_api_port']

        tab_url = "http://" + args.analytics_api_ip + ":" +\
            args.analytics_api_port + "/analytics/tables"
        tables = OpServerUtils.get_url_http(tab_url,
            args.admin_user, args.admin_password)
        if tables != {}:
            if tables.status_code == 200:
                table_list = json.loads(tables.text)
                for table in table_list:
                    if table['type'] == 'OBJECT':
                        # append to OBJECT_TYPE_LIST only if not existing
                        if table['name'] not in OBJECT_TABLE_MAP.values():
                            OBJECT_TYPE_LIST.append(str(table['name']))
                            # For object table the mapping between the actual table
                            # name and the table name used in help msg are the same
                            OBJECT_TABLE_MAP[table['name']]=table['name']

        parser = argparse.ArgumentParser(
                  # Inherit options from config_parser
                  parents=[conf_parser],
                  # print script description with -h/--help
                  description=__doc__,
                  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
        parser.set_defaults(**defaults)
        parser.add_argument(
            "--start-time", help="Logs start time (format now-10m, now-1h)")
        parser.add_argument("--end-time", help="Logs end time")
        parser.add_argument(
            "--last", help="Logs from last time period (format 10m, 1d)")

        parser.add_argument("--source", nargs="*",
            help="list of sources separated by space")
        parser.add_argument("--node-type", help="Logs from node type",
            choices=NodeTypeNames.values())
        parser.add_argument("--module", nargs="*",
            help="list of modules separated by space", choices=ModuleNames.values())
        parser.add_argument("--instance-id", help="Logs from module instance")
        parser.add_argument("--category", help="Logs of category")
        parser.add_argument("--level", help="Logs of level")
#.........这里部分代码省略.........
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:103,代码来源:log.py

示例8: parse_args

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import get_url_http [as 别名]
    def parse_args(self):
        """ 
        Eg. python stats.py --analytics-api-ip 127.0.0.1
                          --analytics-api-port 8181
                          --table NodeStatus.process_mem_cpu_usage
                          --where name=a6s40 cpu_info.module_id=Collector
                          --select "T=60 SUM(cpu_info.cpu_share)"
                          --sort "SUM(cpu_info.cpu_share)"
                          [--start-time now-10m --end-time now] | --last 10m

            python stats.py --table NodeStatus.process_mem_cpu_usage
        """
        defaults = {
            'analytics_api_ip': '127.0.0.1',
            'analytics_api_port': '8181',
            'start_time': 'now-10m',
            'end_time': 'now',
            'select' : [],
            'where' : ['Source=*'],
            'sort': [],
            'admin_user': 'admin',
            'admin_password': 'contrail123',
            'conf_file': '/etc/contrail/contrail-keystone-auth.conf',
        }

        conf_parser = argparse.ArgumentParser(add_help=False)
        conf_parser.add_argument("--admin-user", help="Name of admin user")
        conf_parser.add_argument("--admin-password", help="Password of admin user")
        conf_parser.add_argument("--conf-file", help="Configuration file")
        conf_parser.add_argument("--analytics-api-ip", help="IP address of Analytics API Server")
        conf_parser.add_argument("--analytics-api-port", help="Port of Analytcis API Server")
        args, remaining_argv = conf_parser.parse_known_args();

        configfile = defaults['conf_file']
        if args.conf_file:
            configfile = args.conf_file

        config = ConfigParser.SafeConfigParser()
        config.read(configfile)
        if 'KEYSTONE' in config.sections():
            if args.admin_user == None:
                args.admin_user = config.get('KEYSTONE', 'admin_user')
            if args.admin_password == None:
                args.admin_password = config.get('KEYSTONE','admin_password')

        if args.admin_user == None:
            args.admin_user = defaults['admin_user']
        if args.admin_password == None:
            args.admin_password = defaults['admin_password']

        if args.analytics_api_ip == None:
            args.analytics_api_ip = defaults['analytics_api_ip']
        if args.analytics_api_port == None:
            args.analytics_api_port = defaults['analytics_api_port']

        stat_table_list = [xx.stat_type + "." + xx.stat_attr for xx in VizConstants._STAT_TABLES]
        tab_url = "http://" + args.analytics_api_ip + ":" +\
            args.analytics_api_port + "/analytics/tables"
        tables = OpServerUtils.get_url_http(tab_url,
            args.admin_user, args.admin_password)
        if tables != {}:
            if tables.status_code == 200:
                table_list = json.loads(tables.text)
                for table in table_list:
                    if table['type'] == 'STAT':
                        table_name = '.'.join(table['name'].split('.')[1:])
                        # append to stat_table_list only if not existing
                        if table_name not in stat_table_list:
                            stat_table_list.append(table_name)

        parser = argparse.ArgumentParser(
                  # Inherit options from config_parser
                  parents=[conf_parser],
                  # print script description with -h/--help
                  description=__doc__,
                  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
        parser.set_defaults(**defaults)
        parser.add_argument(
            "--start-time", help="Logs start time (format now-10m, now-1h)")
        parser.add_argument("--end-time", help="Logs end time")
        parser.add_argument(
            "--last", help="Logs from last time period (format 10m, 1d)")
        parser.add_argument(
            "--table", help="StatTable to query", choices=stat_table_list)
        parser.add_argument(
            "--dtable", help="Dynamic StatTable to query")
        parser.add_argument(
            "--select", help="List of Select Terms", nargs='+')
        parser.add_argument(
            "--where", help="List of Where Terms to be ANDed", nargs='+')
        parser.add_argument(
            "--sort", help="List of Sort Terms", nargs='+')
        self._args = parser.parse_args(remaining_argv)

        self._args.admin_user = args.admin_user
        self._args.admin_password = args.admin_password
        self._args.analytics_api_ip = args.analytics_api_ip
        self._args.analytics_api_port = args.analytics_api_port

        if self._args.table is None and self._args.dtable is None:
#.........这里部分代码省略.........
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:103,代码来源:stats.py


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