def main(): try: CONF(project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ryu-manager %s' % version) log.init_log() app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(): try: CONF(project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ryu-manager %s' % version) log.init_log() app_lists = CONF.app_lists + CONF.app app_mgr = AppManager() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() app_mgr.instantiate_apps(**contexts) services = [] # TODO: do the following in app_manager's instantiate_apps() ofpapp = controller.start_service(app_mgr) if ofpapp: thr = hub.spawn(ofpapp) services.append(thr) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(): try: CONF(project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ryu-manager %s' % version) log.init_log() # always enable ofp for now. app_lists = CONF.app_lists + CONF.app + ['ryu.controller.ofp_handler'] app_mgr = AppManager() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() app_mgr.instantiate_apps(**contexts) services = [] ctlr = controller.OpenFlowController() thr = hub.spawn(ctlr) services.append(thr) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): # 加载函数库 _parse_user_flags() # 加载配置文件 try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. # 如果配置文件的列表为空,则加载ryu.controller.ofp_handler if not app_lists: app_lists = ['ryu.controller.ofp_handler'] # 创建实例,调用get_instance,实现单例模式 app_mgr = AppManager.get_instance() # 加载app_lists中的app app_mgr.load_apps(app_lists) # 创建上下文 contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) # 加入services列表 services.append(thr) try: # 对server服务列表遍历wait hub.joinall(services) except KeyboardInterrupt: # KeyboardInterrupt 用户中断执行(通常是输入^C) logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def main(args=None, prog=None): _parse_user_flags() try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # print('1:app_lists:',app_lists) #('1:app_lists:', []) # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() # print('2:app_mgr',app_mgr) #('2:app_mgr', <ryu.base.app_manager.AppManager object at 0x7ff3ce974450>) app_mgr.load_apps(app_lists) # print('17:app_lists:',app_lists) #('17:app_lists:', ['ryu.controller.ofp_handler']) contexts = app_mgr.create_contexts() # print('22:contexts',contexts) #('22:contexts', {}) services = [] services.extend(app_mgr.instantiate_apps(**contexts)) # print('services:',services) #('services:', [<eventlet.greenthread.GreenThread object at 0x7f4f3540c190>]) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def main(args=None, prog=None): _parse_user_flags() try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) # sys.stdout.write("hello world!\n") contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: for name, app in app_mgr.applications.items(): if getattr(app, "set_xml", None): app.set_xml() app_mgr.close()
def main(args=None, prog=None): _parse_user_flags() try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] # step1: 实例化AppManager,是之后管理的基础 app_mgr = AppManager.get_instance() # step2:加载需要的服务,并不实例化,只是保存在对应字典中,还要加载每个app所需要的app app_mgr.load_apps(app_lists) # step3:实例化依赖模块,上面的APP可能需要其他模块服务,进行实例化 contexts = app_mgr.create_contexts() services = [] # step4:关键的一步,实例化app services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] #if CONF.oxp_role == 'super': # app_lists.extend(['ryu.openexchange.super.oxp_server_handler', # 'ryu.openexchange.super.topology', # 'ryu.openexchange.super.routing']) #elif CONF.oxp_role == 'domain': # app_lists.extend( # ['ryu.openexchange.domain.oxp_client_handler', # 'ryu.openexchange.network.abstract', # 'ryu.openexchange.network.topo_reply', # 'ryu.openexchange.network.echo_loop', # 'ryu.openexchange.domain.translation']) app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager {}'.format(version), default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager {}'.format(version)) log.init_log() hub.patch(thread=True) if CONF.pid_file: LOG.info('Pid file : %s', CONF.pid_file) import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app if not app_lists: app_lists = ['ryu.controller.ofp_handler', 'dragon_knight.dk_plugin'] if 'ryu.controller.ofp_handler' not in app_lists: app_lists.append('ryu.controller.ofp_handler') if 'dragon_knight.dk_plugin' not in app_lists: app_lists.append('dragon_knight.dk_plugin') app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF( args=args, prog=prog, project="ryu", version="ryu-manager {}".format(version), default_config_files=["/usr/local/etc/ryu/ryu.conf"], ) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project="ryu", version="ryu-manager {}".format(version)) log.init_log() hub.patch(thread=True) if CONF.pid_file: LOG.info("Pid file : %s", CONF.pid_file) import os with open(CONF.pid_file, "w") as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app if not app_lists: app_lists = ["ryu.controller.ofp_handler", "dragon_knight.dk_plugin"] if "ryu.controller.ofp_handler" not in app_lists: app_lists.append("ryu.controller.ofp_handler") if "dragon_knight.dk_plugin" not in app_lists: app_lists.append("dragon_knight.dk_plugin") app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() if CONF.enable_debugger: LOG = logging.getLogger('ryu.cmd.manager') msg = 'debugging is available (--enable-debugger option is turned on)' LOG.info(msg) else: hub.patch(thread=True) if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def main(): log.init_log() app_mgr = AppManager.get_instance() app_mgr.load_apps(['./ryu_controller.py']) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) print services try: hub.joinall(services) finally: app_mgr.close()
def main(): config_file = None try: config_file = '/usr/local/etc/ryu/ryu.conf' CONF(project='ryu', version='ryu-manager %s' % version, default_config_files=[config_file]) except cfg.ConfigFilesNotFoundError: try: config_file = os.path.join(TOP_DIR, 'etc/ryu/inception.conf') CONF(project='ryu', version='ryu-manager %s' % version, default_config_files=[config_file]) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ryu-manager %s' % version) log.init_log() LOGGER.info('config_file=%s', config_file) LOGGER.info('ZooKeeper servers=%s', CONF.zk_servers) zk = KazooClient(hosts=CONF.zk_servers, logger=LOGGER) zk.start() election = zk.Election(CONF.zk_election) LOGGER.info('Contending to be the leader...') election.run(real_main)
def main(): args = sys.argv[1:] try: CONF(args=args, prog=sys.argv[0], project='daolicontroller', version='1.1', default_config_files=['/etc/daolicontroller/daolicontroller.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=sys.argv[0], project='daolicontroller', version='1.1') log.init_log() #if ryu_cfg.CONF is not CONF: # ryu_cfg.CONF(args=args, project='ryu') #if CONF.enable_debugger: # LOG = logging.getLogger('daolicontroller') # msg = 'debugging is available (--enable-debugger option is turned on)' # LOG.info(msg) #else: #hub.patch(thread=True) AppManager.run_apps(['daolicontroller.ofa_agent'])
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app print(app_lists) # keep old behavior, run ofp if no application is specified. if not app_lists: #app_lists = ['ryu.controller.ofp_handler'] app_lists = ['ryu.app.rest_firewall'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts))
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] # add oxp_handler #app_lists.append('ryu.openexchange.oxp_handler') app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF( args=args, prog=prog, project='daolicontroller', version='1.1', default_config_files=['/etc/daolicontroller/daolicontroller.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='daolicontroller', version='1.1') log.init_log() if ryu_cfg.CONF is not CONF: ryu_cfg.CONF(args=args, project='ryu') if CONF.enable_debugger: LOG = logging.getLogger('daolicontroller') msg = 'debugging is available (--enable-debugger option is turned on)' LOG.info(msg) else: hub.patch(thread=True) AppManager.run_apps(['daolicontroller.ofa_agent'])
def load_tests(loader, tests, pattern): dirname = os.path.dirname(os.path.abspath(__file__)) base_path = os.path.abspath(dirname + '/../..') suite = unittest.TestSuite() for test_dir in ['tests/integrated/bgp']: if not pattern: suite.addTests(loader.discover(test_dir, top_level_dir=base_path)) else: suite.addTests( loader.discover(test_dir, pattern=pattern, top_level_dir=base_path)) return suite if __name__ == '__main__': log.early_init_log(logging.DEBUG) log.init_log() LOG = logging.getLogger(__name__) pattern = None if len(sys.argv) == 2: pattern = sys.argv[1] loader = unittest.defaultTestLoader suite = load_tests(loader, None, pattern) res = unittest.TextTestRunner(verbosity=2).run(suite) ret = 0 if res.errors or res.failures: ret = 1 sys.exit(ret)
def main(args=None, prog=None): print('aaa') try: print('aaa') CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app print(app_lists) # keep old behavior, run ofp if no application is specified. if not app_lists: #app_lists = ['ryu.controller.ofp_handler'] print('bbb') app_lists = ['ryu.app.rest_firewall'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() print('contexts:') print(contexts) services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) print('ccc') print(webapp) if webapp: thr = hub.spawn(webapp) services.append(thr) print('ddd') try: print(services[0]) services[1].wait() print('eee3') services[0].wait() print('eee') hub.joinall(services) print('fff') except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def load_tests(loader, tests, pattern): dirname = os.path.dirname(os.path.abspath(__file__)) base_path = os.path.abspath(dirname + '/../../..') suite = unittest.TestSuite() for test_dir in ['ryu/tests/integrated/bgp']: if not pattern: suite.addTests(loader.discover(test_dir, top_level_dir=base_path)) else: suite.addTests(loader.discover(test_dir, pattern=pattern, top_level_dir=base_path)) return suite if __name__ == '__main__': log.early_init_log(logging.DEBUG) log.init_log() LOG = logging.getLogger(__name__) pattern = None if len(sys.argv) == 2: pattern = sys.argv[1] loader = unittest.defaultTestLoader suite = load_tests(loader, None, pattern) res = unittest.TextTestRunner(verbosity=2).run(suite) ret = 0 if res.errors or res.failures: ret = 1 sys.exit(ret)