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 _
from django.db.models.signals import post_delete
from model_utils.models import TimeStampedModel
from .tasks import StorageDriver
from manager import storage
from . import tasks
logger = logging.getLogger(__name__)
class DataStore(models.Model):
"""Collection of virtual disks.
"""
name = models.CharField(max_length=100, unique=True,
......@@ -20,6 +23,7 @@ class DataStore(models.Model):
verbose_name=_('path'))
hostname = models.CharField(max_length=40, unique=True,
verbose_name=_('hostname'))
class Meta:
ordering = ['name']
verbose_name = _('datastore')
......@@ -30,6 +34,7 @@ class DataStore(models.Model):
class Disk(TimeStampedModel):
"""A virtual disk.
"""
TYPES = [('qcow2-norm', 'qcow2 normal'), ('qcow2-snap', 'qcow2 snapshot'),
......@@ -93,6 +98,9 @@ class Disk(TimeStampedModel):
def __unicode__(self):
return u"%s (#%d)" % (self.name, self.id)
def deploy_async(self):
storage.deploy.apply_async(self)
def deploy(self):
if self.ready:
return
......@@ -105,7 +113,7 @@ class Disk(TimeStampedModel):
'base_name': self.base.name if self.base else None,
'type': self.type
}
StorageDriver.create_disk.delay(disk_desc).get()
tasks.create_disk.delay(disk_desc).get()
self.ready = True
self.save()
......
......@@ -13,7 +13,7 @@ from netaddr import EUI
from . import tasks
from firewall.models import Vlan, Host
from manager import manager, scheduler
from manager import vm, scheduler
from storage.models import Disk
......@@ -424,7 +424,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
def deploy_async(self, user=None):
""" 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):
""" 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