From 63cc49360e89a337faa6f76d4d143d34de9fdf9f Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sat, 9 Jun 2012 20:06:19 +0900 Subject: [PATCH] Pass AppManager module name instead of class name RyuApp class is used as a base class for Ryu network application. So let's pass Ryu application module name instead of class name. Signed-off-by: FUJITA Tomonori Reviewed-by: Isaku Yamahata --- bin/ryu-manager | 5 ++--- ryu/base/app_manager.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bin/ryu-manager b/bin/ryu-manager index 2437275d..43e0cba4 100755 --- a/bin/ryu-manager +++ b/bin/ryu-manager @@ -35,9 +35,8 @@ from ryu.controller import controller FLAGS = gflags.FLAGS gflags.DEFINE_multistring('app_lists', - ['ryu.app.simple_isolation.SimpleIsolation', - 'ryu.app.rest.restapi', - # 'ryu.app.event_dumper.EventDumper', + ['ryu.app.simple_isolation', + 'ryu.app.rest', ], 'application module name to run') diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index 19e93160..7b44eed0 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2011, 2012 Nippon Telegraph and Telephone Corporation. # Copyright (C) 2011 Isaku Yamahata # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -69,6 +69,16 @@ class AppManager(object): self.contexts_cls = {} self.contexts = {} + def load_app(self, name): + mod = utils.import_module(name) + for k, v in mod.__dict__.items(): + try: + if issubclass(v, RyuApp): + return getattr(mod, k) + except TypeError: + pass + return None + def load_apps(self, app_lists): for app_cls_name in itertools.chain.from_iterable([app_list.split(',') for app_list @@ -80,7 +90,10 @@ class AppManager(object): # Yes, maybe for slicing. assert app_cls_name not in self.applications_cls - cls = utils.import_object(app_cls_name) + cls = self.load_app(app_cls_name) + if cls is None: + continue + self.applications_cls[app_cls_name] = cls for key, context_cls in cls.context_iteritems():