Commit c462cc6d by Szabolcs Gelencser

Refactor deploy vm operation, add diagnostics extension deploy

parent bac9f005
......@@ -52,7 +52,7 @@ from .models import (
NodeActivity, pwgen
)
from .tasks import agent_tasks, vm_tasks
from .tasks import agent_tasks, vm_tasks, net_tasks
from dashboard.store_api import Store, NoStoreException
from firewall.models import Host
......@@ -372,28 +372,25 @@ class DeployOperation(InstanceOperation):
def on_commit(self, activity):
activity.resultant_state = 'RUNNING'
activity.result = create_readable(
ugettext_noop("virtual machine successfully "
"deployed to node: %(node)s"),
node=self.instance.node)
def _operation(self, activity, node=None):
# Deploy VM in Azure
if self.instance.state == 'PENDING':
if not self.instance.azure_id:
self.instance._deploy_vm(parent_activity=activity)
self.instance._start_diagnostics(parent_activity=activity)
else:
self.instance._resume_vm(parent_activity=activity)
self.instance._collect_public_ips(parent_activity=activity)
try:
self.instance.renew(parent_activity=activity)
except:
pass
self.instance._resume_vm(parent_activity=activity)
@register_operation
class DeployVmOperation(SubOperationMixin, InstanceOperation):
id = "_deploy_vm"
name = _("deploy vm")
description = _("Deploy virtual machine.")
name = _("Create and start virtual machine in Azure")
def _operation(self):
nics = [str(nic_id) for nic_id in
......@@ -419,7 +416,7 @@ class DeployOperation(InstanceOperation):
}]
azure_id = vm_tasks.deploy.apply_async(
args=args, queue="localhost.vm.fast"
args=args, queue="localhost.vm.slow"
).get(timeout=1200)
if azure_id:
......@@ -434,17 +431,26 @@ class DeployOperation(InstanceOperation):
@register_operation
class ResumeVmOperation(SubOperationMixin, InstanceOperation):
id = "_resume_vm"
name = _("boot virtual machine")
name = _("Start existing virtual machine")
def _operation(self):
vm_tasks.resume.apply_async(
args=[self.instance.name], queue="localhost.vm.slow"
).get(timeout=1200)
@register_operation
class CollectPublicIPsOperation(SubOperationMixin, InstanceOperation):
id = "_collect_public_ips"
name = _("Collect public IPs of virtual machine")
def _operation(self):
#TODO: implement resume functionality too
nics = [{
"id": nic.id,
"public_ip_name": nic.public_ip_name,
} for nic in self.instance.interface_set.all()]
result = vm_tasks.resume.apply_async(
args=[nics], queue="localhost.vm.fast"
result = net_tasks.collect_public_ips.apply_async(
args=[nics], queue="localhost.net.fast"
).get(timeout=1200)
for nic in result:
......@@ -452,6 +458,16 @@ class DeployOperation(InstanceOperation):
nic_obj.public_ip = nic["public_ip"]
nic_obj.save()
@register_operation
class StartDiagnosticsOperation(SubOperationMixin, InstanceOperation):
id = "_start_diagnostics"
name = _("Start diagnostics on virtual machine")
def _operation(self):
vm_tasks.install_diagnostics_extension.apply_async(
args=[self.instance.name], queue="localhost.vm.fast"
).get(timeout=1200)
@register_operation
class DestroyOperation(InstanceOperation):
id = 'destroy'
......
......@@ -17,6 +17,9 @@
from manager.mancelery import celery
@celery.task(name='netdriver.collect_public_ips')
def collect_public_ips(nics):
pass
@celery.task(name='netdriver.create_azure_interface')
def create_azure_interface(ifacepk, vlan_name):
......
......@@ -61,6 +61,10 @@ def get_queues():
cache.set(key, result, 10)
return result
@celery.task(name='vmdriver.install_diagnostics_extension')
def install_diagnostics_extension(vm_name):
pass
@celery.task(name='vmdriver.save_as_template')
def save_as_template(vm_name, vm_pk):
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