From c41bf2bb65a57b50e3291e61a2e53c97a291f0dd Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 8 Dec 2016 08:37:14 -0500 Subject: [PATCH] [RM-18169] util: create http get helpers to help translate chacra urls into repos Signed-off-by: Alfredo Deza --- ceph_deploy/util/net.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ceph_deploy/util/net.py b/ceph_deploy/util/net.py index 103b324..f23c665 100644 --- a/ceph_deploy/util/net.py +++ b/ceph_deploy/util/net.py @@ -1,3 +1,9 @@ +try: + from urllib.request import urlopen + from urllib.error import HTTPError +except ImportError: + from urllib2 import urlopen, HTTPError + from ceph_deploy import exc import logging import re @@ -362,3 +368,23 @@ def cidr_to_ipv4_netmask(cidr_bits): netmask += '{0:d}'.format(256 - (2 ** (8 - cidr_bits))) cidr_bits = 0 return netmask + + +def get_request(url): + try: + return urlopen(url) + except HTTPError as err: + LOG.error('repository might not be available yet') + raise RuntimeError('%s, failed to fetch %s' % (err, url)) + + +def get_chacra_repo(shaman_url): + """ + From a Shaman URL, get the chacra url for a repository, read the + contents that point to the repo and return it as a string. + """ + shaman_response = get_request(shaman_url) + chacra_url = shaman_response.geturl() + chacra_response = get_request(chacra_url) + + return chacra_response.read() -- 2.47.3