vm_tasks.py 4 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
    Result is cached for 10 seconds!
    """
    key = __name__ + u'queues'
    result = cache.get(key)
    if result is None:
        inspect = celery.control.inspect()
58
        inspect.timeout = 0.5
Őry Máté committed
59
        result = inspect.active_queues()
60
        logger.debug('Queue list of length %d cached.', result and len(result))
Őry Máté committed
61 62 63 64
        cache.set(key, result, 10)
    return result


Guba Sándor committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
@celery.task(name='vmdriver.attach_disk')
def attach_disk(vm, disk):
    pass


@celery.task(name='vmdriver.detach_disk')
def detach_disk(vm, disk):
    pass


@celery.task(name='vmdriver.attach_network')
def attach_network(vm, net):
    pass


@celery.task(name='vmdriver.detach_network')
def detach_network(vm, net):
    pass


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


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


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


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


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


110 111
@celery.task(name='vmdriver.resume')
def resume(params):
Guba Sándor committed
112 113 114
    pass


115 116
@celery.task(name='vmdriver.shutdown')
def shutdown(params):
Guba Sándor committed
117 118 119
    pass


120 121
@celery.task(name='vmdriver.reset')
def reset(params):
Guba Sándor committed
122 123 124
    pass


125 126
@celery.task(name='vmdriver.reboot')
def reboot(params):
Guba Sándor committed
127 128 129 130 131
    pass


@celery.task(name='vmdriver.migrate')
def migrate(params):
132
    pass
Guba Sándor committed
133 134


135 136 137 138 139
@celery.task(name='vmdriver.resize_disk')
def resize_disk(params):
    pass


Guba Sándor committed
140 141 142 143 144 145 146 147
@celery.task(name='vmdriver.domain_info')
def domain_info(params):
    pass


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

149

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


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


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


165 166 167 168 169
@celery.task(name='vmdriver.get_architecture')
def get_architecture():
    pass


170 171 172
@celery.task(name='vmdriver.get_ram_size')
def get_ram_size(params):
    pass
173

Gregory Nagy committed
174

175 176 177 178 179
@celery.task(name='vmdriver.get_info')
def get_info(params):
    pass


180 181 182
@celery.task(name='vmdriver.get_node_metrics')
def get_node_metrics(params):
    pass
183 184 185 186 187


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