]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-18169] util: create http get helpers to help translate chacra urls into repos
authorAlfredo Deza <adeza@redhat.com>
Thu, 8 Dec 2016 13:37:14 +0000 (08:37 -0500)
committerAlfredo Deza <adeza@redhat.com>
Thu, 8 Dec 2016 13:37:14 +0000 (08:37 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
ceph_deploy/util/net.py

index 103b3244ca98c56f29affe1fc8c232cd6f3a30c5..f23c6654a502388c297dbe1d0bfb58b828045004 100644 (file)
@@ -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()