Commit 0988e858 by Guba Sándor

adding async functions

parent f79946dd
from .mancelery import celery
@celery.task
def deploy(disk, user):
'''Create new virtual machine from VM class.
'''
disk.deploy(task_uuid=deploy.rdiskd, user=user)
def delete():
pass
def save_as():
pass
from mancelery import celery
@celery.task
def deploy(instance, user):
'''Create new virtual machine from VM class.
'''
instance.deploy(task_uuid=deploy.request.id, user=user)
def delete():
pass
def save_as():
pass
def suspend():
pass
def resume():
pass
def restart():
pass
def reset():
pass
def migrate():
pass
...@@ -6,12 +6,15 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -6,12 +6,15 @@ from django.utils.translation import ugettext_lazy as _
from django.db.models.signals import post_delete from django.db.models.signals import post_delete
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
from .tasks import StorageDriver from manager import storage
from . import tasks
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DataStore(models.Model): class DataStore(models.Model):
"""Collection of virtual disks. """Collection of virtual disks.
""" """
name = models.CharField(max_length=100, unique=True, name = models.CharField(max_length=100, unique=True,
...@@ -20,6 +23,7 @@ class DataStore(models.Model): ...@@ -20,6 +23,7 @@ class DataStore(models.Model):
verbose_name=_('path')) verbose_name=_('path'))
hostname = models.CharField(max_length=40, unique=True, hostname = models.CharField(max_length=40, unique=True,
verbose_name=_('hostname')) verbose_name=_('hostname'))
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
verbose_name = _('datastore') verbose_name = _('datastore')
...@@ -30,6 +34,7 @@ class DataStore(models.Model): ...@@ -30,6 +34,7 @@ class DataStore(models.Model):
class Disk(TimeStampedModel): class Disk(TimeStampedModel):
"""A virtual disk. """A virtual disk.
""" """
TYPES = [('qcow2-norm', 'qcow2 normal'), ('qcow2-snap', 'qcow2 snapshot'), TYPES = [('qcow2-norm', 'qcow2 normal'), ('qcow2-snap', 'qcow2 snapshot'),
...@@ -93,6 +98,9 @@ class Disk(TimeStampedModel): ...@@ -93,6 +98,9 @@ class Disk(TimeStampedModel):
def __unicode__(self): def __unicode__(self):
return u"%s (#%d)" % (self.name, self.id) return u"%s (#%d)" % (self.name, self.id)
def deploy_async(self):
storage.deploy.apply_async(self)
def deploy(self): def deploy(self):
if self.ready: if self.ready:
return return
...@@ -105,7 +113,7 @@ class Disk(TimeStampedModel): ...@@ -105,7 +113,7 @@ class Disk(TimeStampedModel):
'base_name': self.base.name if self.base else None, 'base_name': self.base.name if self.base else None,
'type': self.type 'type': self.type
} }
StorageDriver.create_disk.delay(disk_desc).get() tasks.create_disk.delay(disk_desc).get()
self.ready = True self.ready = True
self.save() self.save()
......
...@@ -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 manager, scheduler from manager import vm, scheduler
from storage.models import Disk from storage.models import Disk
...@@ -424,7 +424,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel): ...@@ -424,7 +424,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
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.
""" """
manager.deploy.apply_async(self, user) vm.deploy.apply_async(self, user)
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
......
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