本文整理汇总了Python中opserver.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.opserver_util.OpServerUtils
的用法示例。
在下文中一共展示了OpServerUtils.str_to_ip_protocol方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_args
# 需要导入模块: from opserver.opserver_util import OpServerUtils [as 别名]
# 或者: from opserver.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