local_tasks.py 1.87 KB
Newer Older
1
from manager.mancelery import celery
Guba Sándor committed
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16

@celery.task
def async_operation(operation_id, instance_pk, activity_pk, **kwargs):
    from vm.models import Instance, InstanceActivity
    instance = Instance.objects.get(pk=instance_pk)
    operation = getattr(instance, operation_id)
    activity = InstanceActivity.objects.get(pk=activity_pk)

    # save async task UUID to activity
    activity.task_uuid = async_operation.request.id
    activity.save()

    return operation._exec_op(activity=activity, **kwargs)

17 18
# TODO: Keep synchronised with Instance funcs

Guba Sándor committed
19 20 21 22 23 24

@celery.task
def deploy(instance, user):
    instance.deploy(task_uuid=deploy.request.id, user=user)


25
@celery.task
26 27 28 29 30
def redeploy(instance, user):
    instance.redeploy(task_uuid=redeploy.request.id, user=user)


@celery.task
31 32 33 34 35
def shut_off(instance, user):
    instance.shut_off(task_uuid=shut_off.request.id, user=user)


@celery.task
36 37
def destroy(instance, user):
    instance.destroy(task_uuid=destroy.request.id, user=user)
Guba Sándor committed
38 39


40
@celery.task
41 42 43 44 45 46
def save_as_template(instance, name, user, params):
    instance.save_as_template(name, task_uuid=save_as_template.request.id,
                              user=user, **params)


@celery.task
47 48
def sleep(instance, user):
    instance.sleep(task_uuid=sleep.request.id, user=user)
Guba Sándor committed
49 50


51 52 53
@celery.task
def wake_up(instance, user):
    instance.wake_up(task_uuid=wake_up.request.id, user=user)
Guba Sándor committed
54 55


56 57 58
@celery.task
def shutdown(instance, user):
    instance.shutdown(task_uuid=shutdown.request.id, user=user)
Guba Sándor committed
59 60


61 62 63
@celery.task
def reset(instance, user):
    instance.reset(task_uuid=reset.request.id, user=user)
Guba Sándor committed
64 65


66 67 68 69
@celery.task
def reboot(instance, user):
    instance.reboot(task_uuid=reboot.request.id, user=user)

Guba Sándor committed
70

71
@celery.task
72 73
def migrate(instance, to_node,  user):
    instance.migrate(to_node, task_uuid=migrate.request.id, user=user)
Őry Máté committed
74 75 76 77


@celery.task
def flush(node, user):
Őry Máté committed
78
    node.flush(task_uuid=flush.request.id, user=user)