Commit 797305ce by Szabolcs Gelencser

Add Azure specific fields to instance, base template creation form.

parent 541a0e59
...@@ -54,7 +54,9 @@ from django.core.urlresolvers import reverse_lazy ...@@ -54,7 +54,9 @@ from django.core.urlresolvers import reverse_lazy
from django_sshkey.models import UserKey from django_sshkey.models import UserKey
from firewall.models import Vlan, Host from firewall.models import Vlan, Host
from vm.models import ( from vm.models import (
InstanceTemplate, Lease, InterfaceTemplate, Node, Trait, Instance InstanceTemplate, Lease, InterfaceTemplate, Node, Trait, Instance,
AzureVirtualMachineSize, AzureBuiltinPublisher, AzureBuiltinOffer,
AzureBuiltinSKU, AzureBuiltinVersion
) )
from storage.models import DataStore, Disk from storage.models import DataStore, Disk
from django.contrib.admin.widgets import FilteredSelectMultiple from django.contrib.admin.widgets import FilteredSelectMultiple
...@@ -458,8 +460,43 @@ class NodeForm(forms.ModelForm): ...@@ -458,8 +460,43 @@ class NodeForm(forms.ModelForm):
model = Node model = Node
fields = ['name', 'priority', 'enabled', ] fields = ['name', 'priority', 'enabled', ]
from logging import getLogger
logger = getLogger(__name__)
class VmSizeChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return """%s, Cores: %d, Memory: %d MB, OS Disk: %d MB,
Data Disk: %d MB, Max disks: %d""" % (
obj.name, obj.number_of_cores, obj.memory_in_mb,
obj.os_disk_size_in_mb, obj.resource_disk_size_in_mb,
obj.max_data_disk_count)
class TemplateForm(forms.ModelForm): class TemplateForm(forms.ModelForm):
logger.debug(str(AzureVirtualMachineSize.objects.all()))
azure_vm_size = VmSizeChoiceField(
queryset=AzureVirtualMachineSize.objects.all())
#TODO: this is terribly slow, should make 4 choicefields, and set choices
# with JS value changed event, and AJAX calls
# ONLY FOR TESTING PURPOSES
def generate_azure_template_list():
result = []
for p in AzureBuiltinPublisher.objects.all():
for o in p.azure_offer.all():
for s in o.azure_sku.all():
for v in s.azure_version.all():
result.append((
v.pk,
"%s - %s - %s - %s" % (
p.name, o.name, s.name, v.name
),
))
return result
azure_template = forms.ChoiceField(
choices=generate_azure_template_list
)
networks = forms.ModelMultipleChoiceField( networks = forms.ModelMultipleChoiceField(
queryset=None, required=False, label=_("Networks")) queryset=None, required=False, label=_("Networks"))
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
{% if perms.vm.create_base_template %} {% if perms.vm.create_base_template %}
<div class="panel panel-default template-choose-list-element"> <div class="panel panel-default template-choose-list-element">
<input type="radio" name="parent" value="base_vm"/> <input type="radio" name="parent" value="base_vm"/>
{% trans "Create a new base VM without disk" %} {% trans "Create a new base VM from Azure Built-In templates" %}
</div> </div>
{% endif %} {% endif %}
<button type="submit" id="template-choose-next-button" class="btn btn-success pull-right">{% trans "Next" %}</button> <button type="submit" id="template-choose-next-button" class="btn btn-success pull-right">{% trans "Next" %}</button>
......
...@@ -11,6 +11,12 @@ ...@@ -11,6 +11,12 @@
{{ form.name|as_crispy_field }} {{ form.name|as_crispy_field }}
<fieldset>
<legend>{% trans "Azure settings" %}</legend>
{{ form.azure_vm_size|as_crispy_field }}
{{ form.azure_template|as_crispy_field }}
</fieldset>
<fieldset class="resources-sliders"> <fieldset class="resources-sliders">
<legend>{% trans "Resource configuration" %}</legend> <legend>{% trans "Resource configuration" %}</legend>
{% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %} {% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %}
......
...@@ -36,7 +36,9 @@ from braces.views import ( ...@@ -36,7 +36,9 @@ from braces.views import (
) )
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from vm.models import InstanceTemplate, InterfaceTemplate, Instance, Lease from vm.models import (
InstanceTemplate, InterfaceTemplate, Instance, Lease, AzureBuiltinVersion
)
from storage.models import Disk from storage.models import Disk
from ..forms import ( from ..forms import (
...@@ -147,6 +149,8 @@ class TemplateCreate(SuccessMessageMixin, CreateView): ...@@ -147,6 +149,8 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
tags = post.pop("tags") tags = post.pop("tags")
post['pw'] = User.objects.make_random_password() post['pw'] = User.objects.make_random_password()
post['is_base'] = True post['is_base'] = True
post['azure_template'] = AzureBuiltinVersion.objects.get(
pk=post['azure_template'])
inst = Instance.create(params=post, disks=[], inst = Instance.create(params=post, disks=[],
networks=networks, networks=networks,
tags=tags, req_traits=req_traits) tags=tags, req_traits=req_traits)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0005_azurevirtualmachinesize'),
]
operations = [
migrations.AddField(
model_name='instance',
name='azure_template',
field=models.ForeignKey(default=8000, verbose_name='azure vm template', to='vm.AzureBuiltinVersion'),
preserve_default=False,
),
migrations.AddField(
model_name='instance',
name='azure_vm_size',
field=models.ForeignKey(default=1, verbose_name='azure vm size', to='vm.AzureVirtualMachineSize'),
preserve_default=False,
),
migrations.AlterField(
model_name='azurevirtualmachinesize',
name='name',
field=models.TextField(unique=True, verbose_name='name'),
),
]
...@@ -50,6 +50,8 @@ from .activity import (ActivityInProgressError, InstanceActivity) ...@@ -50,6 +50,8 @@ from .activity import (ActivityInProgressError, InstanceActivity)
from .common import BaseResourceConfigModel, Lease from .common import BaseResourceConfigModel, Lease
from .network import Interface from .network import Interface
from .node import Node, Trait from .node import Node, Trait
from .azure_virtual_machine_size import AzureVirtualMachineSize
from .azure_builtin_template import AzureBuiltinVersion
logger = getLogger(__name__) logger = getLogger(__name__)
pre_state_changed = Signal(providing_args=["new_state"]) pre_state_changed = Signal(providing_args=["new_state"])
...@@ -259,6 +261,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -259,6 +261,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
objects = Manager() objects = Manager()
active = QueryManager(destroyed_at=None) active = QueryManager(destroyed_at=None)
azure_vm_size = ForeignKey(AzureVirtualMachineSize,
verbose_name=_('azure vm size'))
azure_template = ForeignKey(AzureBuiltinVersion,
verbose_name=_('azure vm template'))
class Meta: class Meta:
app_label = 'vm' app_label = 'vm'
db_table = 'vm_instance' db_table = 'vm_instance'
......
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