← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~harlowja/cloud-init/same-register-content into lp:cloud-init

 

Joshua Harlow has proposed merging lp:~harlowja/cloud-init/same-register-content into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/same-register-content/+merge/176617

Unify default vs custom handler registering.
-- 
https://code.launchpad.net/~harlowja/cloud-init/same-register-content/+merge/176617
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/same-register-content into lp:cloud-init.
=== modified file 'cloudinit/helpers.py'
--- cloudinit/helpers.py	2013-07-21 17:45:29 +0000
+++ cloudinit/helpers.py	2013-07-24 07:52:25 +0000
@@ -292,11 +292,16 @@
     def is_registered(self, content_type):
         return content_type in self.registered
 
-    def register(self, mod, initialized=False):
+    def register(self, mod, initialized=False, overwrite=True):
         types = set()
         for t in mod.list_types():
+            if overwrite:
+                types.add(t)
+            else:
+                if not self.is_registered(t):
+                    types.add(t)
+        for t in types:
             self.registered[t] = mod
-            types.add(t)
         if initialized and mod not in self.initialized:
             self.initialized.append(mod)
         return types

=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py	2013-07-21 18:04:55 +0000
+++ cloudinit/stages.py	2013-07-24 07:52:25 +0000
@@ -375,7 +375,9 @@
                     mod = importer.import_module(mod_locs[0])
                     mod = handlers.fixup_handler(mod)
                     types = c_handlers.register(mod)
-                    LOG.debug("Added handler for %s from %s", types, fname)
+                    if types:
+                        LOG.debug("Added custom handler for %s from %s",
+                                  types, fname)
                 except Exception:
                     util.logexc(LOG, "Failed to register handler from %s",
                                 fname)
@@ -386,10 +388,10 @@
         # Register any other handlers that come from the default set. This
         # is done after the cloud-dir handlers so that the cdir modules can
         # take over the default user-data handler content-types.
-        def_handlers = self._default_userdata_handlers()
-        applied_def_handlers = c_handlers.register_defaults(def_handlers)
-        if applied_def_handlers:
-            LOG.debug("Registered default handlers: %s", applied_def_handlers)
+        for mod in self._default_userdata_handlers():
+            types = c_handlers.register(mod, overwrite=False)
+            if types:
+                LOG.debug("Added default handler for %s from %s", types, mod)
 
         # Form our cloud interface
         data = self.cloudify()


Follow ups