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


Python OFSwitch.add_modify_flow_json方法代码示例

本文整理汇总了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)
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:74,代码来源:oftool.py


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