vm_tasks.py 3.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE.  If not, see <http://www.gnu.org/licenses/>.

Őry Máté committed
18 19 20
from django.core.cache import cache
from logging import getLogger

Guba Sándor committed
21
from manager.mancelery import celery
22

Őry Máté committed
23 24
logger = getLogger(__name__)

25

26
def check_queue(node_hostname, queue_id, priority=None):
Őry Máté committed
27 28
    """True if the queue is alive.

29
    Example: check_queue('node01', 'vm', 'slow'):
Őry Máté committed
30 31
    :param node_hostname: Short hostname of the node.
    :param queue_id: Queue identifier (eg. vm).
32
    :param priority: can be 'slow', 'fast' or None
Őry Máté committed
33
    """
Őry Máté committed
34
    # drivers = ['vmdriver', 'netdriver', 'agentdriver']
Őry Máté committed
35
    # worker_list = [node_hostname + "." + d for d in drivers]
36
    queue_name = node_hostname + "." + queue_id
37 38
    if priority is not None:
        queue_name = queue_name + "." + priority
Őry Máté committed
39
    active_queues = get_queues()
40 41
    if active_queues is None:
        return False
42 43 44
    queue_names = (queue['name'] for worker in active_queues.itervalues()
                   for queue in worker)
    return queue_name in queue_names
45

Őry Máté committed
46

Őry Máté committed
47 48 49
def get_queues():
    """Get active celery queues.

50 51
    Returns a dictionary whose entries are (worker name;list of queues) pairs,
    where queues are represented by dictionaries.
Őry Máté committed
52 53 54 55 56 57 58 59 60 61 62 63 64
    Result is cached for 10 seconds!
    """
    key = __name__ + u'queues'
    result = cache.get(key)
    if result is None:
        inspect = celery.control.inspect()
        inspect.timeout = 0.1
        result = inspect.active_queues()
        logger.debug('Queue list of length %d cached.', len(result))
        cache.set(key, result, 10)
    return result


65
@celery.task(name='vmdriver.create')
66
def deploy(params):
Guba Sándor committed
67 68 69
    pass


70 71
@celery.task(name='vmdriver.delete')
def destroy(params):
Guba Sándor committed
72 73 74
    pass


75 76
@celery.task(name='vmdriver.save')
def sleep(params):
Guba Sándor committed
77 78 79
    pass


80 81
@celery.task(name='vmdriver.restore')
def wake_up(params):
Guba Sándor committed
82 83 84
    pass


85 86
@celery.task(name='vmdriver.suspend')
def suspend(params):
Guba Sándor committed
87 88 89
    pass


90 91
@celery.task(name='vmdriver.resume')
def resume(params):
Guba Sándor committed
92 93 94
    pass


95 96
@celery.task(name='vmdriver.shutdown')
def shutdown(params):
Guba Sándor committed
97 98 99
    pass


100 101
@celery.task(name='vmdriver.reset')
def reset(params):
Guba Sándor committed
102 103 104
    pass


105 106
@celery.task(name='vmdriver.reboot')
def reboot(params):
Guba Sándor committed
107 108 109 110 111
    pass


@celery.task(name='vmdriver.migrate')
def migrate(params):
112
    pass
Guba Sándor committed
113 114 115 116 117 118 119 120 121 122


@celery.task(name='vmdriver.domain_info')
def domain_info(params):
    pass


@celery.task(name='vmdriver.list_domains')
def list_domains(params):
    pass
123

124

125 126 127 128 129
@celery.task(name='vmdriver.list_domains_info')
def list_domains_info(params):
    pass


130 131 132
@celery.task(name='vmdriver.ping')
def ping(params):
    pass
133 134 135 136 137 138 139


@celery.task(name='vmdriver.get_core_num')
def get_core_num(params):
    pass


140 141 142 143 144
@celery.task(name='vmdriver.get_architecture')
def get_architecture():
    pass


145 146 147
@celery.task(name='vmdriver.get_ram_size')
def get_ram_size(params):
    pass
148

Gregory Nagy committed
149

150 151 152 153 154
@celery.task(name='vmdriver.get_info')
def get_info(params):
    pass


155 156 157
@celery.task(name='vmdriver.get_node_metrics')
def get_node_metrics(params):
    pass
158 159 160 161 162


@celery.task(name='vmdriver.screenshot')
def screenshot(params):
    pass