summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorNachi Ueno <ueno.nachi@lab.ntt.co.jp>2011-08-19 12:30:55 -0700
committerNachi Ueno <ueno.nachi@lab.ntt.co.jp>2011-08-19 12:30:55 -0700
commitc06bbe99734f2fea35cfb4bdd854814c9119b617 (patch)
treeba7187f91ce12a2dbd8e3b6ab5bee8a8e8569cce /nova
parentaca07a42fabb7f506cf132b995b4ad0139987b02 (diff)
downloadnova-c06bbe99734f2fea35cfb4bdd854814c9119b617.tar.gz
nova-c06bbe99734f2fea35cfb4bdd854814c9119b617.tar.xz
nova-c06bbe99734f2fea35cfb4bdd854814c9119b617.zip
Added monkey patching notification code function
w
Diffstat (limited to 'nova')
-rw-r--r--nova/flags.py8
-rw-r--r--nova/notifier/api.py18
-rw-r--r--nova/utils.py24
3 files changed, 49 insertions, 1 deletions
diff --git a/nova/flags.py b/nova/flags.py
index 48d5e8168..09c30c7c0 100644
--- a/nova/flags.py
+++ b/nova/flags.py
@@ -402,3 +402,11 @@ DEFINE_bool('resume_guests_state_on_host_boot', False,
DEFINE_string('root_helper', 'sudo',
'Command prefix to use for running commands as root')
+
+DEFINE_bool('monkey_patch', False,
+ 'Whether to monkey patch')
+
+DEFINE_list('monkey_patch_modules',
+ ['nova.api.ec2.cloud:nova.notifier.api.notify_decorator',
+ 'nova.compute.api:nova.notifier.api.notify_decorator'],
+ 'Module list representng monkey patched module and decorator')
diff --git a/nova/notifier/api.py b/nova/notifier/api.py
index e18f3e280..ca0ff60a4 100644
--- a/nova/notifier/api.py
+++ b/nova/notifier/api.py
@@ -39,6 +39,24 @@ class BadPriorityException(Exception):
pass
+def notify_decorator(name, fn):
+ def wrapped_func(*args, **kwarg):
+ body = {}
+ body['args'] = []
+ body['kwarg'] = {}
+ for arg in args:
+ body['args'].append(arg)
+ for key in kwarg:
+ body['kwarg'][key] = kwarg[key]
+ LOG.debug("Notify Decorator: %s %r" % (name, body))
+ notify(FLAGS.host,
+ name,
+ DEBUG,
+ body)
+ fn(*args, **kwarg)
+ return wrapped_func
+
+
def publisher_id(service, host=None):
if not host:
host = FLAGS.host
diff --git a/nova/utils.py b/nova/utils.py
index 7276b6bd5..8024a3517 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -35,6 +35,7 @@ import sys
import time
import types
import uuid
+import pyclbr
from xml.sax import saxutils
from eventlet import event
@@ -634,7 +635,7 @@ def synchronized(name, external=False):
Different methods can share the same lock:
@synchronized('mylock')
- def foo(self, *args):
+ Gdef foo(self, *args):
...
@synchronized('mylock')
@@ -873,3 +874,24 @@ class Bootstrapper(object):
for key in FLAGS:
value = FLAGS.get(key, None)
logging.audit(_("%(key)s : %(value)s" % locals()))
+
+
+def monkey_patch():
+ if not FLAGS.monkey_patch:
+ return
+ for module_and_decorator in FLAGS.monkey_patch_modules:
+ module, decorator_name = module_and_decorator.split(':')
+ decorator = import_class(decorator_name)
+ __import__(module)
+ module_data = pyclbr.readmodule_ex(module)
+ for key in module_data.keys():
+ if isinstance(module_data[key], pyclbr.Class):
+ clz = import_class("%s.%s" % (module, key))
+ for method, func in inspect.getmembers(clz, inspect.ismethod):
+ setattr(clz, method,\
+ decorator("%s.%s" % (module, key), func))
+ if isinstance(module_data[key], pyclbr.Function):
+ func = import_class("%s.%s" % (module, key))
+ setattr(sys.modules[module], key,\
+ setattr(sys.modules[module], key, \
+ decorator("%s.%s" % (module, key), func)))