vmcelery.py 836 Bytes
Newer Older
Guba Sándor committed
1
""" Celery module for libvirt RPC calls. """
Guba Sándor committed
2 3 4
from celery import Celery
from kombu import Queue, Exchange
from socket import gethostname
5
from os import getenv
Guba Sándor committed
6

Guba Sándor committed
7

Guba Sándor committed
8
HOSTNAME = gethostname()
9
AMQP_URI = getenv('AMQP_URI')
10
CACHE_URI = getenv('CACHE_URI')
11

Guba Sándor committed
12

13 14 15
def to_bool(value):
    return value.lower() in ("true", "yes", "y", "t")

tarokkk committed
16 17
lib_connection = None

18
celery = Celery('vmcelery',
19 20
                broker=AMQP_URI,
                include=['vmdriver'])
Guba Sándor committed
21 22

celery.conf.update(
23 24
    CELERY_RESULT_BACKEND='cache',
    CELERY_CACHE_BACKEND=CACHE_URI,
Bach Dániel committed
25
    CELERY_TASK_RESULT_EXPIRES=300,
Guba Sándor committed
26 27 28 29 30 31
    CELERY_QUEUES=(
        Queue(HOSTNAME + '.vm', Exchange(
            'vmdriver', type='direct'), routing_key="vmdriver"),
    )
)

32
if to_bool(getenv('LIBVIRT_KEEPALIVE', "False")):
Guba Sándor committed
33
    import libvirt
34
    lib_connection = libvirt.open(getenv('LIBVIRT_URI'))