vm_tasks.py 3.44 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):
Őry Máté committed
27 28 29 30 31 32
    """True if the queue is alive.

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

Őry Máté committed
43

Őry Máté committed
44 45 46
def get_queues():
    """Get active celery queues.

47 48
    Returns a dictionary whose entries are (worker name;list of queues) pairs,
    where queues are represented by dictionaries.
Őry Máté committed
49 50 51 52 53 54 55 56 57 58 59 60 61
    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


62
@celery.task(name='vmdriver.create')
63
def deploy(params):
Guba Sándor committed
64 65 66
    pass


67 68
@celery.task(name='vmdriver.delete')
def destroy(params):
Guba Sándor committed
69 70 71
    pass


72 73
@celery.task(name='vmdriver.save')
def sleep(params):
Guba Sándor committed
74 75 76
    pass


77 78
@celery.task(name='vmdriver.restore')
def wake_up(params):
Guba Sándor committed
79 80 81
    pass


82 83
@celery.task(name='vmdriver.suspend')
def suspend(params):
Guba Sándor committed
84 85 86
    pass


87 88
@celery.task(name='vmdriver.resume')
def resume(params):
Guba Sándor committed
89 90 91
    pass


92 93
@celery.task(name='vmdriver.shutdown')
def shutdown(params):
Guba Sándor committed
94 95 96
    pass


97 98
@celery.task(name='vmdriver.reset')
def reset(params):
Guba Sándor committed
99 100 101
    pass


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


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


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


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

121

122 123 124 125 126
@celery.task(name='vmdriver.list_domains_info')
def list_domains_info(params):
    pass


127 128 129
@celery.task(name='vmdriver.ping')
def ping(params):
    pass
130 131 132 133 134 135 136


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


137 138 139 140 141
@celery.task(name='vmdriver.get_architecture')
def get_architecture():
    pass


142 143 144
@celery.task(name='vmdriver.get_ram_size')
def get_ram_size(params):
    pass
145

Gregory Nagy committed
146

147 148 149 150 151
@celery.task(name='vmdriver.get_info')
def get_info(params):
    pass


152 153 154
@celery.task(name='vmdriver.get_node_metrics')
def get_node_metrics(params):
    pass
155 156 157 158 159


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