From 9d4a9dc17696d0465ae4f8b56db9c0948fcac28c Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 2 Aug 2011 17:09:43 -0400 Subject: 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 --- cloudinit/UserDataHandler.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'cloudinit/UserDataHandler.py') 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 -- cgit v1.2.3