Commit 9bd69e0a by Bach Dániel

Merge branch 'feature-improve-agent' into 'master'

Feature Improve Agent
parents 8e898f22 492a0407
...@@ -41,3 +41,13 @@ def set_hostname(vm, time): ...@@ -41,3 +41,13 @@ def set_hostname(vm, time):
@celery.task(name='agent.mount_store') @celery.task(name='agent.mount_store')
def mount_store(vm, host, username, password): def mount_store(vm, host, username, password):
pass pass
@celery.task(name='agent.cleanup')
def cleanup(vm):
pass
@celery.task(name='agent.start_access_server')
def start_access_server(vm):
pass
...@@ -17,27 +17,43 @@ ...@@ -17,27 +17,43 @@
from manager.mancelery import celery from manager.mancelery import celery
from vm.tasks.agent_tasks import (restart_networking, change_password, from vm.tasks.agent_tasks import (restart_networking, change_password,
set_time, set_hostname) set_time, set_hostname, start_access_server,
cleanup)
import time import time
def send_init_commands(instance, act, vm):
queue = instance.get_remote_queue_name("agent")
with act.sub_activity('cleanup'):
cleanup.apply_async(queue=queue, args=(vm, ))
with act.sub_activity('restart_networking'):
restart_networking.apply_async(queue=queue, args=(vm, ))
with act.sub_activity('change_password'):
change_password.apply_async(queue=queue, args=(vm, instance.pw))
with act.sub_activity('set_time'):
set_time.apply_async(queue=queue, args=(vm, time.time()))
with act.sub_activity('set_hostname'):
set_hostname.apply_async(
queue=queue, args=(vm, instance.primary_host.hostname))
@celery.task @celery.task
def agent_started(vm): def agent_started(vm):
from vm.models import Instance, instance_activity from vm.models import Instance, instance_activity, InstanceActivity
instance = Instance.objects.get(id=int(vm.split('-')[-1])) instance = Instance.objects.get(id=int(vm.split('-')[-1]))
initialized = InstanceActivity.objects.filter(
instance=instance, activity_code='vm.Instance.agent').exists()
with instance_activity(code_suffix='agent', instance=instance) as act: with instance_activity(code_suffix='agent', instance=instance) as act:
with act.sub_activity('starting'): with act.sub_activity('starting'):
queue = "%s.agent" % instance.node.host.hostname pass
print queue if not initialized:
restart_networking.apply_async(queue=queue, send_init_commands(instance, act, vm)
args=(vm, )) with act.sub_activity('start_access_server'):
change_password.apply_async(queue=queue, queue = instance.get_remote_queue_name("agent")
args=(vm, instance.pw)) start_access_server.apply_async(
set_time.apply_async(queue=queue, queue=queue, args=(vm, ))
args=(vm, time.time()))
set_hostname.apply_async(queue=queue,
args=(vm, instance.primary_host.hostname))
@celery.task @celery.task
...@@ -49,14 +65,3 @@ def agent_stopped(vm): ...@@ -49,14 +65,3 @@ def agent_stopped(vm):
act = qs.latest('id') act = qs.latest('id')
with act.sub_activity('stopping'): with act.sub_activity('stopping'):
pass pass
@celery.task
def agent_ok(vm):
from vm.models import Instance, InstanceActivity
instance = Instance.objects.get(id=int(vm.split('-')[-1]))
qs = InstanceActivity.objects.filter(instance=instance,
activity_code='vm.Instance.agent')
act = qs.latest('id')
with act.sub_activity('ok'):
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment