summaryrefslogtreecommitdiff
path: root/cloudinit/reporting
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-08-06 18:19:46 -0500
committerScott Moser <smoser@ubuntu.com>2015-08-06 18:19:46 -0500
commit6fdb23b6cbc8de14ebcffc17e9e49342b7bf193d (patch)
tree09968b96312b43aedbc4a5c44f089eaeaa0e872e /cloudinit/reporting
parent963647d5197523fabe319df5f0502ec6dce64bd6 (diff)
downloadvyos-cloud-init-6fdb23b6cbc8de14ebcffc17e9e49342b7bf193d.tar.gz
vyos-cloud-init-6fdb23b6cbc8de14ebcffc17e9e49342b7bf193d.zip
sync with cloudinit 2.0 for registry and reporting
Diffstat (limited to 'cloudinit/reporting')
-rw-r--r--cloudinit/reporting/__init__.py29
-rw-r--r--cloudinit/reporting/handlers.py15
2 files changed, 39 insertions, 5 deletions
diff --git a/cloudinit/reporting/__init__.py b/cloudinit/reporting/__init__.py
index 2b92ab58..d0bc14e3 100644
--- a/cloudinit/reporting/__init__.py
+++ b/cloudinit/reporting/__init__.py
@@ -20,8 +20,6 @@ DEFAULT_CONFIG = {
'logging': {'type': 'log'},
}
-instantiated_handler_registry = DictRegistry()
-
class _nameset(set):
def __getattr__(self, name):
@@ -46,6 +44,11 @@ class ReportingEvent(object):
return '{0}: {1}: {2}'.format(
self.event_type, self.name, self.description)
+ def as_dict(self):
+ """The event represented as a dictionary."""
+ return {'name': self.name, 'description': self.description,
+ 'event_type': self.event_type}
+
class FinishReportingEvent(ReportingEvent):
@@ -60,9 +63,26 @@ class FinishReportingEvent(ReportingEvent):
return '{0}: {1}: {2}: {3}'.format(
self.event_type, self.name, self.result, self.description)
+ def as_dict(self):
+ """The event represented as json friendly."""
+ data = super(FinishReportingEvent, self).as_dict()
+ data['result'] = self.result
+ return data
+
-def add_configuration(config):
+def update_configuration(config):
+ """Update the instanciated_handler_registry.
+
+ :param config:
+ The dictionary containing changes to apply. If a key is given
+ with a False-ish value, the registered handler matching that name
+ will be unregistered.
+ """
for handler_name, handler_config in config.items():
+ if not handler_config:
+ instantiated_handler_registry.unregister_item(
+ handler_name, force=True)
+ continue
handler_config = handler_config.copy()
cls = available_handlers.registered_items[handler_config.pop('type')]
instance = cls(**handler_config)
@@ -214,4 +234,5 @@ class ReportEventStack(object):
report_finish_event(self.fullname, msg, result)
-add_configuration(DEFAULT_CONFIG)
+instantiated_handler_registry = DictRegistry()
+update_configuration(DEFAULT_CONFIG)
diff --git a/cloudinit/reporting/handlers.py b/cloudinit/reporting/handlers.py
index be323f53..86cbe3c3 100644
--- a/cloudinit/reporting/handlers.py
+++ b/cloudinit/reporting/handlers.py
@@ -1,14 +1,27 @@
+# vi: ts=4 expandtab
+
import abc
import logging
+import oauthlib.oauth1 as oauth1
+
+import six
from cloudinit.registry import DictRegistry
+from cloudinit import url_helper
+from cloudinit import util
+@six.add_metaclass(abc.ABCMeta)
class ReportingHandler(object):
+ """Base class for report handlers.
+
+ Implement :meth:`~publish_event` for controlling what
+ the handler does with an event.
+ """
@abc.abstractmethod
def publish_event(self, event):
- raise NotImplementedError
+ """Publish an event to the ``INFO`` log level."""
class LogHandler(ReportingHandler):