本文整理汇总了Python中opserver_util.OpServerUtils.parse_start_end_time方法的典型用法代码示例。如果您正苦于以下问题:Python OpServerUtils.parse_start_end_time方法的具体用法?Python OpServerUtils.parse_start_end_time怎么用?Python OpServerUtils.parse_start_end_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opserver_util.OpServerUtils
的用法示例。
在下文中一共展示了OpServerUtils.parse_start_end_time方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [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
示例2: main
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
def main():
try:
querier = LogQuerier()
if querier.parse_args() != 0:
return
if querier._args.f:
start_time = UTCTimestampUsec() - 10 * pow(10, 6)
while True:
querier._start_time = start_time
querier._end_time = UTCTimestampUsec()
start_time = querier._end_time + 1
time.sleep(3)
result = querier.query()
if result == -1:
return
querier.display(result)
else:
start_time = querier._args.start_time
end_time = querier._args.end_time
if not querier._args.start_time:
start_time = "now-10m"
if not querier._args.end_time:
end_time = "now"
try:
querier._start_time, querier._end_time = OpServerUtils.parse_start_end_time(
start_time=start_time, end_time=end_time, last=querier._args.last
)
except:
return -1
result = querier.query()
if result == -1:
return
querier.display(result)
except KeyboardInterrupt:
return
示例3: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
def parse_args(self):
"""
Eg. python stats.py --analytics-api-ip 127.0.0.1
--analytics-api-port 8081
--table AnalyticsCpuState.cpu_info
--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 AnalyticsCpuState.cpu_info
"""
defaults = {
'analytics_api_ip': '127.0.0.1',
'analytics_api_port': '8081',
'start_time': 'now-10m',
'end_time': 'now',
'select' : [],
'where' : ['Source=*'],
'sort': []
}
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.set_defaults(**defaults)
parser.add_argument("--analytics-api-ip", help="IP address of Analytics API Server")
parser.add_argument("--analytics-api-port", help="Port of Analytcis API Server")
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()
if self._args.table is None and self._args.dtable is None:
return -1
try:
self._start_time, self._end_time = \
OpServerUtils.parse_start_end_time(
start_time = self._args.start_time,
end_time = self._args.end_time,
last = self._args.last)
except:
return -1
return 0
示例4: run
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
def run(self):
try:
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
示例5: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
def parse_args(self):
"""
Eg. python flow.py --analytics-api-ip 127.0.0.1
--analytics-api-port 8081
--vrouter a6s23
--source-vn default-domain:default-project:vn1
--destination-vn default-domain:default-project:vn2
--source-ip 1.1.1.1
--destination-ip 2.2.2.2
--protocol TCP
--source-port 32678
--destination-port 80
--action drop
--direction ingress
--vrouter-ip 172.16.0.1
--other-vrouter-ip 172.32.0.1
--tunnel-info
[--start-time now-10m --end-time now] | --last 10m
"""
defaults = {
'analytics_api_ip': '127.0.0.1',
'analytics_api_port': '8081',
'start_time': 'now-10m',
'end_time': 'now',
'direction' : 'ingress',
}
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.set_defaults(**defaults)
parser.add_argument("--analytics-api-ip",
help="IP address of Analytics API Server")
parser.add_argument("--analytics-api-port",
help="Port of Analytics API Server")
parser.add_argument(
"--start-time", help="Flow record start time (format now-10m, now-1h)")
parser.add_argument("--end-time", help="Flow record end time")
parser.add_argument(
"--last", help="Flow records from last time period (format 10m, 1d)")
parser.add_argument("--vrouter", help="Flow records from vrouter")
parser.add_argument("--source-vn",
help="Flow records with source virtual network")
parser.add_argument("--destination-vn",
help="Flow records with destination virtual network")
parser.add_argument("--source-ip",
help="Flow records with source IP address")
parser.add_argument("--destination-ip",
help="Flow records with destination IP address")
parser.add_argument("--protocol", help="Flow records with protocol")
parser.add_argument("--source-port",
help="Flow records with source port", type=int)
parser.add_argument("--destination-port",
help="Flow records with destination port", type=int)
parser.add_argument("--action", help="Flow records with action")
parser.add_argument("--direction", help="Flow direction",
choices=['ingress', 'egress'])
parser.add_argument("--vrouter-ip",
help="Flow records from vrouter IP address")
parser.add_argument("--other-vrouter-ip",
help="Flow records to vrouter IP address")
parser.add_argument("--tunnel-info", action="store_true",
help="Show flow tunnel information")
parser.add_argument("--vmi-uuid",
help="Show vmi uuid information")
parser.add_argument(
"--verbose", action="store_true", help="Show internal information")
self._args = parser.parse_args()
try:
self._start_time, self._end_time = \
OpServerUtils.parse_start_end_time(
start_time = self._args.start_time,
end_time = self._args.end_time,
last = self._args.last)
except:
return -1
# Validate flow arguments
if self._args.source_ip is not None and self._args.source_vn is None:
print 'Please provide source virtual network in addtion to '\
'source IP address'
return -1
if self._args.destination_ip is not None and \
self._args.destination_vn is None:
print 'Please provide destination virtual network in addtion to '\
'destination IP address'
return -1
if self._args.source_port is not None and self._args.protocol is None:
print 'Please provide protocol in addtion to source port'
return -1
if self._args.destination_port is not None and \
self._args.protocol is None:
print 'Please provide protocol in addtion to '\
'destination port'
return -1
# Convert direction
if self._args.direction.lower() == "ingress":
self._args.direction = 1
elif self._args.direction.lower() == "egress":
#.........这里部分代码省略.........
示例6: run
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
def run(self):
try:
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
start_time = self._start_time
end_time = self._end_time
result_list = []
while int(end_time) - int(start_time) > 0:
if not self._args.reverse:
self._start_time = start_time
self._end_time = start_time + 10*60*pow(10,6) if (start_time + 10*60*pow(10,6) <= int(end_time)) else int(end_time)
else:
self._end_time = end_time
self._start_time = end_time - 10*60*pow(10,6) if (end_time - 10*60*pow(10,6) >= int(start_time)) else int(start_time)
p = Process(target=self.display, args=(result_list,))
p.start()
result = self.query()
if result == -1:
return
# Accumulate the result before processing it as the
# formatting of result can be cpu intensive and hence would
# affect the overall time taken to fetch the result from the
# analytics-api. Since the query result ttl is set to 5 min
# in redis, it is necessary to improve the read throughput.
result_list = self.read_result(result)
p.join()
if not self._args.reverse:
start_time = self._end_time + 1
else:
end_time = self._start_time - 1
self.display(result_list)
except KeyboardInterrupt:
return
示例7: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
def parse_args(self):
"""
Eg. python log.py --opserver-ip 127.0.0.1
--opserver-port 8081
--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
"""
defaults = {"opserver_ip": "127.0.0.1", "opserver_port": "8081", "start_time": "now-10m", "end_time": "now"}
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.set_defaults(**defaults)
parser.add_argument("--opserver-ip", help="IP address of OpServer")
parser.add_argument("--opserver-port", help="Port of OpServer")
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", help="Logs from source address")
parser.add_argument("--node-type", help="Logs from node type", choices=NodeTypeNames.values())
parser.add_argument("--module", help="Logs from module", 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")
parser.add_argument("--message-type", help="Logs of message type")
parser.add_argument("--reverse", action="store_true", help="Show logs in reverse chronological order")
parser.add_argument("--verbose", action="store_true", help="Show internal information")
parser.add_argument("--all", action="store_true", help="Show all logs")
parser.add_argument("--raw", action="store_true", help="Show raw XML messages")
parser.add_argument("--object-type", help="Logs of object type", choices=OBJECT_TYPE_LIST)
parser.add_argument("--object-values", action="store_true", help="Display list of object names")
parser.add_argument("--object-id", help="Logs of object name")
parser.add_argument(
"--object-select-field",
help="Select field to filter the log",
choices=[VizConstants.OBJECT_LOG, VizConstants.SYSTEM_LOG],
)
parser.add_argument("--trace", help="Dump trace buffer")
parser.add_argument("--limit", help="Limit the number of messages")
parser.add_argument("--send-syslog", action="store_true", help="Send syslog to specified server and port")
parser.add_argument("--syslog-server", help="IP address of syslog server", default="localhost")
parser.add_argument("--syslog-port", help="Port to send syslog to", type=int, default=514)
self._args = parser.parse_args()
try:
self._start_time, self._end_time = OpServerUtils.parse_start_end_time(
start_time=self._args.start_time, end_time=self._args.end_time, last=self._args.last
)
except:
return -1
return 0
示例8: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
#.........这里部分代码省略.........
args.admin_user = defaults['admin_user']
if args.admin_password == None:
args.admin_password = defaults['admin_password']
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("--analytics-api-ip",
help="IP address of Analytics API Server")
parser.add_argument("--analytics-api-port",
help="Port of Analytics API Server")
parser.add_argument(
"--start-time", help="Flow record start time (format now-10m, now-1h)")
parser.add_argument("--end-time", help="Flow record end time")
parser.add_argument(
"--last", help="Flow records from last time period (format 10m, 1d)")
parser.add_argument("--vrouter", help="Flow records from vrouter")
parser.add_argument("--source-vn",
help="Flow records with source virtual network")
parser.add_argument("--destination-vn",
help="Flow records with destination virtual network")
parser.add_argument("--source-ip",
help="Flow records with source IP address")
parser.add_argument("--destination-ip",
help="Flow records with destination IP address")
parser.add_argument("--protocol", help="Flow records with protocol")
parser.add_argument("--source-port",
help="Flow records with source port", type=int)
parser.add_argument("--destination-port",
help="Flow records with destination port", type=int)
parser.add_argument("--action", help="Flow records with action")
parser.add_argument("--direction", help="Flow direction",
choices=['ingress', 'egress'])
parser.add_argument("--vrouter-ip",
help="Flow records from vrouter IP address")
parser.add_argument("--other-vrouter-ip",
help="Flow records to vrouter IP address")
parser.add_argument("--tunnel-info", action="store_true",
help="Show flow tunnel information")
parser.add_argument("--vmi-uuid",
help="Show vmi uuid information")
parser.add_argument(
"--verbose", action="store_true", help="Show internal information")
self._args = parser.parse_args(remaining_argv)
self._args.admin_user = args.admin_user
self._args.admin_password = args.admin_password
try:
self._start_time, self._end_time = \
OpServerUtils.parse_start_end_time(
start_time = self._args.start_time,
end_time = self._args.end_time,
last = self._args.last)
except:
return -1
# Validate flow arguments
if self._args.source_ip is not None and self._args.source_vn is None:
print 'Please provide source virtual network in addtion to '\
'source IP address'
return -1
if self._args.destination_ip is not None and \
self._args.destination_vn is None:
print 'Please provide destination virtual network in addtion to '\
'destination IP address'
return -1
if self._args.source_port is not None and self._args.protocol is None:
print 'Please provide protocol in addtion to source port'
return -1
if self._args.destination_port is not None and \
self._args.protocol is None:
print 'Please provide protocol in addtion to '\
'destination port'
return -1
# Convert direction
if self._args.direction.lower() == "ingress":
self._args.direction = 1
elif self._args.direction.lower() == "egress":
self._args.direction = 0
else:
print 'Direction should be ingress or egress'
return -1
# Protocol
if self._args.protocol is not None:
if self._args.protocol.isalpha():
protocol = OpServerUtils.str_to_ip_protocol(
self._args.protocol)
if protocol == -1:
print 'Please provide valid protocol'
return -1
self._args.protocol = protocol
return 0
示例9: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import parse_start_end_time [as 别名]
#.........这里部分代码省略.........
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:
return -1
try:
self._start_time, self._end_time = \
OpServerUtils.parse_start_end_time(
start_time = self._args.start_time,
end_time = self._args.end_time,
last = self._args.last)
except:
return -1
return 0