Package pulp :: Package messaging :: Module transport
[hide private]
[frames] | no frames]

Source Code for Module pulp.messaging.transport

 1  # 
 2  # Copyright (c) 2010 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  """ 
17  Contains custom QPID transport classes. 
18  """ 
19   
20  from pulp.messaging.broker import Broker 
21  from ssl import wrap_socket, CERT_NONE, CERT_REQUIRED 
22  from qpid.messaging.transports import connect, TRANSPORTS, tls 
23  from logging import getLogger 
24   
25  log = getLogger(__name__) 
26   
27   
28 -class SSLTransport(tls):
29 """ 30 SSL Transport. 31 """ 32
33 - def __init__(self, broker):
34 """ 35 @param broker: An amqp broker. 36 @type broker: L{Broker} 37 """ 38 url = broker.url 39 self.socket = connect(url.host, url.port) 40 if broker.cacert: 41 reqcert = CERT_REQUIRED 42 else: 43 reqcert = CERT_NONE 44 self.tls = wrap_socket( 45 self.socket, 46 cert_reqs=reqcert, 47 ca_certs = broker.cacert, 48 certfile = broker.clientcert) 49 self.socket.setblocking(0) 50 self.state = None
51 52
53 -class SSLFactory:
54 """ 55 Factory used to create a transport. 56 """ 57
58 - def __call__(self, host, port):
59 """ 60 @param host: A host or IP. 61 @type host: str 62 @type port: A tcp port. 63 @type port: int 64 """ 65 url = '%s:%d' % (host, port) 66 broker = Broker.get(url) 67 transport = SSLTransport(broker) 68 return transport
69 70 # 71 # Install the transport. 72 # 73 TRANSPORTS['ssl'] = SSLFactory() 74