Commit 654dbc54 by Szabolcs Gelencser

Implement deploy operation for Azure VM creation.

parent b2ef4090
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0007_interface_azure_id'),
]
operations = [
migrations.AddField(
model_name='instance',
name='azure_id',
field=models.TextField(null=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0008_instance_azure_id'),
]
operations = [
migrations.AlterField(
model_name='instance',
name='azure_id',
field=models.TextField(blank=True),
),
]
......@@ -228,6 +228,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
)
name = CharField(blank=True, max_length=100, verbose_name=_('name'),
help_text=_("Human readable name of instance."))
azure_id = TextField(blank=True)
description = TextField(blank=True, verbose_name=_('description'))
template = ForeignKey(InstanceTemplate, blank=True, null=True,
related_name='instance_set', on_delete=SET_NULL,
......@@ -645,7 +646,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
if self.node:
return self.node.get_remote_queue_name(queue_id, priority)
else:
raise Node.DoesNotExist()
return "localhost.vm.fast"
def _is_notified_about_expiration(self):
last_activity = self.activity_log.latest('pk')
......
......@@ -51,6 +51,8 @@ from .models import (
Instance, InstanceActivity, InstanceTemplate, Interface, Node,
NodeActivity, pwgen
)
#from storage.models import DataStore
from .tasks import agent_tasks, vm_tasks
from dashboard.store_api import Store, NoStoreException
......@@ -377,32 +379,10 @@ class DeployOperation(InstanceOperation):
node=self.instance.node)
def _operation(self, activity, node=None):
# Allocate VNC port and host node
self.instance.allocate_vnc_port()
if node is not None:
self.instance.node = node
self.instance.save()
else:
self.instance.allocate_node()
# Deploy virtual images
try:
self.instance._deploy_disks(parent_activity=activity)
except:
self.instance.yield_node()
self.instance.yield_vnc_port()
raise
# Deploy VM on remote machine
if self.instance.state not in ['PAUSED']:
# Deploy VM in Azure
if self.instance.state == 'PENDING':
self.instance._deploy_vm(parent_activity=activity)
# Establish network connection (vmdriver)
with activity.sub_activity(
'deploying_net', readable_name=ugettext_noop(
"deploy network")):
self.instance.deploy_net()
try:
self.instance.renew(parent_activity=activity)
except:
......@@ -410,26 +390,46 @@ class DeployOperation(InstanceOperation):
self.instance._resume_vm(parent_activity=activity)
if self.instance.has_agent:
activity.sub_activity('os_boot', readable_name=ugettext_noop(
"wait operating system loading"), interruptible=True)
@register_operation
class DeployVmOperation(SubOperationMixin, RemoteInstanceOperation):
class DeployVmOperation(SubOperationMixin, InstanceOperation):
id = "_deploy_vm"
name = _("deploy vm")
description = _("Deploy virtual machine.")
remote_queue = ("vm", "slow")
task = vm_tasks.deploy
def _get_remote_args(self, **kwargs):
return [self.instance.get_vm_desc()]
# intentionally not calling super
def get_activity_name(self, kwargs):
return create_readable(ugettext_noop("deploy virtual machine"),
ugettext_noop("deploy vm to %(node)s"),
node=self.instance.node)
def _operation(self):
nics = [str(nic_id) for nic_id in
self.instance.interface_set.values_list('azure_id', flat=True)]
#storage_name = DataStore.objects.get(pk=1).name
vm_size_version = self.instance.azure_template
vm_size_sku = vm_size_version.sku
vm_size_offer = vm_size_sku.offer
vm_size_publisher = vm_size_offer.publisher
args = [{
"name": self.instance.name,
"user": "cloud",
"pw": self.instance.pw,
"vm_size": self.instance.azure_vm_size.name,
"nics": nics,
"datastore_name": "mylittledatastore", #storage_name,
"os_publisher": vm_size_publisher.name,
"os_offer": vm_size_offer.name,
"os_sku": vm_size_sku.name,
"os_version": vm_size_version.name,
}]
azure_id = vm_tasks.deploy.apply_async(
args=args, queue="localhost.vm.fast"
).get(timeout=1200)
if azure_id:
logger.info("deployed '%s' vm in azure, with id '%s'" % (
self.instance.name, azure_id))
self.instance.azure_id = azure_id
self.instance.save()
else:
logger.error("failed to deploy '%s' vm in azure" % (
self.instance.name))
@register_operation
class DeployDisksOperation(SubOperationMixin, InstanceOperation):
......
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