From b6f158b8a55f37d9d2854ff0e566298b85cc0c89 Mon Sep 17 00:00:00 2001 From: harlowja Date: Sun, 17 Jun 2012 18:23:24 -0700 Subject: 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. --- cloudinit/user_data.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'cloudinit/user_data.py') 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]) -- cgit v1.2.3