AppManager: Add a convenient method to run apps

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMAMOTO Takashi 2014-06-12 18:05:23 +09:00 committed by FUJITA Tomonori
parent 771fb79501
commit ecbb8640f5

View File

@ -31,6 +31,7 @@ import os
from ryu import cfg from ryu import cfg
from ryu import utils from ryu import utils
from ryu.app import wsgi
from ryu.controller.handler import register_instance, get_dependent_services from ryu.controller.handler import register_instance, get_dependent_services
from ryu.controller.controller import Datapath from ryu.controller.controller import Datapath
from ryu.controller import event from ryu.controller import event
@ -325,6 +326,25 @@ class AppManager(object):
# singletone # singletone
_instance = None _instance = None
@staticmethod
def run_apps(app_lists):
"""Run a set of Ryu applications
A convenient method to load and instantiate apps.
This blocks until all relevant apps stop.
"""
app_mgr = AppManager.get_instance()
app_mgr.load_apps(app_lists)
contexts = app_mgr.create_contexts()
services = app_mgr.instantiate_apps(**contexts)
webapp = wsgi.start_service(app_mgr)
if webapp:
services.append(hub.spawn(webapp))
try:
hub.joinall(services)
finally:
app_mgr.close()
@staticmethod @staticmethod
def get_instance(): def get_instance():
if not AppManager._instance: if not AppManager._instance: