commit
646f73763e
5 changed files with 36 additions and 16 deletions
|
@ -4,15 +4,21 @@ from django.core.urlresolvers import reverse
|
|||
from opennebula_api.serializers import VirtualMachineTemplateSerializer
|
||||
from opennebula_api.models import OpenNebulaManager
|
||||
|
||||
from .models import HostingPlan
|
||||
|
||||
|
||||
class ProcessVMSelectionMixin(object):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
||||
template_id = int(request.POST.get('vm_template_id'))
|
||||
configuration_id = int(request.POST.get('configuration'))
|
||||
template = OpenNebulaManager().get_template(template_id)
|
||||
data = VirtualMachineTemplateSerializer(template).data
|
||||
configuration = HostingPlan.objects.get(id=configuration_id)
|
||||
|
||||
request.session['template'] = data
|
||||
request.session['specs'] = configuration.serialize()
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
request.session['next'] = reverse('hosting:payment')
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
<div class="row text-center">
|
||||
|
||||
<div class="block col-md-offset-3">
|
||||
{% for vm in vm_types %}
|
||||
{% for vm in configuration_options %}
|
||||
<div class="col-xs-12 col-sm-6 col-md-4">
|
||||
<form class="form-inline" method="POST" action="{{request.path}}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="hosting_company" value="{{vm.hosting_company}}">
|
||||
<input type="hidden" name="location_code" value="{{vm.location_code}}">
|
||||
<input type="hidden" name="vm_template_id" value="{{vm.id}}">
|
||||
<input type="hidden" name="configuration" value="{{vm.id}}">
|
||||
|
||||
|
||||
|
||||
|
@ -53,14 +53,14 @@
|
|||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<!-- <li>
|
||||
<li>
|
||||
<label for="configuration">Configuration: </label>
|
||||
<select class="form-control" name="configuration" id="{{vm.hosting_company}}-configuration" data-vm-type="{{vm.hosting_company}}">
|
||||
{% for key,value in configuration_options.items %}
|
||||
<option value="{{key}}">{{ value }}</option>
|
||||
<select class="form-control" name="vm_template_id" id="{{vm.hosting_company}}-configuration" data-vm-type="{{vm.hosting_company}}">
|
||||
{% for template in templates %}
|
||||
<option value="{{template.id}}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</li> -->
|
||||
</li>
|
||||
<li>
|
||||
<input type="hidden" name="final_price" value="{{vm.final_price|floatformat}}">
|
||||
<h3 id="{{vm.hosting_company}}-final-price">{{vm.price|floatformat}} CHF</h3>
|
||||
|
|
|
@ -47,6 +47,7 @@ class DjangoHostingView(ProcessVMSelectionMixin, View):
|
|||
HOSTING = 'django'
|
||||
templates = OpenNebulaManager().get_templates()
|
||||
data = VirtualMachineTemplateSerializer(templates, many=True).data
|
||||
configuration_options = HostingPlan.get_serialized_configs()
|
||||
|
||||
# configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
|
||||
context = {
|
||||
|
@ -57,8 +58,8 @@ class DjangoHostingView(ProcessVMSelectionMixin, View):
|
|||
'google_analytics': "UA-62285904-6",
|
||||
'vm_types': data,
|
||||
'email': "info@django-hosting.ch",
|
||||
# 'vm_types': VirtualMachineType.get_serialized_vm_types(),
|
||||
# 'configuration_options': dict(VirtualMachinePlan.VM_CONFIGURATION)
|
||||
'configuration_options': configuration_options,
|
||||
'templates': templates,
|
||||
}
|
||||
|
||||
return context
|
||||
|
@ -77,7 +78,7 @@ class RailsHostingView(ProcessVMSelectionMixin, View):
|
|||
HOSTING = 'rails'
|
||||
|
||||
templates = OpenNebulaManager().get_templates()
|
||||
data = VirtualMachineTemplateSerializer(templates, many=True).data
|
||||
configuration_options = HostingPlan.get_serialized_configs()
|
||||
|
||||
context = {
|
||||
'hosting': HOSTING,
|
||||
|
@ -85,7 +86,8 @@ class RailsHostingView(ProcessVMSelectionMixin, View):
|
|||
'domain': "rails-hosting.ch",
|
||||
'google_analytics': "UA-62285904-5",
|
||||
'email': "info@rails-hosting.ch",
|
||||
'vm_types': data,
|
||||
'configuration_options': configuration_options,
|
||||
'templates': templates,
|
||||
}
|
||||
return context
|
||||
|
||||
|
@ -102,7 +104,7 @@ class NodeJSHostingView(ProcessVMSelectionMixin, View):
|
|||
HOSTING = 'nodejs'
|
||||
# configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
|
||||
templates = OpenNebulaManager().get_templates()
|
||||
data = VirtualMachineTemplateSerializer(templates, many=True).data
|
||||
configuration_options = HostingPlan.get_serialized_configs()
|
||||
|
||||
context = {
|
||||
'hosting': HOSTING,
|
||||
|
@ -111,7 +113,9 @@ class NodeJSHostingView(ProcessVMSelectionMixin, View):
|
|||
'domain': "node-hosting.ch",
|
||||
'google_analytics': "UA-62285904-7",
|
||||
'email': "info@node-hosting.ch",
|
||||
'vm_types': data,
|
||||
'templates': templates,
|
||||
'configuration_options': configuration_options,
|
||||
|
||||
}
|
||||
return context
|
||||
|
||||
|
@ -128,12 +132,15 @@ class HostingPricingView(ProcessVMSelectionMixin, View):
|
|||
def get_context_data(self, **kwargs):
|
||||
# configuration_options = dict(VirtualMachinePlan.VM_CONFIGURATION)
|
||||
templates = OpenNebulaManager().get_templates()
|
||||
data = VirtualMachineTemplateSerializer(templates, many=True).data
|
||||
configuration_options = HostingPlan.get_serialized_configs()
|
||||
|
||||
context = {
|
||||
# 'configuration_options': configuration_options,
|
||||
'email': "info@django-hosting.ch",
|
||||
'vm_types': data,
|
||||
'templates': templates,
|
||||
'configuration_options': configuration_options,
|
||||
|
||||
|
||||
}
|
||||
|
||||
return context
|
||||
|
|
|
@ -82,6 +82,7 @@ class OpenNebulaManager():
|
|||
try:
|
||||
vm_pool = oca.VirtualMachinePool(self.client)
|
||||
vm_pool.info()
|
||||
return vm_pool
|
||||
except AttributeError:
|
||||
logger.info('Could not connect via client, using oneadmin instead')
|
||||
try:
|
||||
|
|
|
@ -12,7 +12,7 @@ class VirtualMachineTemplateSerializer(serializers.Serializer):
|
|||
id = serializers.IntegerField(read_only=True)
|
||||
set_name = serializers.CharField(read_only=True, label='Name')
|
||||
name = serializers.SerializerMethodField()
|
||||
cores = serializers.IntegerField(source='template.vcpu')
|
||||
cores = serializers.SerializerMethodField()
|
||||
disk = serializers.IntegerField(write_only=True)
|
||||
disk_size = serializers.SerializerMethodField()
|
||||
set_memory = serializers.IntegerField(write_only=True, label='Memory')
|
||||
|
@ -41,6 +41,12 @@ class VirtualMachineTemplateSerializer(serializers.Serializer):
|
|||
|
||||
return manager.get_template(template_id=opennebula_id)
|
||||
|
||||
def get_cores(self, obj):
|
||||
if hasattr(obj.template, 'vcpu'):
|
||||
return obj.template.vcpu
|
||||
|
||||
return ''
|
||||
|
||||
def get_disk_size(self, obj):
|
||||
template = obj.template
|
||||
disk_size = 0
|
||||
|
|
Loading…
Reference in a new issue