summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/cloud-init6
-rw-r--r--cloudinit/reporting/__init__.py11
-rw-r--r--cloudinit/reporting/handlers.py15
3 files changed, 23 insertions, 9 deletions
diff --git a/bin/cloud-init b/bin/cloud-init
index ad2e624a..86780408 100755
--- a/bin/cloud-init
+++ b/bin/cloud-init
@@ -138,8 +138,8 @@ def run_module_section(mods, action_name, section):
def apply_reporting_cfg(cfg):
- reporting.reset_configuration()
- reporting.update_configuration(cfg.get('reporting'), {})
+ if cfg.get('reporting'):
+ reporting.update_configuration(cfg.get('reporting'))
def main_init(name, args):
@@ -648,7 +648,7 @@ def main():
"running single module %s" % args.name)
report_on = args.report
- reporting.add_configuration({'print': {'type': 'print'}})
+ reporting.update_configuration({'print': {'type': 'print'}})
args.reporter = reporting.ReportEventStack(
rname, rdesc, reporting_enabled=report_on)
with args.reporter:
diff --git a/cloudinit/reporting/__init__.py b/cloudinit/reporting/__init__.py
index d0bc14e3..b9d4f679 100644
--- a/cloudinit/reporting/__init__.py
+++ b/cloudinit/reporting/__init__.py
@@ -9,8 +9,8 @@ The reporting framework is intended to allow all parts of cloud-init to
report events in a structured manner.
"""
-from cloudinit.registry import DictRegistry
-from cloudinit.reporting.handlers import available_handlers
+from ..registry import DictRegistry
+from ..reporting.handlers import available_handlers
FINISH_EVENT_TYPE = 'finish'
@@ -18,6 +18,7 @@ START_EVENT_TYPE = 'start'
DEFAULT_CONFIG = {
'logging': {'type': 'log'},
+ 'print': {'type': 'print'},
}
@@ -83,8 +84,14 @@ def update_configuration(config):
instantiated_handler_registry.unregister_item(
handler_name, force=True)
continue
+ registered = instantiated_handler_registry.registered_items
handler_config = handler_config.copy()
cls = available_handlers.registered_items[handler_config.pop('type')]
+ if (handler_name in registered and
+ (registered[handler_name] == handler_config)):
+ continue
+ else:
+ instantiated_handler_registry.unregister_item(handler_name)
instance = cls(**handler_config)
instantiated_handler_registry.register_item(handler_name, instance)
diff --git a/cloudinit/reporting/handlers.py b/cloudinit/reporting/handlers.py
index d8f69641..a962edae 100644
--- a/cloudinit/reporting/handlers.py
+++ b/cloudinit/reporting/handlers.py
@@ -6,9 +6,8 @@ import oauthlib.oauth1 as oauth1
import six
-from cloudinit.registry import DictRegistry
-from cloudinit import url_helper
-from cloudinit import util
+from ..registry import DictRegistry
+from .. import (url_helper, util)
@six.add_metaclass(abc.ABCMeta)
@@ -34,13 +33,19 @@ class LogHandler(ReportingHandler):
logger.info(event.as_string())
+class PrintHandler(ReportingHandler):
+ def publish_event(self, event):
+ """Publish an event to the ``INFO`` log level."""
+ print(event.as_string())
+
+
class WebHookHandler(ReportingHandler):
def __init__(self, endpoint, consumer_key=None, token_key=None,
token_secret=None, consumer_secret=None, timeout=None,
retries=None):
super(WebHookHandler, self).__init__()
- if any(consumer_key, token_key, token_secret, consumer_secret):
+ if any([consumer_key, token_key, token_secret, consumer_secret]):
self.oauth_helper = url_helper.OauthHelper(
consumer_key=consumer_key, token_key=token_key,
token_secret=token_secret, consumer_secret=consumer_secret)
@@ -64,3 +69,5 @@ class WebHookHandler(ReportingHandler):
available_handlers = DictRegistry()
available_handlers.register_item('log', LogHandler)
+available_handlers.register_item('print', PrintHandler)
+available_handlers.register_item('webhook', WebHookHandler)