Revision bd444a11

b/logic/dispatcher.py
96 96

  
97 97
    def _init(self):
98 98
        self.logger.info("Initializing")
99
        
99

  
100
        # Queue declarations
101
        prefix = settings.BACKEND_PREFIX_ID.split('-')[0]
102

  
103
        QUEUE_GANETI_EVENTS_OP = "%s-events-op" % prefix
104
        QUEUE_GANETI_EVENTS_NET = "%s-events-net" % prefix
105
        QUEUE_CRON_CREDITS = "%s-credits" % prefix
106
        QUEUE_EMAIL = "%s-email" % prefix
107
        QUEUE_RECONC = "%s-reconciliation" % prefix
108
        if settings.DEBUG is True:
109
            QUEUE_DEBUG = "debug"       # Debug queue, retrieves all messages
110

  
111
        QUEUES = (QUEUE_GANETI_EVENTS_OP, QUEUE_GANETI_EVENTS_NET,
112
                  QUEUE_CRON_CREDITS, QUEUE_EMAIL, QUEUE_RECONC)
113

  
114
        if settings.DEBUG is True:
115
            BINDINGS_DEBUG = [
116
                # Queue       # Exchange          # RouteKey  # Handler
117
                (QUEUE_DEBUG, settings.EXCHANGE_GANETI, '#',  'dummy_proc'),
118
                (QUEUE_DEBUG, settings.EXCHANGE_CRON,   '#',  'dummy_proc'),
119
                (QUEUE_DEBUG, settings.EXCHANGE_API,    '#',  'dummy_proc'),
120
            ]
121
            QUEUES += (QUEUE_DEBUG,)
122

  
123
        # notifications of type "ganeti-op-status"
124
        DB_HANDLER_KEY_OP ='ganeti.%s.event.op' % prefix
125
        # notifications of type "ganeti-net-status"
126
        DB_HANDLER_KEY_NET ='ganeti.%s.event.net' % prefix
127

  
128
        BINDINGS = [
129
        # Queue                   # Exchange                # RouteKey          # Handler
130
        (QUEUE_GANETI_EVENTS_OP,  settings.EXCHANGE_GANETI, DB_HANDLER_KEY_OP,  'update_db'),
131
        (QUEUE_GANETI_EVENTS_NET, settings.EXCHANGE_GANETI, DB_HANDLER_KEY_NET, 'update_net'),
132
        (QUEUE_CRON_CREDITS,      settings.EXCHANGE_CRON,   '*.credits.*',      'update_credits'),
133
        (QUEUE_EMAIL,             settings.EXCHANGE_API,    '*.email.*',        'send_email'),
134
        (QUEUE_EMAIL,             settings.EXCHANGE_CRON,   '*.email.*',        'send_email'),
135
        (QUEUE_RECONC,            settings.EXCHANGE_CRON,   'reconciliation.*', 'trigger_status_update'),
136
        ]
137

  
100 138
        # Connect to RabbitMQ
101 139
        conn = None
102 140
        while conn == None:
......
118 156
            self.chan.exchange_declare(exchange=exchange, type="topic",
119 157
                                       durable=True, auto_delete=False)
120 158

  
121
        for queue in settings.QUEUES:
159
        for queue in QUEUES:
122 160
            self.chan.queue_declare(queue=queue, durable=True,
123 161
                                    exclusive=False, auto_delete=False)
124 162

  
125
        bindings = settings.BINDINGS
163
        bindings = BINDINGS
126 164

  
127 165
        # Special queue for debugging, should not appear in production
128 166
        if self.debug and settings.DEBUG:
129
            self.chan.queue_declare(queue=settings.QUEUE_DEBUG, durable=True,
167
            self.chan.queue_declare(queue=QUEUE_DEBUG, durable=True,
130 168
                                    exclusive=False, auto_delete=False)
131
            bindings += settings.BINDINGS_DEBUG
169
            bindings += BINDINGS_DEBUG
132 170

  
133 171
        # Bind queues to handler methods
134 172
        for binding in bindings:
b/settings.d/15-queues.conf
13 13
EXCHANGE_CRON = "cron"      # Messages from periodically triggered tasks
14 14
EXCHANGE_API = "api"        # Messages from the REST API
15 15
EXCHANGES = (EXCHANGE_GANETI, EXCHANGE_CRON, EXCHANGE_API)
16

  
17
def fix_amqp_settings(backend_prefix):
18
    """Configure AMQP-specific settings
19

  
20
    Configure AMQP-specific settings based on backend_prefix.
21
    This function *must* be called later in settings.py, with
22
    BACKEND_PREFIX_ID as argument.
23

  
24
    """
25
    global BINDINGS, QUEUES, QUEUE_DEBUG, BINDINGS_DEBUG
26

  
27
    BINDINGS = []
28
    QUEUES = []
29

  
30
    prefix = backend_prefix.split('-')[0]
31

  
32
    QUEUE_GANETI_EVENTS_OP = "%s-events-op" % prefix
33
    QUEUE_GANETI_EVENTS_NET = "%s-events-net" % prefix
34
    QUEUE_CRON_CREDITS = "%s-credits" % prefix
35
    QUEUE_EMAIL = "%s-email" % prefix
36
    QUEUE_RECONC = "%s-reconciliation" % prefix
37
    if DEBUG is True:
38
        QUEUE_DEBUG = "debug"       # Debug queue, retrieves all messages
39

  
40
    QUEUES = (QUEUE_GANETI_EVENTS_OP, QUEUE_GANETI_EVENTS_NET,
41
              QUEUE_CRON_CREDITS, QUEUE_EMAIL, QUEUE_RECONC)
42

  
43
    if DEBUG is True:
44
        BINDINGS_DEBUG = [
45
        # Queue         # Exchange          # RouteKey  # Handler
46
        (QUEUE_DEBUG,   EXCHANGE_GANETI,    '#',        'dummy_proc'),
47
        (QUEUE_DEBUG,   EXCHANGE_CRON,      '#',        'dummy_proc'),
48
        (QUEUE_DEBUG,   EXCHANGE_API,       '#',        'dummy_proc'),
49
        ]
50
        QUEUES += (QUEUE_DEBUG,)
51

  
52
    # notifications of type "ganeti-op-status"
53
    DB_HANDLER_KEY_OP ='ganeti.%s.event.op' % prefix 
54
    # notifications of type "ganeti-net-status"
55
    DB_HANDLER_KEY_NET ='ganeti.%s.event.net' % prefix
56

  
57
    BINDINGS = [
58
    # Queue                     # Exchange          # RouteKey              # Handler
59
    (QUEUE_GANETI_EVENTS_OP,    EXCHANGE_GANETI,    DB_HANDLER_KEY_OP,    'update_db'),
60
    (QUEUE_GANETI_EVENTS_NET,   EXCHANGE_GANETI,    DB_HANDLER_KEY_NET,   'update_net'),
61
    (QUEUE_CRON_CREDITS,        EXCHANGE_CRON,      '*.credits.*',          'update_credits'),
62
    (QUEUE_EMAIL,               EXCHANGE_API,       '*.email.*',            'send_email'),
63
    (QUEUE_EMAIL,               EXCHANGE_CRON,      '*.email.*',            'send_email'),
64
    (QUEUE_RECONC,              EXCHANGE_CRON,      'reconciliation.*',     'trigger_status_update'),
65
    ]
66

  
67

  
68
# Fix up the AMQP-specific settings based on BACKEND_PREFIX_ID
69
# Make sure to call it again, if you modify it at some later point
70
fix_amqp_settings(BACKEND_PREFIX_ID)

Also available in: Unified diff