vmcelery.py 632 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 10
AMQP_URI = getenv('AMQP_URI')

Guba Sándor committed
11

tarokkk committed
12 13
lib_connection = None

Guba Sándor committed
14
celery = Celery('vmcelery', backend='amqp',
15 16
                broker=AMQP_URI,
                include=['vmdriver'])
Guba Sándor committed
17 18 19 20 21 22 23 24

celery.conf.update(
    CELERY_QUEUES=(
        Queue(HOSTNAME + '.vm', Exchange(
            'vmdriver', type='direct'), routing_key="vmdriver"),
    )
)

25
if getenv('LIBVIRT_KEEPALIVE') is not None:
Guba Sándor committed
26
    import libvirt
27
    lib_connection = libvirt.open(getenv('LIBVIRT_URI'))