diff options
author | Scott Moser <smoser@brickies.net> | 2012-10-23 18:58:32 +0200 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2012-10-23 18:58:32 +0200 |
commit | 71b4108d029fff61ff8183ffbd77917569bea2cd (patch) | |
tree | 6564cd3f5faa26fb1c843b14d27ca6eaa23164f0 /cloudinit/sources/DataSourceAltCloud.py | |
parent | cb5893c3e3f635de4fef86f0a19be0ada0054930 (diff) | |
parent | e8a10a41d22876d555084def823817337d9c2a80 (diff) | |
download | vyos-cloud-init-71b4108d029fff61ff8183ffbd77917569bea2cd.tar.gz vyos-cloud-init-71b4108d029fff61ff8183ffbd77917569bea2cd.zip |
use only util methods for reading/loading/appending/peeking
Use only util methods for reading/loading/appending/peeking
at files since it is likely soon that we will add a new
way of adjusting the root of files read, also it is useful
for debugging to track what is being read/written in a central
fashion.
Diffstat (limited to 'cloudinit/sources/DataSourceAltCloud.py')
-rw-r--r-- | cloudinit/sources/DataSourceAltCloud.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py index 69c376a5..d7e1204f 100644 --- a/cloudinit/sources/DataSourceAltCloud.py +++ b/cloudinit/sources/DataSourceAltCloud.py @@ -73,13 +73,11 @@ def read_user_data_callback(mount_dir): # First try deltacloud_user_data_file. On failure try user_data_file. try: - with open(deltacloud_user_data_file, 'r') as user_data_f: - user_data = user_data_f.read().strip() - except: + user_data = util.load_file(deltacloud_user_data_file).strip() + except IOError: try: - with open(user_data_file, 'r') as user_data_f: - user_data = user_data_f.read().strip() - except: + user_data = util.load_file(user_data_file).strip() + except IOError: util.logexc(LOG, ('Failed accessing user data file.')) return None @@ -157,11 +155,10 @@ class DataSourceAltCloud(sources.DataSource): if os.path.exists(CLOUD_INFO_FILE): try: - cloud_info = open(CLOUD_INFO_FILE) - cloud_type = cloud_info.read().strip().upper() - cloud_info.close() - except: - util.logexc(LOG, 'Unable to access cloud info file.') + cloud_type = util.load_file(CLOUD_INFO_FILE).strip().upper() + except IOError: + util.logexc(LOG, 'Unable to access cloud info file at %s.', + CLOUD_INFO_FILE) return False else: cloud_type = self.get_cloud_type() |