-
-
- GB RAM
-
+
+
+ GB RAM
+
{% for message in messages %}
@@ -51,10 +53,11 @@
-->
diff --git a/datacenterlight/views.py b/datacenterlight/views.py
index fc0b8b2e..10e2d791 100644
--- a/datacenterlight/views.py
+++ b/datacenterlight/views.py
@@ -1,7 +1,7 @@
from django.views.generic import FormView, CreateView, TemplateView, DetailView
from django.http import HttpResponseRedirect
from .forms import BetaAccessForm
-from .models import BetaAccess, BetaAccessVMType, BetaAccessVM
+from .models import BetaAccess, BetaAccessVMType, BetaAccessVM, VMTemplate
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.core.mail import EmailMessage
@@ -21,7 +21,7 @@ from datetime import datetime
from membership.models import CustomUser, StripeCustomer
from opennebula_api.models import OpenNebulaManager
-from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer
+from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer, VMTemplateSerializer
class LandingProgramView(TemplateView):
@@ -211,20 +211,11 @@ class IndexView(CreateView):
for session_var in ['specs', 'user', 'billing_address_data']:
if session_var in request.session:
del request.session[session_var]
- try:
- manager = OpenNebulaManager()
- templates = manager.get_templates()
- context = {
- 'templates': VirtualMachineTemplateSerializer(templates, many=True).data
- }
- except:
- messages.error(request,
- 'We have a temporary problem to connect to our backend. \
- Please try again in a few minutes'
- )
- context = {
- 'error': 'connection'
- }
+
+ vm_templates = VMTemplate.objects.all()
+ context = {
+ 'templates': vm_templates
+ }
return render(request, self.template_name, context)
def post(self, request):
@@ -236,9 +227,8 @@ class IndexView(CreateView):
storage_field = forms.IntegerField(validators=[self.validate_storage])
price = request.POST.get('total')
template_id = int(request.POST.get('config'))
- manager = OpenNebulaManager()
- template = manager.get_template(template_id)
- template_data = VirtualMachineTemplateSerializer(template).data
+ template = VMTemplate.objects.filter(opennebula_vm_template_id=template_id).first()
+ template_data = VMTemplateSerializer(template).data
name = request.POST.get('name')
email = request.POST.get('email')
@@ -350,25 +340,6 @@ class WhyDataCenterLightView(IndexView):
template_name = "datacenterlight/whydatacenterlight.html"
model = BetaAccess
- @cache_control(no_cache=True, must_revalidate=True, no_store=True)
- def get(self, request, *args, **kwargs):
- try:
- manager = OpenNebulaManager()
- templates = manager.get_templates()
- context = {
- 'templates': VirtualMachineTemplateSerializer(templates, many=True).data,
- }
- except:
- messages.error(
- request,
- 'We have a temporary problem to connect to our backend. \
- Please try again in a few minutes'
- )
- context = {
- 'error': 'connection'
- }
- return render(request, self.template_name, context)
-
class PaymentOrderView(FormView):
template_name = 'hosting/payment.html'
@@ -499,9 +470,9 @@ class OrderConfirmationView(DetailView):
template_id=vm_template_id,
specs=specs,
vm_name="{email}-{template_name}-{date}".format(
- email=user.get('email'),
- template_name=template.get('name'),
- date=int(datetime.now().strftime("%s")))
+ email=user.get('email'),
+ template_name=template.get('name'),
+ date=int(datetime.now().strftime("%s")))
)
# Create a Hosting Order
diff --git a/opennebula_api/models.py b/opennebula_api/models.py
index 383062f1..60f3159c 100644
--- a/opennebula_api/models.py
+++ b/opennebula_api/models.py
@@ -59,7 +59,7 @@ class OpenNebulaManager():
domain=settings.OPENNEBULA_DOMAIN,
port=settings.OPENNEBULA_PORT,
endpoint=settings.OPENNEBULA_ENDPOINT
- ))
+ ))
def _get_opennebula_client(self, username, password):
return oca.Client("{0}:{1}".format(
@@ -71,7 +71,7 @@ class OpenNebulaManager():
domain=settings.OPENNEBULA_DOMAIN,
port=settings.OPENNEBULA_PORT,
endpoint=settings.OPENNEBULA_ENDPOINT
- ))
+ ))
def _get_user(self, user):
"""Get the corresponding opennebula user for a CustomUser object
@@ -325,7 +325,7 @@ class OpenNebulaManager():
public_templates = [
template
for template in self._get_template_pool()
- if 'public-' in template.name
+ if template.name.startswith('public-')
]
return public_templates
except ConnectionRefusedError:
@@ -396,7 +396,7 @@ class OpenNebulaManager():
def delete_template(self, template_id):
self.oneadmin_client.call(oca.VmTemplate.METHODS[
- 'delete'], template_id, False)
+ 'delete'], template_id, False)
def change_user_password(self, new_password):
self.oneadmin_client.call(
diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py
index 16ab1e76..12b313af 100644
--- a/opennebula_api/serializers.py
+++ b/opennebula_api/serializers.py
@@ -129,6 +129,12 @@ class VirtualMachineSerializer(serializers.Serializer):
return obj.name.strip('public-')
+class VMTemplateSerializer(serializers.Serializer):
+ """Serializer to map the VMTemplate instance into JSON format."""
+ id = serializers.IntegerField(read_only=True, source='opennebula_vm_template_id')
+ name = serializers.CharField(read_only=True)
+
+
def hexstr2int(string):
return int(string.replace(':', ''), 16)