Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3 kB)

1
# Copyright 2012 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions
5
# are met:
6
#
7
#   1. Redistributions of source code must retain the above copyright
8
#      notice, this list of conditions and the following disclaimer.
9
#
10
#  2. Redistributions in binary form must reproduce the above copyright
11
#     notice, this list of conditions and the following disclaimer in the
12
#     documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
#
26
# The views and conclusions contained in the software and documentation are
27
# those of the authors and should not be interpreted as representing official
28
# policies, either expressed or implied, of GRNET S.A.
29

    
30

    
31
from synnefo.settings import BACKEND_PREFIX_ID, DEBUG, EXCHANGE_GANETI
32

    
33
try:
34
    prefix = BACKEND_PREFIX_ID.split('-')[0]
35
except TypeError, IndexError:
36
    raise Exception("Invalid BACKEND_PREFIX_ID")
37

    
38
# EXCHANGES
39
EXCHANGES = (EXCHANGE_GANETI,)
40

    
41

    
42
# QUEUES
43
QUEUE_OP = "%s-events-op" % prefix
44
QUEUE_NETWORK = "%s-events-network" % prefix
45
QUEUE_PROGRESS = "%s-events-progress" % prefix
46

    
47

    
48
QUEUES = (QUEUE_OP,
49
          QUEUE_NETWORK,
50
          QUEUE_PROGRESS)
51

    
52
# ROUTING KEYS
53
# notifications of type "ganeti-op-status"
54
KEY_OP = 'ganeti.%s.event.op' % prefix
55
# notifications of type "ganeti-network-status"
56
KEY_NETWORK = 'ganeti.%s.event.network' % prefix
57
# notifications of type "ganeti-create-progress"
58
KEY_PROGRESS = 'ganeti.%s.event.progress' % prefix
59

    
60
# BINDINGS:
61
BINDINGS = (
62
    # Queue           # Exchange        # RouteKey    # Handler
63
    (QUEUE_OP,        EXCHANGE_GANETI,  KEY_OP,       'update_db'),
64
    (QUEUE_NETWORK,   EXCHANGE_GANETI,  KEY_NETWORK,  'update_network'),
65
    (QUEUE_PROGRESS,  EXCHANGE_GANETI,  KEY_PROGRESS, 'update_build_progress'),
66
)
67

    
68

    
69
## Extra for DEBUG:
70
if DEBUG is True:
71
    # Debug queue, retrieves all messages
72
    QUEUE_DEBUG = "%s-debug" % prefix
73
    QUEUES += (QUEUE_DEBUG,)
74
    BINDINGS += ((QUEUE_DEBUG, EXCHANGE_GANETI, "#", "dummy_proc"),)
75

    
76

    
77
def convert_queue_to_dead(queue):
78
    """Convert the name of a queue to the corresponding dead-letter one"""
79
    return queue + "-dl"
80

    
81

    
82
def convert_exchange_to_dead(exchange):
83
    """Convert the name of an exchange to the corresponding dead-letter one"""
84
    return exchange + "-dl"