summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-09-08 09:36:10 -0400
committerScott Moser <smoser@ubuntu.com>2013-09-08 09:36:10 -0400
commit0f84bfe5e0f06872a866432178a5f19d04195d30 (patch)
treea1af0442da20d09b66d0e37fa36698011033958f
parent50e90192bffb3f0ce437ec9abcca89cc56649dff (diff)
parentd04b027003faf526028740d34421693396fcabb1 (diff)
downloadvyos-cloud-init-0f84bfe5e0f06872a866432178a5f19d04195d30.tar.gz
vyos-cloud-init-0f84bfe5e0f06872a866432178a5f19d04195d30.zip
Use the same method for registering custom or default handlers.
Instead of having a register default handler and a register custom handler, just use the same function to do both but provide a parameter to affect how overwritting of previously existing content-types (which default handlers use to not overwrite custom ones).
-rw-r--r--cloudinit/helpers.py18
-rw-r--r--cloudinit/stages.py12
2 files changed, 14 insertions, 16 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index 1c46efde..e5eac6a7 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -292,11 +292,16 @@ class ContentHandlers(object):
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
@@ -310,15 +315,6 @@ class ContentHandlers(object):
def iteritems(self):
return self.registered.iteritems()
- def register_defaults(self, defs):
- registered = set()
- for mod in defs:
- for t in mod.list_types():
- if not self.is_registered(t):
- self.registered[t] = mod
- registered.add(t)
- return registered
-
class Paths(object):
def __init__(self, path_cfgs, ds=None):
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 3e49e8c5..07c55802 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -375,7 +375,9 @@ class Init(object):
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 @@ class Init(object):
# 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()