Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.2 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
QUEUE_CLUSTER = "%s-events-cluster" % prefix
47

    
48

    
49
QUEUES = (QUEUE_OP,
50
          QUEUE_NETWORK,
51
          QUEUE_PROGRESS,
52
          QUEUE_CLUSTER)
53

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

    
63
# BINDINGS:
64
BINDINGS = (
65
    # Queue           # Exchange        # RouteKey    # Handler
66
    (QUEUE_OP,        EXCHANGE_GANETI,  KEY_OP,       'update_db'),
67
    (QUEUE_NETWORK,   EXCHANGE_GANETI,  KEY_NETWORK,  'update_network'),
68
    (QUEUE_PROGRESS,  EXCHANGE_GANETI,  KEY_PROGRESS, 'update_build_progress'),
69
    (QUEUE_CLUSTER,   EXCHANGE_GANETI,  KEY_CLUSTER,  'update_cluster'),
70
)
71

    
72

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

    
80

    
81
def convert_queue_to_dead(queue):
82
    """Convert the name of a queue to the corresponding dead-letter one"""
83
    return queue + "-dl"
84

    
85

    
86
def convert_exchange_to_dead(exchange):
87
    """Convert the name of an exchange to the corresponding dead-letter one"""
88
    return exchange + "-dl"