diff options
author | Soren Hansen <soren@canonical.com> | 2009-08-25 22:23:30 +0200 |
---|---|---|
committer | Soren Hansen <soren@canonical.com> | 2009-08-25 22:23:30 +0200 |
commit | 85f6e6168beb89436ebc20c67d329581f7155f5c (patch) | |
tree | 3cef6e3fb0b9d8eef4bd5cc022c7e94c77bade3d | |
parent | 76d5d79c0ec119cf5e87e71578125081c40c291d (diff) | |
parent | 674eee8a45c8c492afde327208f0c1d1fe3fd2a4 (diff) | |
download | vyos-cloud-init-85f6e6168beb89436ebc20c67d329581f7155f5c.tar.gz vyos-cloud-init-85f6e6168beb89436ebc20c67d329581f7155f5c.zip |
Merge with lp:~soren/ec2-init/decorator
Add @handler decorator for appliance config
-rwxr-xr-x | ec2-run-user-data.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py index 2917b2fe..67ecf219 100755 --- a/ec2-run-user-data.py +++ b/ec2-run-user-data.py @@ -26,6 +26,15 @@ from xml.dom.minidom import parse, parseString import ec2init +content_type_handlers = {} + +def handler(mimetype): + return lambda f: register_handler(mimetype, f) + +def register_handler(mimetype, func): + content_type_handlers[mimetype] = func + return func + def handle_part(part): if part.is_multipart(): for p in part.get_payload(): @@ -45,11 +54,12 @@ def handle_unknown_payload(payload): if payload.startswith('<appliance>'): content_type_handlers['text/x-appliance-config'](payload) - +@handler('text/x-appliance-config') def handle_appliance_config(payload): app = ApplianceConfig(payload) app.handle() +@handler('text/x-ebs-mount-description') def handle_ebs_mount_description(payload): (volume_description, path) = payload.split(':') (identifier_type, identifier) = volume_description.split('=') @@ -63,6 +73,7 @@ def handle_ebs_mount_description(payload): else: return +@handler('text/x-shellscript') def handle_shell_script(payload): (fd, path) = tempfile.mkstemp() fp = os.fdopen(fd, 'a') @@ -77,10 +88,6 @@ def handle_shell_script(payload): os.unlink(path) -content_type_handlers = { 'text/x-shellscript' : handle_shell_script, - 'text/x-ebs-mount-description' : handle_ebs_mount_description, - 'text/x-appliance-config': handle_appliance_config } - class ApplianceConfig(object): def __init__(self, data): self.data = data |