Hi
I am working on dynamic application loader for ryu, base on ryu-manager.
I tried App_manager.instantiate(app_class) and it works
However, if the _CONTEXT in app is not empty, it raised 'KeyError'
The reason is that instantiate method in app manager does not create
context instance from app class
If we want to use instantiate method in AppManager with new context, we
need to create context before we call "_instantiate" method.
>From 2eaace91ee70e489ca51f240615b1744c024d1be Mon Sep 17 00:00:00 2001
From: Takeshi <[email protected]>
Date: Sat, 11 Apr 2015 22:14:02 +0800
Subject: [PATCH 4/4] add "fix context not exist problem while using
AppManager.instantiate
Signed-off-by: Takeshi <[email protected]>
---
ryu/base/app_manager.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index f0137ea..fe055b0 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -418,6 +418,17 @@ class AppManager(object):
self.contexts[key] = context
return self.contexts
+ def add_context(self, key, context_cls):
+ if issubclass(context_cls, RyuApp):
+ # hack for dpset
+ context = self._instantiate(None, context_cls)
+
+ else:
+ context = context_cls()
+ LOG.info('creating context %s', key)
+ assert key not in self.contexts
+ self.contexts[key] = context
+
def _update_bricks(self):
for i in SERVICE_BRICKS.values():
for _k, m in inspect.getmembers(i, inspect.ismethod):
@@ -469,6 +480,11 @@ class AppManager(object):
return app
def instantiate(self, cls, *args, **kwargs):
+ # create context for new application
+ for key, context_cls in cls.context_iteritems():
+ self.add_context(key, context_cls)
+
+ kwargs.update(self.contexts)
app = self._instantiate(None, cls, *args, **kwargs)
self._update_bricks()
self._report_brick(app.name, app)
--
2.3.2 (Apple Git-55)
-----
Yi Tseng (Takeshi)
Taiwan National Chiao Tung University
Department of Computer Science
-----
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel