diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-11-07 10:23:32 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-11-07 10:23:32 -0500 |
commit | 8ada8c1f625be5365a5116c458476c7deeae8818 (patch) | |
tree | a2f3b4c968a3fd4cbc76ad59ce70563485ea8171 /cloudinit/sources/DataSourceConfigDrive.py | |
parent | 0da58fe113726c7654bca54b365d95044b44ef87 (diff) | |
parent | ce5a554672f4ffbc383af08a35d22a1dd89ce41f (diff) | |
download | vyos-cloud-init-8ada8c1f625be5365a5116c458476c7deeae8818.tar.gz vyos-cloud-init-8ada8c1f625be5365a5116c458476c7deeae8818.zip |
merge from trunk
Diffstat (limited to 'cloudinit/sources/DataSourceConfigDrive.py')
-rw-r--r-- | cloudinit/sources/DataSourceConfigDrive.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py index 4af2e5ae..9729cfb9 100644 --- a/cloudinit/sources/DataSourceConfigDrive.py +++ b/cloudinit/sources/DataSourceConfigDrive.py @@ -307,19 +307,19 @@ def read_config_drive_dir_v2(source_dir, version="2012-08-10"): found = False if os.path.isfile(fpath): try: - with open(fpath) as fp: - data = fp.read() - except Exception as exc: - raise BrokenConfigDriveDir("failed to read: %s" % fpath) + data = util.load_file(fpath) + except IOError: + raise BrokenConfigDriveDir("Failed to read: %s" % fpath) found = True elif required: - raise NonConfigDriveDir("missing mandatory %s" % fpath) + raise NonConfigDriveDir("Missing mandatory path: %s" % fpath) if found and process: try: data = process(data) except Exception as exc: - raise BrokenConfigDriveDir("failed to process: %s" % fpath) + raise BrokenConfigDriveDir(("Failed to process " + "path: %s") % fpath) if found: results[name] = data @@ -335,8 +335,7 @@ def read_config_drive_dir_v2(source_dir, version="2012-08-10"): # do not use os.path.join here, as content_path starts with / cpath = os.path.sep.join((source_dir, "openstack", "./%s" % item['content_path'])) - with open(cpath) as fp: - return(fp.read()) + return util.load_file(cpath) files = {} try: @@ -350,7 +349,7 @@ def read_config_drive_dir_v2(source_dir, version="2012-08-10"): if item: results['network_config'] = read_content_path(item) except Exception as exc: - raise BrokenConfigDriveDir("failed to read file %s: %s" % (item, exc)) + raise BrokenConfigDriveDir("Failed to read file %s: %s" % (item, exc)) # to openstack, user can specify meta ('nova boot --meta=key=value') and # those will appear under metadata['meta']. @@ -465,8 +464,7 @@ def get_previous_iid(paths): # hasn't declared itself found. fname = os.path.join(paths.get_cpath('data'), 'instance-id') try: - with open(fname) as fp: - return fp.read() + return util.load_file(fname) except IOError: return None |