diff options
author | Marc Cluet <marc.cluet@ubuntu.com> | 2011-07-25 13:27:27 +0100 |
---|---|---|
committer | Marc Cluet <marc.cluet@ubuntu.com> | 2011-07-25 13:27:27 +0100 |
commit | 57ea45b2bc86895582de65928c555e6f0430b287 (patch) | |
tree | 6bea9226c35341a9884b9744d1399f7353976613 /cloudinit | |
parent | a3dcbac2528f7c8ecaedeca64c4792f7e3d4ee59 (diff) | |
download | vyos-cloud-init-57ea45b2bc86895582de65928c555e6f0430b287.tar.gz vyos-cloud-init-57ea45b2bc86895582de65928c555e6f0430b287.zip |
Added new feature include-once
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/UserDataHandler.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/cloudinit/UserDataHandler.py b/cloudinit/UserDataHandler.py index 83377dab..4fd6ef28 100644 --- a/cloudinit/UserDataHandler.py +++ b/cloudinit/UserDataHandler.py @@ -25,6 +25,7 @@ import yaml starts_with_mappings={ '#include' : 'text/x-include-url', + '#include-once' : 'text/x-include-once-url', '#!' : 'text/x-shellscript', '#cloud-config' : 'text/cloud-config', '#upstart-job' : 'text/upstart-job', @@ -45,16 +46,34 @@ def decomp_str(str): def do_include(str,parts): import urllib + import os + import base64 # is just a list of urls, one per line # also support '#include <url here>' + includeonce = False for line in str.splitlines(): if line == "#include": continue - if line.startswith("#include"): + if line == "#include-once": + includeonce == True + if line.startswith("#include-once"): + line = line[len("#include-once"):].lstrip() + includeonce = True + elif line.startswith("#include"): line = line[len("#include"):].lstrip() if line.startswith("#"): continue - content = urllib.urlopen(line).read() + if includeonce == True: + uniquestring = base64.encodestring(line).strip('\n') + includeonce_filename = "/var/lib/cloud/instance/.includeonce.%s" % uniquestring + if os.path.isfile(includeonce_filename): continue + includeonce_file = open(includeonce_filename,'w') + includeonce_file.close() + try: + content = urllib.urlopen(line).read() + except Exception as e: + log.debug(traceback.format_exc(e)) process_includes(email.message_from_string(decomp_str(content)),parts) + def explode_cc_archive(archive,parts): for ent in yaml.load(archive): # ent can be one of: |