summaryrefslogtreecommitdiff
path: root/cloudinit/user_data.py
diff options
context:
space:
mode:
authorharlowja <harlowja@virtualbox.rhel>2012-06-17 18:23:24 -0700
committerharlowja <harlowja@virtualbox.rhel>2012-06-17 18:23:24 -0700
commitb6f158b8a55f37d9d2854ff0e566298b85cc0c89 (patch)
tree706d434f19edf151d51072a32c41f3baa26093cc /cloudinit/user_data.py
parentbc5322d2bc81b2421ae8dfe1bb02fa2fd61fed51 (diff)
downloadvyos-cloud-init-b6f158b8a55f37d9d2854ff0e566298b85cc0c89.tar.gz
vyos-cloud-init-b6f158b8a55f37d9d2854ff0e566298b85cc0c89.zip
1. Add a url response class that urlreading now returns (instead of a tuple).
a. This allows for more properties to be added as needed in the future, instead of being very restrictive. 2. Fix up all uses of the url reading to now use this new response object. 3. Also fixup user data including, such that if no response actual occurs the url content is not further processed.
Diffstat (limited to 'cloudinit/user_data.py')
-rw-r--r--cloudinit/user_data.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py
index 663f7cda..bf34943d 100644
--- a/cloudinit/user_data.py
+++ b/cloudinit/user_data.py
@@ -121,19 +121,25 @@ class UserDataProcessor(object):
continue
include_once_fn = None
+ content = None
if include_once_on:
include_once_fn = self._get_include_once_filename(include_url)
if include_once_on and os.path.isfile(include_once_fn):
content = util.load_file(include_once_fn)
else:
- (content, st) = url_helper.readurl(include_url)
- if include_once_on and url_helper.ok_http_code(st):
- util.write_file(include_once_fn, content, mode=0600)
- if not url_helper.ok_http_code(st):
- content = ''
-
- new_msg = convert_string(content)
- self._process_msg(new_msg, append_msg)
+ resp = url_helper.readurl(include_url)
+ if include_once_on and resp.ok():
+ util.write_file(include_once_fn, str(resp), mode=0600)
+ if resp.ok():
+ content = str(resp)
+ else:
+ LOG.warn(("Fetching from %s resulted in"
+ " a invalid http code of %s"),
+ include_url, resp.code)
+
+ if content is not None:
+ new_msg = convert_string(content)
+ self._process_msg(new_msg, append_msg)
def _explode_archive(self, archive, append_msg):
entries = util.load_yaml(archive, default=[], allowed=[list, set])