summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-16 09:33:27 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-16 09:33:27 -0700
commit5395081ce719471dc1101feaf310417457ae5261 (patch)
tree10a35910930d56bccd34d8515c84bc7f09d6de4d /cloudinit
parentc23ade677e59e67d4d84ee111e337a99d11271e2 (diff)
downloadvyos-cloud-init-5395081ce719471dc1101feaf310417457ae5261.tar.gz
vyos-cloud-init-5395081ce719471dc1101feaf310417457ae5261.zip
1. Change to fixup handler instead of fixup module
2. Add logging of unknown content types + seperate payload logging detail message into a separate function.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/user_data.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py
index 866bf6de..f64a1707 100644
--- a/cloudinit/user_data.py
+++ b/cloudinit/user_data.py
@@ -250,7 +250,7 @@ class PartHandler(object):
raise NotImplementedError()
-def fixup_module(mod, def_freq=PER_INSTANCE):
+def fixup_handler(mod, def_freq=PER_INSTANCE):
if not hasattr(mod, "handler_version"):
setattr(mod, "handler_version", 1)
if not hasattr(mod, 'list_types'):
@@ -307,7 +307,7 @@ def walker_handle_handler(pdata, _ctype, _filename, payload):
util.write_file(modfname, payload, 0600)
handlers = pdata['handlers']
try:
- mod = fixup_module(importer.import_module(modname))
+ mod = fixup_handler(importer.import_module(modname))
handlers.register(mod)
call_begin(mod, pdata['data'], frequency)
pdata['handlercount'] = curcount + 1
@@ -315,23 +315,35 @@ def walker_handle_handler(pdata, _ctype, _filename, payload):
util.logexc(LOG, "Failed at registered python file: %s", modfname)
+def extract_first_or_bytes(blob, size):
+ # Extract the first line upto X bytes or X bytes from more than the
+ # first line if the first line does not contain enough bytes
+ first_line = blob.split("\n", 1)[0]
+ if len(first_line) >= size:
+ start = first_line[:size]
+ else:
+ start = blob[0:size]
+ return start
+
+
def walker_callback(pdata, ctype, filename, payload):
if ctype in PART_CONTENT_TYPES:
walker_handle_handler(pdata, ctype, filename, payload)
return
handlers = pdata['handlers']
if ctype not in handlers:
+ # Extract the first line or 24 bytes for displaying in the log
+ start = extract_first_or_bytes(payload, 24)
+ details = "'%s...'" % (start.encode("string-escape"))
if ctype == NOT_MULTIPART_TYPE:
- # Extract the first line or 24 bytes for displaying in the log
- start = payload.split("\n", 1)[0][:24]
- if start < payload:
- details = "starting '%s...'" % start.encode("string-escape")
- else:
- details = repr(payload)
- LOG.warning("Unhandled non-multipart userdata: %s", details)
- return
- run_part(handlers[ctype], pdata['data'], ctype, filename,
- payload, pdata['frequency'])
+ LOG.warning("Unhandled non-multipart (%s) userdata: %s",
+ ctype, details)
+ else:
+ LOG.warning("Unhandled unknown content-type (%s) userdata: %s",
+ ctype, details)
+ else:
+ run_part(handlers[ctype], pdata['data'], ctype, filename,
+ payload, pdata['frequency'])
# Callback is a function that will be called with