From 3f198bb4decff20bbd7d2a48fedeb358bdd920ed Mon Sep 17 00:00:00 2001 From: Levi Date: Sun, 21 May 2017 22:01:26 -0500 Subject: [PATCH] Fixed djangohosting, railshosting and nodehosting page. Fixed payment erro --- hosting/mixins.py | 6 +++++ .../templates/hosting/includes/_pricing.html | 14 +++++------ hosting/views.py | 23 ++++++++++++------- opennebula_api/models.py | 1 + opennebula_api/serializers.py | 8 ++++++- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/hosting/mixins.py b/hosting/mixins.py index c8539eee..666cbcbe 100644 --- a/hosting/mixins.py +++ b/hosting/mixins.py @@ -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') diff --git a/hosting/templates/hosting/includes/_pricing.html b/hosting/templates/hosting/includes/_pricing.html index c1b2fa11..c5cb2bf1 100644 --- a/hosting/templates/hosting/includes/_pricing.html +++ b/hosting/templates/hosting/includes/_pricing.html @@ -18,13 +18,13 @@
- {% for vm in vm_types %} + {% for vm in configuration_options %}
{% csrf_token %} - + @@ -53,14 +53,14 @@
- +
  • {{vm.price|floatformat}} CHF

    diff --git a/hosting/views.py b/hosting/views.py index 10116079..8ab77a2a 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -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 diff --git a/opennebula_api/models.py b/opennebula_api/models.py index bf5b036e..1745fb49 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -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: diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index c8878120..c72af4e3 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -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