app_manager: allow separated modules of Event and RyuApp

Because handler.set_ev_cls() sets observer to module of ev_cls,
Event class and RyuApp must be in same module now.

This patch let RyuApp have a list of events to be generated in app.
So, AppManager can bind sender app and receiver app via event class.

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
2013-02-22 19:14:18 +09:00
committed by FUJITA Tomonori
parent 0fab6cdf2f
commit 817baee386

View File

@@ -46,6 +46,7 @@ class RyuApp(object):
Base class for Ryu network application
"""
_CONTEXTS = {}
_EVENTS = [] # list of events to be generated in app
@classmethod
def context_iteritems(cls):
@@ -179,11 +180,18 @@ class AppManager(object):
for key, i in SERVICE_BRICKS.items():
for _k, m in inspect.getmembers(i, inspect.ismethod):
if hasattr(m, 'observer'):
# name is module name of ev_cls
name = m.observer.split('.')[-1]
if name in SERVICE_BRICKS:
brick = SERVICE_BRICKS[name]
brick.register_observer(m.ev_cls, i.name)
# allow RyuApp and Event class are in different module
if hasattr(m, 'ev_cls'):
for brick in SERVICE_BRICKS.itervalues():
if m.ev_cls in brick._EVENTS:
brick.register_observer(m.ev_cls, i.name)
for brick, i in SERVICE_BRICKS.items():
LOG.debug("BRICK %s" % brick)
for ev_cls, list in i.observers.items():