Commit 2e78f147 by Guba Sándor

refactor manager

parent d6b8a8a9
from celery import Celery from celery import Celery
from kombu import Queue, Exchange from kombu import Queue, Exchange
from socket import gethostname from os import getenv
HOSTNAME = "localhost"
HOSTNAME = gethostname()
celery = Celery('manager', backend='amqp', celery = Celery('manager', backend='amqp',
broker='amqp://cloud:test@10.9.1.31/vmdriver', broker=getenv("AMQP_URI"),
include=['vmdriver_stub']) include=['manager.vm_manager', 'manager.storage_manager'])
celery.conf.update( celery.conf.update(
CELERY_QUEUES=( CELERY_QUEUES=(
......
...@@ -8,9 +8,11 @@ def deploy(disk, user): ...@@ -8,9 +8,11 @@ def deploy(disk, user):
disk.deploy(task_uuid=deploy.rdiskd, user=user) disk.deploy(task_uuid=deploy.rdiskd, user=user)
@celery.task
def delete(): def delete():
pass pass
@celery.task
def save_as(): def save_as():
pass pass
from mancelery import celery from .mancelery import celery
@celery.task @celery.task
......
...@@ -13,7 +13,7 @@ from netaddr import EUI ...@@ -13,7 +13,7 @@ from netaddr import EUI
from . import tasks from . import tasks
from firewall.models import Vlan, Host from firewall.models import Vlan, Host
from manager import vm, scheduler from manager import vm_manager, scheduler
from storage.models import Disk from storage.models import Disk
...@@ -35,7 +35,7 @@ class BaseResourceConfigModel(models.Model): ...@@ -35,7 +35,7 @@ class BaseResourceConfigModel(models.Model):
arch = models.CharField(max_length=10, verbose_name=_('architecture')) arch = models.CharField(max_length=10, verbose_name=_('architecture'))
priority = models.IntegerField(help_text=_('instance priority')) priority = models.IntegerField(help_text=_('instance priority'))
boot_menu = models.BooleanField(default=False) boot_menu = models.BooleanField(default=False)
raw_data = models.TextField(blank=True, null=True) raw_data = models.TextField(blank=True)
class Meta: class Meta:
abstract = True abstract = True
...@@ -242,7 +242,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel): ...@@ -242,7 +242,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
verbose_name=_('active since')) verbose_name=_('active since'))
node = models.ForeignKey(Node, blank=True, null=True, node = models.ForeignKey(Node, blank=True, null=True,
related_name='instance_set', related_name='instance_set',
verbose_name=_('host nose')) verbose_name=_('host node'))
state = models.CharField(choices=STATES, default='NOSTATE', max_length=20) state = models.CharField(choices=STATES, default='NOSTATE', max_length=20)
disks = models.ManyToManyField(Disk, related_name='instance_set', disks = models.ManyToManyField(Disk, related_name='instance_set',
verbose_name=_('disks')) verbose_name=_('disks'))
...@@ -416,15 +416,15 @@ class Instance(BaseResourceConfigModel, TimeStampedModel): ...@@ -416,15 +416,15 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
'type': 'vnc', 'type': 'vnc',
'listen': '0.0.0.0', 'listen': '0.0.0.0',
'passwd': '', 'passwd': '',
'port': self.get_vnc_port() 'port': self.vnc_port
}, },
'raw_data': self.raw_data 'raw_data': "" if not self.raw_data else self.raw_data
} }
def deploy_async(self, user=None): def deploy_async(self, user=None):
""" Launch celery task to handle the job asynchronously. """ Launch celery task to handle the job asynchronously.
""" """
vm.deploy.apply_async(self, user) vm_manager.deploy.apply_async(self, user, queue="localhost.man")
def deploy(self, user=None, task_uuid=None): def deploy(self, user=None, task_uuid=None):
""" Deploy new virtual machine with network """ Deploy new virtual machine with network
...@@ -437,7 +437,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel): ...@@ -437,7 +437,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
# Schedule # Schedule
act.update_state("PENDING") act.update_state("PENDING")
self.node = scheduler.get_node() self.node = scheduler.get_node(self)
self.save() self.save()
# Create virtual images # Create virtual images
...@@ -447,8 +447,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel): ...@@ -447,8 +447,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
# Deploy VM on remote machine # Deploy VM on remote machine
act.update_state("DEPLOYING VM") act.update_state("DEPLOYING VM")
tasks.create.apply_async(self.get_vm_desc, tasks.create.apply_async(args=[self.get_vm_desc()],
queue=self.node + ".vm").get() queue=self.node.host.hostname + ".vm").get()
# Estabilish network connection (vmdriver) # Estabilish network connection (vmdriver)
act.update_state("DEPLOYING NET") act.update_state("DEPLOYING NET")
...@@ -457,7 +457,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel): ...@@ -457,7 +457,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
# Resume vm # Resume vm
act.update_state("BOOTING") act.update_state("BOOTING")
tasks.resume.apply_async(self.vm_name, queue=self.node + ".vm").get() tasks.resume.apply_async(args=[self.vm_name],
queue=self.node + ".vm").get()
act.finish(result='SUCCESS') act.finish(result='SUCCESS')
......
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