summaryrefslogtreecommitdiff
path: root/cloudinit/url_helper.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-10-19 14:06:21 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-10-19 14:06:21 -0700
commit7c9bbbc9b49425e3ba8e0517908477c58ea51d4b (patch)
tree1c21d521b299f5ac29a5f83855cb976eba44ed0e /cloudinit/url_helper.py
parent914c6e86f1689ae186a0db836e7f0304d72c38b4 (diff)
downloadvyos-cloud-init-7c9bbbc9b49425e3ba8e0517908477c58ea51d4b.tar.gz
vyos-cloud-init-7c9bbbc9b49425e3ba8e0517908477c58ea51d4b.zip
Remove the need for boto just for fetching the
userdata and metadata. Add in this crawling functionality to the ec2_utils module that will fully crawl (not lazily) the ec2 metadata and parse it in the same manner as boto. 1. Make the ec2 datasource + cloudstack now call into these. 2. Fix phone_home due to urllib3 change (TBD)
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r--cloudinit/url_helper.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index e3f63021..2c9d5eef 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -22,11 +22,10 @@
from contextlib import closing
-import errno
-import socket
import time
import urllib
+from urllib3 import exceptions
from urllib3 import connectionpool
from urllib3 import util
@@ -91,7 +90,10 @@ def readurl(url, data=None, timeout=None, retries=0,
'url': p_url.request_uri,
}
if data is not None:
- open_args['body'] = urllib.urlencode(data)
+ if isinstance(data, (str, basestring)):
+ open_args['body'] = data
+ else:
+ open_args['body'] = urllib.urlencode(data)
open_args['method'] = 'POST'
if not headers:
headers = {
@@ -112,7 +114,7 @@ def wait_for_url(urls, max_wait=None, timeout=None,
max_wait: roughly the maximum time to wait before giving up
The max time is *actually* len(urls)*timeout as each url will
be tried once and given the timeout provided.
- timeout: the timeout provided to urllib2.urlopen
+ timeout: the timeout provided to urlopen
status_cb: call method with string message when a url is not available
headers_cb: call method with single argument of url to get headers
for request.
@@ -174,12 +176,8 @@ def wait_for_url(urls, max_wait=None, timeout=None,
e = ValueError(reason)
else:
return url
- except urllib2.HTTPError as e:
+ except exceptions.HTTPError as e:
reason = "http error [%s]" % e.code
- except urllib2.URLError as e:
- reason = "url error [%s]" % e.reason
- except socket.timeout as e:
- reason = "socket timeout [%s]" % e
except Exception as e:
reason = "unexpected error [%s]" % e