app_manager: Let application module to use require_app()

Signed-off-by: YAMADA Hideki <yamada.hideki@po.ntts.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMADA Hideki 2014-06-13 17:34:18 +09:00 committed by FUJITA Tomonori
parent 5474bf214c
commit a5c1841e44
4 changed files with 14 additions and 8 deletions

View File

@ -38,4 +38,4 @@ def send_msg(app, msg, reply_cls=None, reply_multi=False):
reply_multi=reply_multi))()
app_manager.require_app('ryu.app.ofctl.service')
app_manager.require_app('ryu.app.ofctl.service', api_style=True)

View File

@ -65,17 +65,23 @@ def unregister_app(app):
SERVICE_BRICKS.pop(app.name)
def require_app(app_name):
def require_app(app_name, api_style=False):
"""
Request the application to be loaded.
Request the application to be automatically loaded.
This is used for "api" style modules, which is imported by a client
application, to automatically load the corresponding server application.
If this is used for "api" style modules, which is imported by a client
application, set api_style=True.
If this is used for client application module, set api_style=False.
"""
if api_style:
frm = inspect.stack()[2] # skip a frame for "api" module
else:
frm = inspect.stack()[1]
m = inspect.getmodule(frm[0]) # client module
m._REQUIRED_APP = getattr(m, '_REQUIRED_APP', [])
m._REQUIRED_APP.append(app_name)
LOG.debug('require_app: %s is required by %s', app_name, m.__name__)
class RyuApp(object):

View File

@ -66,4 +66,4 @@ def vrrp_config_change(app, instance_name,
return app.send_event(vrrp_event.VRRP_MANAGER_NAME, config_change)
app_manager.require_app('ryu.services.protocols.vrrp.manager')
app_manager.require_app('ryu.services.protocols.vrrp.manager', api_style=True)

View File

@ -35,4 +35,4 @@ def get_all_link(app):
return get_link(app)
app_manager.require_app('ryu.topology.switches')
app_manager.require_app('ryu.topology.switches', api_style=True)