本文整理汇总了Python中opserver_util.OpServerUtils.str_to_ip_protocol方法的典型用法代码示例。如果您正苦于以下问题:Python OpServerUtils.str_to_ip_protocol方法的具体用法?Python OpServerUtils.str_to_ip_protocol怎么用?Python OpServerUtils.str_to_ip_protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opserver_util.OpServerUtils
的用法示例。
在下文中一共展示了OpServerUtils.str_to_ip_protocol方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import str_to_ip_protocol [as 别名]
#.........这里部分代码省略.........
'opserver_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("--opserver-ip", help="IP address of OpServer")
parser.add_argument("--opserver-port", help="Port of OpServer")
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(
"--verbose", action="store_true", help="Show internal information")
self._args = parser.parse_args()
# Validate start-time and end-time
if self._args.last is not None:
self._args.last = '-' + self._args.last
self._start_time = OpServerUtils.convert_to_utc_timestamp_usec(
self._args.last)
self._end_time = OpServerUtils.convert_to_utc_timestamp_usec('now')
else:
try:
if (self._args.start_time.isdigit() and
self._args.end_time.isdigit()):
self._start_time = int(self._args.start_time)
self._end_time = int(self._args.end_time)
else:
self._start_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.start_time)
self._end_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.end_time)
except:
print 'Incorrect start-time (%s) or end-time (%s) format' %\
(self._args.start_time, self._args.end_time)
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
示例2: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import str_to_ip_protocol [as 别名]
#.........这里部分代码省略.........
--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":
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
示例3: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import str_to_ip_protocol [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