summaryrefslogtreecommitdiff
path: root/ec2-run-user-data.py
diff options
context:
space:
mode:
authorSoren Hansen <soren@canonical.com>2009-08-25 17:38:05 +0200
committerSoren Hansen <soren@canonical.com>2009-08-25 17:38:05 +0200
commit674eee8a45c8c492afde327208f0c1d1fe3fd2a4 (patch)
treeb47eb9c05274a0b2af8dd7aea87717513552a7fc /ec2-run-user-data.py
parent41d05bf5c7980588cd289d95f9beb4a0ac1462d4 (diff)
downloadvyos-cloud-init-674eee8a45c8c492afde327208f0c1d1fe3fd2a4.tar.gz
vyos-cloud-init-674eee8a45c8c492afde327208f0c1d1fe3fd2a4.zip
Replace static content_type_handler dictionary with a decorator.
LP: #376740
Diffstat (limited to 'ec2-run-user-data.py')
-rwxr-xr-xec2-run-user-data.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py
index 51e0d68d..5af04249 100755
--- a/ec2-run-user-data.py
+++ b/ec2-run-user-data.py
@@ -25,8 +25,14 @@ import tempfile
import ec2init
-content_type_handlers = { 'text/x-shellscript' : handle_shell_script,
- 'text/x-ebs-mount-description' : handle_ebs_mount_description }
+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 main():
ec2 = ec2init.EC2Init()
@@ -52,6 +58,7 @@ def handle_unknown_payload(payload):
if payload.startswith('#!'):
content_type_handlers['text/x-shellscript'](payload)
+@handler('text/x-ebs-mount-description')
def handle_ebs_mount_description(payload):
(volume_description, path) = payload.split(':')
(identifier_type, identifier) = volume_description.split('=')
@@ -65,6 +72,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')