~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

Viewing changes to src/maasserver/rabbit.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-27 14:49:56 UTC
  • mto: (20.1.1 quantal) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20120327144956-z5stunhc83bnnwsi
Tags: upstream-0.1+bzr363+dfsg
ImportĀ upstreamĀ versionĀ 0.1+bzr363+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    ]
18
18
 
19
19
 
 
20
from errno import ECONNREFUSED
 
21
import socket
20
22
import threading
21
23
 
22
24
from amqplib import client_0_8 as amqp
23
25
from django.conf import settings
 
26
from maasserver.exceptions import NoRabbit
24
27
 
25
28
 
26
29
def connect():
27
30
    """Connect to AMQP."""
28
 
    return amqp.Connection(
29
 
        host=settings.RABBITMQ_HOST,
30
 
        userid=settings.RABBITMQ_USERID,
31
 
        password=settings.RABBITMQ_PASSWORD,
32
 
        virtual_host=settings.RABBITMQ_VIRTUAL_HOST,
33
 
        insist=False)
 
31
    try:
 
32
        return amqp.Connection(
 
33
            host=settings.RABBITMQ_HOST,
 
34
            userid=settings.RABBITMQ_USERID,
 
35
            password=settings.RABBITMQ_PASSWORD,
 
36
            virtual_host=settings.RABBITMQ_VIRTUAL_HOST,
 
37
            insist=False)
 
38
    except socket.error as e:
 
39
        if e.errno == ECONNREFUSED:
 
40
            raise NoRabbit(e.message)
 
41
        else:
 
42
            raise
34
43
 
35
44
 
36
45
class RabbitSession(threading.local):