summaryrefslogtreecommitdiff
path: root/cloudinit/handlers
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2013-07-20 07:01:33 -0700
committerJoshua Harlow <harlowja@gmail.com>2013-07-20 07:01:33 -0700
commit1f73904df31feb22ad8545a3a336ba2e92e367bb (patch)
tree8a477a395da6829f4b728c20066ee5262a30b547 /cloudinit/handlers
parent03d93b4fe94d0cd4de8fb661748207ea251fbb2a (diff)
downloadcloud-init-git-1f73904df31feb22ad8545a3a336ba2e92e367bb.tar.gz
Fix constant move.
Diffstat (limited to 'cloudinit/handlers')
-rw-r--r--cloudinit/handlers/cloud_config.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/cloudinit/handlers/cloud_config.py b/cloudinit/handlers/cloud_config.py
index 3a4f2150..99dc71d0 100644
--- a/cloudinit/handlers/cloud_config.py
+++ b/cloudinit/handlers/cloud_config.py
@@ -52,6 +52,12 @@ MERGE_HEADER = 'Merge-Type'
# This gets loaded into yaml with final result {'a': 22}
DEF_MERGERS = mergers.string_extract_mergers('dict(replace)+list()+str()')
+# The file header -> content types this module will handle.
+CC_TYPES = {
+ '#json-patch': handlers.type_from_starts_with("#json-patch"),
+ '#cloud-config': handlers.type_from_starts_with("#cloud-config"),
+}
+
class CloudConfigPartHandler(handlers.Handler):
def __init__(self, paths, **_kwargs):
@@ -61,23 +67,20 @@ class CloudConfigPartHandler(handlers.Handler):
self.file_names = []
def list_types(self):
- ctypes_handled = [
- handlers.type_from_starts_with("#cloud-config"),
- handlers.type_from_starts_with("#json-patch"),
- ]
- return ctypes_handled
+ return list(CC_TYPES.values())
def _write_cloud_config(self):
- if not self.cloud_fn or not len(self.file_names):
+ if not self.cloud_fn:
return
# Capture which files we merged from...
file_lines = []
- file_lines.append("# from %s files" % (len(self.file_names)))
- for fn in self.file_names:
- if not fn:
- fn = '?'
- file_lines.append("# %s" % (fn))
- file_lines.append("")
+ if self.file_names:
+ file_lines.append("# from %s files" % (len(self.file_names)))
+ for fn in self.file_names:
+ if not fn:
+ fn = '?'
+ file_lines.append("# %s" % (fn))
+ file_lines.append("")
if self.cloud_buf is not None:
# Something was actually gathered....
lines = [
@@ -138,7 +141,7 @@ class CloudConfigPartHandler(handlers.Handler):
# First time through, merge with an empty dict...
if self.cloud_buf is None or not self.file_names:
self.cloud_buf = {}
- if ctype == JSON_PATCH_CTYPE:
+ if ctype == CC_TYPES['#json-patch']:
self._merge_patch(payload)
else:
self._merge_part(payload, headers)