local_agent_tasks.py 1.48 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/>.

18
from django.utils.translation import ugettext_noop
Bach Dániel committed
19

Bach Dániel committed
20
from manager.mancelery import celery
Bach Dániel committed
21 22


Bach Dániel committed
23
@celery.task
24
def agent_started(vm, version=None, system=None):
Bach Dániel committed
25
    from vm.models import Instance
Bach Dániel committed
26
    instance = Instance.objects.get(id=int(vm.split('-')[-1]))
Bach Dániel committed
27 28
    instance.agent_started(
        user=instance.owner, old_version=version, agent_system=system)
Kálmán Viktor committed
29 30


Bach Dániel committed
31 32
@celery.task
def agent_stopped(vm):
33
    from vm.models import Instance, InstanceActivity
Bach Dániel committed
34
    instance = Instance.objects.get(id=int(vm.split('-')[-1]))
Bach Dániel committed
35 36
    qs = InstanceActivity.objects.filter(
        instance=instance, activity_code='vm.Instance.agent')
Bach Dániel committed
37
    act = qs.latest('id')
Bach Dániel committed
38 39
    with act.sub_activity('stopping', concurrency_check=False,
                          readable_name=ugettext_noop('stopping')):
Bach Dániel committed
40
        pass