diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-07-26 13:54:56 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-07-26 13:54:56 -0400 |
commit | cf65c6c8e0da58698139223888f23adf7093d12f (patch) | |
tree | 8ea230e3727ba81ef065f6614327428370abfc60 /cloudinit/UserDataHandler.py | |
parent | 155e519a63703183823ef9368e2fdb3a6b7b0c0a (diff) | |
download | vyos-cloud-init-cf65c6c8e0da58698139223888f23adf7093d12f.tar.gz vyos-cloud-init-cf65c6c8e0da58698139223888f23adf7093d12f.zip |
include-once: fixups found in testing
at this point, the following user-data file in
/var/lib/cloud/seed/nocloud-net/user-data will do what you would expect:
$ cat > /var/lib/cloud/seed/nocloud-net/user-data <<EOF
#include-once
http://169.254.169.254/2011-01-01/user-data
EOF
$ python -c \
'import boto.utils, pprint; pprint.pprint(boto.utils.get_instance_metadata())' |
sudo tee /var/lib/cloud/seed/nocloud-net/meta-data
Then,
$ sudo sh -c 'for i in /var/lib/cloud/*; do [ ${i##*/} = "seed" ] &&
continue; rm -Rf "$i"; done'
$ sudo reboot
You will then find a file in /var/lib/cloud/instance/data/urlcache/
that has the contents of user-data from the metadata service.
It will not be downloaded again as long as that file is present.
Diffstat (limited to 'cloudinit/UserDataHandler.py')
-rw-r--r-- | cloudinit/UserDataHandler.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/cloudinit/UserDataHandler.py b/cloudinit/UserDataHandler.py index 4ac0e2cd..fa8ce716 100644 --- a/cloudinit/UserDataHandler.py +++ b/cloudinit/UserDataHandler.py @@ -22,7 +22,8 @@ from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import encoders import yaml -from cloudinit import util, get_ipath_cur +import cloudinit +import cloudinit.util as util starts_with_mappings={ '#include' : 'text/x-include-url', @@ -55,7 +56,8 @@ def do_include(str,parts): for line in str.splitlines(): if line == "#include": continue if line == "#include-once": - includeonce == True + includeonce = True + continue if line.startswith("#include-once"): line = line[len("#include-once"):].lstrip() includeonce = True @@ -65,7 +67,7 @@ def do_include(str,parts): # urls cannot not have leading or trailing white space uniquestring = base64.encodestring(line).strip() - includeonce_filename = "%/urlcache/%s" % (get_ipath_cur("data"), uniquestring) + includeonce_filename = "%s/urlcache/%s" % (cloudinit.get_ipath_cur("data"), uniquestring) try: if includeonce and os.path.isfile(includeonce_filename): with open(includeonce_filename, "r") as fp: @@ -75,7 +77,7 @@ def do_include(str,parts): if includeonce: util.write_file(includeonce_filename, content, mode=0600) except Exception as e: - log.debug(traceback.format_exc(e)) + raise process_includes(email.message_from_string(decomp_str(content)),parts) @@ -138,6 +140,10 @@ def process_includes(msg,parts): do_include(payload,parts) continue + if ctype == 'text/x-include-once-url': + do_include(payload,parts) + continue + if ctype == "text/cloud-config-archive": explode_cc_archive(payload,parts) continue |