本文整理汇总了Python中pybvc.openflowdev.ofswitch.OFSwitch.add_modify_flow_json方法的典型用法代码示例。如果您正苦于以下问题:Python OFSwitch.add_modify_flow_json方法的具体用法?Python OFSwitch.add_modify_flow_json怎么用?Python OFSwitch.add_modify_flow_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybvc.openflowdev.ofswitch.OFSwitch
的用法示例。
在下文中一共展示了OFSwitch.add_modify_flow_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_flow
# 需要导入模块: from pybvc.openflowdev.ofswitch import OFSwitch [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.OFSwitch import add_modify_flow_json [as 别名]
def add_flow(self, options):
parser = argparse.ArgumentParser(
prog=self.prog,
description="Add flow entries to the Controller's cache",
usage="%(prog)s add-flow -s=SWITCHID|--switch=SWICTHID\n"
" -f <path>|--file <path>\n"
" [--dry-run]\n"
"\n\n"
"Add flow entries to the Controller's cache\n\n"
"\n\n"
"Options:\n"
" -s, --switch switch identifier\n"
" -f, --file path to the file containing flow entries\n"
" (default is './flow.json')\n"
" -dry-run show content of flow(s) to be created"
)
parser.add_argument('-s', '--switch', metavar = "SWITCHID")
parser.add_argument('-f', '--file', metavar="<path>",
dest='flow_file',
help="path to the file containing flow entries "
"(default is './flow.json')",
default="./flow.json")
parser.add_argument('-U', action="store_true", dest="usage",
help=argparse.SUPPRESS)
parser.add_argument('--dry-run', action="store_true",
dest='dry_run', default=False)
args = parser.parse_args(options)
if(args.usage):
parser.print_usage()
print "\n".strip()
return
if(args.dry_run):
flows = self.read_flows(args.flow_file)
if flows:
for flow in flows:
print json.dumps(flow, indent=4)
return
if (args.switch == None):
msg = "option -s (or --switch) is required"
parser.error(msg)
flows = self.read_flows(args.flow_file)
if not flows:
print "Failed to execute command, exit"
exit(1)
print "\n".strip()
print " [Controller '%s']" % self.ctrl_cfg.to_string()
print "\n".strip()
ctrl = Controller(self.ctrl_cfg.ip_addr, self.ctrl_cfg.tcp_port,
self.ctrl_cfg.admin_name, self.ctrl_cfg.admin_pswd)
ofswitch = OFSwitch(ctrl, args.switch)
try:
for flow in flows:
fid = flow['id']
tid = flow['table_id']
js = json.dumps(flow, default=lambda o: o.__dict__)
result = ofswitch.add_modify_flow_json(table_id=tid, flow_id=fid,flow_json=js)
status = result.get_status()
if(status.eq(STATUS.OK) == True):
print "Flow id '%s', success" % fid
else:
print "Flow id '%s', failure, reason: %s" % (fid, status.detailed())
print "\n".strip()
except(Exception) as e:
msg = "Error: %s" % repr(e)
dbg_print(msg)