summaryrefslogtreecommitdiff
path: root/cloudinit/handlers/cloud_config.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2012-11-20 20:02:48 -0800
committerJoshua Harlow <harlowja@gmail.com>2012-11-20 20:02:48 -0800
commit8bc85abd97e06d964bbd26208eb732e80eb87c10 (patch)
tree6cbff248cbe85d3ef26da32bc185f34edd8f5c4d /cloudinit/handlers/cloud_config.py
parentd324a2cb0b10a4cd1b1b05dd23d0040ab3e9621c (diff)
downloadvyos-cloud-init-8bc85abd97e06d964bbd26208eb732e80eb87c10.tar.gz
vyos-cloud-init-8bc85abd97e06d964bbd26208eb732e80eb87c10.zip
Start allowing different merging types to be applied
After user data handling splits apart all the different content types into there various mime messages it is nice to be able to have each message specify how it should be merged (mainly for cloud-config or cloud-archive) into the single cloud config that is eventually used. This starts to add a plugable merging framework and the needed components to activate said headers and merging.
Diffstat (limited to 'cloudinit/handlers/cloud_config.py')
-rw-r--r--cloudinit/handlers/cloud_config.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/cloudinit/handlers/cloud_config.py b/cloudinit/handlers/cloud_config.py
index f6d95244..86027187 100644
--- a/cloudinit/handlers/cloud_config.py
+++ b/cloudinit/handlers/cloud_config.py
@@ -22,6 +22,7 @@
from cloudinit import handlers
from cloudinit import log as logging
+from cloudinit import mergers
from cloudinit import util
from cloudinit.settings import (PER_ALWAYS)
@@ -31,8 +32,8 @@ LOG = logging.getLogger(__name__)
class CloudConfigPartHandler(handlers.Handler):
def __init__(self, paths, **_kwargs):
- handlers.Handler.__init__(self, PER_ALWAYS)
- self.cloud_buf = []
+ handlers.Handler.__init__(self, PER_ALWAYS, version=3)
+ self.cloud_buf = {}
self.cloud_fn = paths.get_ipath("cloud_config")
def list_types(self):
@@ -43,20 +44,17 @@ class CloudConfigPartHandler(handlers.Handler):
def _write_cloud_config(self, buf):
if not self.cloud_fn:
return
- lines = [str(b) for b in buf]
- payload = "\n".join(lines)
+ payload = util.yaml_dumps(self.cloud_buf)
util.write_file(self.cloud_fn, payload, 0600)
- def _handle_part(self, _data, ctype, filename, payload, _frequency):
+ def handle_part(self, _data, ctype, filename, payload, _frequency, headers):
if ctype == handlers.CONTENT_START:
- self.cloud_buf = []
+ self.cloud_buf = {}
return
if ctype == handlers.CONTENT_END:
self._write_cloud_config(self.cloud_buf)
- self.cloud_buf = []
+ self.cloud_buf = {}
return
-
- filename = util.clean_filename(filename)
- if not filename:
- filename = '??'
- self.cloud_buf.extend(["#%s" % (filename), str(payload)])
+ merge_how = headers.get("Merge-Type", 'list+dict+str')
+ merger = mergers.construct(merge_how)
+ self.cloud_buf = merger.merge(self.cloud_buf, util.load_yaml(payload))