Commit c462cc6d by Szabolcs Gelencser

Refactor deploy vm operation, add diagnostics extension deploy

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