summaryrefslogtreecommitdiff
path: root/cloudinit/url_helper.py
diff options
context:
space:
mode:
authorharlowja <harlowja@virtualbox.rhel>2013-02-23 21:23:24 -0800
committerharlowja <harlowja@virtualbox.rhel>2013-02-23 21:23:24 -0800
commiteacfc7ffbec3e6a0348ed484da895e2d2fc5ba10 (patch)
treee63c8f74a34c6250764136865c542af6ba78d989 /cloudinit/url_helper.py
parent46a7a39775ed8f745ec8b63a9563f3ae6337d845 (diff)
downloadvyos-cloud-init-eacfc7ffbec3e6a0348ed484da895e2d2fc5ba10.tar.gz
vyos-cloud-init-eacfc7ffbec3e6a0348ed484da895e2d2fc5ba10.zip
Get tests working and further adjustments.
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r--cloudinit/url_helper.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index 0839e63b..300e70c2 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -70,9 +70,14 @@ class UrlResponse(object):
def url(self):
return self._response.url
- @property
- def ok(self):
- return self._response.ok
+ def ok(self, redirects_ok=False):
+ upper = 300
+ if redirects_ok:
+ upper = 400
+ if self.code >= 200 and self.code < upper:
+ return True
+ else:
+ return False
@property
def headers(self):
@@ -158,11 +163,8 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1,
r = requests.request(**req_args)
if check_status:
r.raise_for_status()
- contents = r.content
- status = r.status_code
- headers = r.headers
LOG.debug("Read from %s (%s, %sb) after %s attempts", url,
- status, len(contents), (i + 1))
+ r.status_code, len(r.content), (i + 1))
# Doesn't seem like we can make it use a different
# subclass for responses, so add our own backward-compat
# attrs
@@ -256,8 +258,9 @@ def wait_for_url(urls, max_wait=None, timeout=None,
time_taken = int(time.time() - start_time)
status_msg = "Calling '%s' failed [%s/%ss]: %s" % (url,
- time_taken,
- max_wait, reason)
+ time_taken,
+ max_wait,
+ reason)
status_cb(status_msg)
if exception_cb:
exception_cb(msg=status_msg, exception=e)