Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / logic / queues.py @ 95059648

History | View | Annotate | Download (3 kB)

1 659de616 Christos Stavrakakis
# Copyright 2012 GRNET S.A. All rights reserved.
2 659de616 Christos Stavrakakis
#
3 659de616 Christos Stavrakakis
# Redistribution and use in source and binary forms, with or without
4 659de616 Christos Stavrakakis
# modification, are permitted provided that the following conditions
5 659de616 Christos Stavrakakis
# are met:
6 659de616 Christos Stavrakakis
#
7 659de616 Christos Stavrakakis
#   1. Redistributions of source code must retain the above copyright
8 659de616 Christos Stavrakakis
#      notice, this list of conditions and the following disclaimer.
9 659de616 Christos Stavrakakis
#
10 659de616 Christos Stavrakakis
#  2. Redistributions in binary form must reproduce the above copyright
11 659de616 Christos Stavrakakis
#     notice, this list of conditions and the following disclaimer in the
12 659de616 Christos Stavrakakis
#     documentation and/or other materials provided with the distribution.
13 659de616 Christos Stavrakakis
#
14 659de616 Christos Stavrakakis
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 659de616 Christos Stavrakakis
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 659de616 Christos Stavrakakis
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 659de616 Christos Stavrakakis
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 659de616 Christos Stavrakakis
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 659de616 Christos Stavrakakis
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 659de616 Christos Stavrakakis
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 659de616 Christos Stavrakakis
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 659de616 Christos Stavrakakis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 659de616 Christos Stavrakakis
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 659de616 Christos Stavrakakis
# SUCH DAMAGE.
25 659de616 Christos Stavrakakis
#
26 659de616 Christos Stavrakakis
# The views and conclusions contained in the software and documentation are
27 659de616 Christos Stavrakakis
# those of the authors and should not be interpreted as representing official
28 659de616 Christos Stavrakakis
# policies, either expressed or implied, of GRNET S.A.
29 659de616 Christos Stavrakakis
30 659de616 Christos Stavrakakis
31 659de616 Christos Stavrakakis
from synnefo.settings import BACKEND_PREFIX_ID, DEBUG, EXCHANGE_GANETI
32 659de616 Christos Stavrakakis
33 659de616 Christos Stavrakakis
try:
34 659de616 Christos Stavrakakis
    prefix = BACKEND_PREFIX_ID.split('-')[0]
35 659de616 Christos Stavrakakis
except TypeError, IndexError:
36 659de616 Christos Stavrakakis
    raise Exception("Invalid BACKEND_PREFIX_ID")
37 659de616 Christos Stavrakakis
38 659de616 Christos Stavrakakis
# EXCHANGES
39 659de616 Christos Stavrakakis
EXCHANGES = (EXCHANGE_GANETI,)
40 659de616 Christos Stavrakakis
41 659de616 Christos Stavrakakis
42 659de616 Christos Stavrakakis
# QUEUES
43 659de616 Christos Stavrakakis
QUEUE_OP = "%s-events-op" % prefix
44 659de616 Christos Stavrakakis
QUEUE_NETWORK = "%s-events-network" % prefix
45 659de616 Christos Stavrakakis
QUEUE_PROGRESS = "%s-events-progress" % prefix
46 659de616 Christos Stavrakakis
47 659de616 Christos Stavrakakis
48 659de616 Christos Stavrakakis
QUEUES = (QUEUE_OP,
49 659de616 Christos Stavrakakis
          QUEUE_NETWORK,
50 659de616 Christos Stavrakakis
          QUEUE_PROGRESS)
51 659de616 Christos Stavrakakis
52 659de616 Christos Stavrakakis
# ROUTING KEYS
53 659de616 Christos Stavrakakis
# notifications of type "ganeti-op-status"
54 659de616 Christos Stavrakakis
KEY_OP = 'ganeti.%s.event.op' % prefix
55 659de616 Christos Stavrakakis
# notifications of type "ganeti-network-status"
56 659de616 Christos Stavrakakis
KEY_NETWORK = 'ganeti.%s.event.network' % prefix
57 659de616 Christos Stavrakakis
# notifications of type "ganeti-create-progress"
58 659de616 Christos Stavrakakis
KEY_PROGRESS = 'ganeti.%s.event.progress' % prefix
59 659de616 Christos Stavrakakis
60 659de616 Christos Stavrakakis
# BINDINGS:
61 659de616 Christos Stavrakakis
BINDINGS = (
62 cc92b70f Christos Stavrakakis
    # Queue           # Exchange        # RouteKey    # Handler
63 cc92b70f Christos Stavrakakis
    (QUEUE_OP,        EXCHANGE_GANETI,  KEY_OP,       'update_db'),
64 cc92b70f Christos Stavrakakis
    (QUEUE_NETWORK,   EXCHANGE_GANETI,  KEY_NETWORK,  'update_network'),
65 cc92b70f Christos Stavrakakis
    (QUEUE_PROGRESS,  EXCHANGE_GANETI,  KEY_PROGRESS, 'update_build_progress'),
66 659de616 Christos Stavrakakis
)
67 659de616 Christos Stavrakakis
68 659de616 Christos Stavrakakis
69 659de616 Christos Stavrakakis
## Extra for DEBUG:
70 659de616 Christos Stavrakakis
if DEBUG is True:
71 659de616 Christos Stavrakakis
    # Debug queue, retrieves all messages
72 659de616 Christos Stavrakakis
    QUEUE_DEBUG = "%s-debug" % prefix
73 659de616 Christos Stavrakakis
    QUEUES += (QUEUE_DEBUG,)
74 659de616 Christos Stavrakakis
    BINDINGS += ((QUEUE_DEBUG, EXCHANGE_GANETI, "#", "dummy_proc"),)
75 659de616 Christos Stavrakakis
76 659de616 Christos Stavrakakis
77 659de616 Christos Stavrakakis
def convert_queue_to_dead(queue):
78 659de616 Christos Stavrakakis
    """Convert the name of a queue to the corresponding dead-letter one"""
79 659de616 Christos Stavrakakis
    return queue + "-dl"
80 659de616 Christos Stavrakakis
81 659de616 Christos Stavrakakis
82 659de616 Christos Stavrakakis
def convert_exchange_to_dead(exchange):
83 659de616 Christos Stavrakakis
    """Convert the name of an exchange to the corresponding dead-letter one"""
84 659de616 Christos Stavrakakis
    return exchange + "-dl"