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