diff options
| author | Nachi Ueno <ueno.nachi@lab.ntt.co.jp> | 2011-08-19 12:30:55 -0700 |
|---|---|---|
| committer | Nachi Ueno <ueno.nachi@lab.ntt.co.jp> | 2011-08-19 12:30:55 -0700 |
| commit | c06bbe99734f2fea35cfb4bdd854814c9119b617 (patch) | |
| tree | ba7187f91ce12a2dbd8e3b6ab5bee8a8e8569cce | |
| parent | aca07a42fabb7f506cf132b995b4ad0139987b02 (diff) | |
| download | nova-c06bbe99734f2fea35cfb4bdd854814c9119b617.tar.gz nova-c06bbe99734f2fea35cfb4bdd854814c9119b617.tar.xz nova-c06bbe99734f2fea35cfb4bdd854814c9119b617.zip | |
Added monkey patching notification code function
w
| -rwxr-xr-x | bin/nova-api | 2 | ||||
| -rwxr-xr-x | bin/nova-compute | 1 | ||||
| -rwxr-xr-x | bin/nova-network | 1 | ||||
| -rwxr-xr-x | bin/nova-objectstore | 1 | ||||
| -rwxr-xr-x | bin/nova-scheduler | 1 | ||||
| -rw-r--r-- | nova/flags.py | 8 | ||||
| -rw-r--r-- | nova/notifier/api.py | 18 | ||||
| -rw-r--r-- | nova/utils.py | 24 | ||||
| -rw-r--r-- | tools/pip-requires | 1 |
9 files changed, 55 insertions, 2 deletions
diff --git a/bin/nova-api b/bin/nova-api index fe8e83366..4edf77c7f 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -45,7 +45,7 @@ FLAGS = flags.FLAGS def main(): """Launch EC2 and OSAPI services.""" nova.utils.Bootstrapper.bootstrap_binary(sys.argv) - + nova.utils.monkey_patch() launcher = nova.service.Launcher() for api in FLAGS.enabled_apis: diff --git a/bin/nova-compute b/bin/nova-compute index cd7c78def..1de53c075 100755 --- a/bin/nova-compute +++ b/bin/nova-compute @@ -45,5 +45,6 @@ if __name__ == '__main__': utils.default_flagfile() flags.FLAGS(sys.argv) logging.setup() + utils.monkey_patch() service.serve() service.wait() diff --git a/bin/nova-network b/bin/nova-network index 101761ef7..5b66b8f2b 100755 --- a/bin/nova-network +++ b/bin/nova-network @@ -45,5 +45,6 @@ if __name__ == '__main__': utils.default_flagfile() flags.FLAGS(sys.argv) logging.setup() + utils.monkey_patch() service.serve() service.wait() diff --git a/bin/nova-objectstore b/bin/nova-objectstore index 4d5aec445..c2860f534 100755 --- a/bin/nova-objectstore +++ b/bin/nova-objectstore @@ -49,6 +49,7 @@ if __name__ == '__main__': utils.default_flagfile() FLAGS(sys.argv) logging.setup() + utils.monkey_patch() router = s3server.S3Application(FLAGS.buckets_path) server = wsgi.Server("S3 Objectstore", router, diff --git a/bin/nova-scheduler b/bin/nova-scheduler index 0c205a80f..ae3db51bc 100755 --- a/bin/nova-scheduler +++ b/bin/nova-scheduler @@ -45,5 +45,6 @@ if __name__ == '__main__': utils.default_flagfile() flags.FLAGS(sys.argv) logging.setup() + utils.monkey_patch() service.serve() service.wait() 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))) diff --git a/tools/pip-requires b/tools/pip-requires index 60b502ffd..7eb220a95 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -34,3 +34,4 @@ coverage nosexcover GitPython paramiko +pyclbr |
