summaryrefslogtreecommitdiff
path: root/cloudinit/UserDataHandler.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-08-02 17:09:43 -0400
committerScott Moser <smoser@ubuntu.com>2011-08-02 17:09:43 -0400
commit9d4a9dc17696d0465ae4f8b56db9c0948fcac28c (patch)
tree77b6c6c2d98016524f4191786dd6e89f2e28090b /cloudinit/UserDataHandler.py
parentfb0150dd71bf54bd46e30efab62dbb2f6eca2ba2 (diff)
downloadvyos-cloud-init-9d4a9dc17696d0465ae4f8b56db9c0948fcac28c.tar.gz
vyos-cloud-init-9d4a9dc17696d0465ae4f8b56db9c0948fcac28c.zip
This fixes LP: #819507, to make consume_userdata run 'always'
consume_userdata should really run always, rather than once per instance. The documentation says that boothooks were on their own for per-instance but since this routine was only being called once, they would only get called once. This modifies the behavior to be: user_script: per_always cloud_config : per_always upstart_job : per_instance cloud_boothook: per_always In order to not break part handlers that are existing, and expect to only be called once per instance, this adds a 'handler_version' item in a handler that can indicate the version (currently 1 or 2). If it is 2, then the hander will be passed the frequency (per-instance or per-always) that this is being run. That way the handler can differenciate between them. This also makes 'bootcmd' run every boot. That should be changable in cloud-config though, so users who dont like the behavior can modify it. LP: #819507
Diffstat (limited to 'cloudinit/UserDataHandler.py')
-rw-r--r--cloudinit/UserDataHandler.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/cloudinit/UserDataHandler.py b/cloudinit/UserDataHandler.py
index 9670c0cb..afd5dd99 100644
--- a/cloudinit/UserDataHandler.py
+++ b/cloudinit/UserDataHandler.py
@@ -190,11 +190,10 @@ def preprocess_userdata(data):
process_includes(email.message_from_string(decomp_str(data)),parts)
return(parts2mime(parts))
-# callbacks is a dictionary with:
-# { 'content-type': handler(data,content_type,filename,payload) }
-def walk_userdata(str, callbacks, data = None):
+# callback is a function that will be called with (data, content_type, filename, payload)
+def walk_userdata(istr, callback, data = None):
partnum = 0
- for part in email.message_from_string(str).walk():
+ for part in email.message_from_string(istr).walk():
# multipart/* are just containers
if part.get_content_maintype() == 'multipart':
continue
@@ -207,8 +206,7 @@ def walk_userdata(str, callbacks, data = None):
if not filename:
filename = 'part-%03d' % partnum
- if callbacks.has_key(ctype):
- callbacks[ctype](data,ctype,filename,part.get_payload())
+ callback(data, ctype, filename, part.get_payload())
partnum = partnum+1