Package pulp :: Package server :: Package api :: Module fetch_listings
[hide private]
[frames] | no frames]

Source Code for Module pulp.server.api.fetch_listings

 1  # 
 2  # This module establishes and retrieves listing files from CDN for  
 3  # versions and arches substitutions 
 4  # 
 5  # Copyright (c) 2010 Red Hat, Inc. 
 6  # 
 7  # This software is licensed to you under the GNU General Public License, 
 8  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 9  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
10  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
11  # along with this software; if not, see 
12  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
13  # 
14  # Red Hat trademarks are not licensed under GPLv2. No permission is 
15  # granted to use or replicate Red Hat trademarks that are incorporated 
16  # in this software or its documentation. 
17  # 
18   
19  import logging 
20  from M2Crypto import SSL, httpslib 
21   
22  log = logging.getLogger(__name__) 
23   
24 -class CDNConnection:
25 - def __init__(self, hostname, port=443, cacert=None, cert=None, key=None):
26 self.hostname = hostname 27 self.port = port 28 self.cacert = cacert 29 self.cert = cert 30 self.key = key 31 self.httpServ = None
32
33 - def connect(self):
34 context = SSL.Context("sslv3") 35 context.load_cert(self.cert, keyfile=self.key) 36 context.load_verify_locations(self.cacert) 37 context.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, depth=9) 38 39 self.httpServ = httpslib.HTTPSConnection(self.hostname, port=self.port, 40 ssl_context=context) 41 self.httpServ.connect()
42
43 - def _request_get(self, URI):
44 """ 45 Fetch the listings file from CDN 46 @param URI: relative url for the listings file 47 @type URI: str (ex: "/content/dist/rhel/server/listing") 48 """ 49 self.httpServ.request('GET', URI) 50 response = self.httpServ.getresponse() 51 if response.status != 200: 52 raise Exception(response.status, response.read()) 53 return response.read()
54
55 - def fetch_urls(self, content_sets):
56 version_arch_urls = {} 57 for label, uri in content_sets.items(): 58 try: 59 versions = self._request_get(uri[:uri.find("$releasever")] + "/listing").split('\n') 60 for version in versions: 61 ver_uri = uri.replace("$releasever", version) 62 arches = self._request_get(ver_uri[:ver_uri.find("$basearch")] + "/listing").split('\n') 63 for arch in arches: 64 full_uri = ver_uri.replace("$basearch", arch) 65 version_arch_urls[label + '-' + version + '-' + arch] = full_uri 66 except Exception: 67 log.error("Unable to fetch the listings file for relative url %s" % uri) 68 69 return version_arch_urls
70
71 - def disconnect(self):
72 self.httpServ.close()
73