',
+ 'to': ['info@ungleich.ch'],
+ 'body': "\n".join(["%s=%s" % (k, v) for (k, v) in context.items()]),
+ 'reply_to': [context['email']],
+ }
+ email = EmailMessage(**email_data)
+ email.send()
+ return HttpResponseRedirect(reverse('datacenterlight:order_confirmation', kwargs={'pk': order.id}))
+ else:
+ return self.form_invalid(form)
+
+class OrderConfirmationView(DetailView):
+ template_name = "datacenterlight/order_detail.html"
+ context_object_name = "order"
+ model = HostingOrder
+ def get_context_data(self, **kwargs):
+ # Get context
+ context = super(DetailView, self).get_context_data(**kwargs)
+ obj = self.get_object()
+ manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME,
+ password=settings.OPENNEBULA_PASSWORD)
+ try:
+ vm = manager.get_vm(obj.vm_id)
+ context['vm'] = VirtualMachineSerializer(vm).data
+ context['next_url'] = reverse('datacenterlight:order_success')
+ except WrongIdError:
+ messages.error(self.request,
+ 'The VM you are looking for is unavailable at the moment. \
+ Please contact Data Center Light support.'
+ )
+ self.kwargs['error'] = 'WrongIdError'
+ context['error'] = 'WrongIdError'
+ except ConnectionRefusedError:
+ messages.error(self.request,
+ 'In order to create a VM, you need to create/upload your SSH KEY first.'
+ )
+ return context
diff --git a/hosting/templates/hosting/base_short.html b/hosting/templates/hosting/base_short.html
index cf9f54d9..0ccfe5f9 100644
--- a/hosting/templates/hosting/base_short.html
+++ b/hosting/templates/hosting/base_short.html
@@ -46,7 +46,7 @@
- {% if request.user.is_authenticated %}
+
- {% endif %}
+
{% block content %}
diff --git a/membership/models.py b/membership/models.py
index db0155b5..16fe71e8 100644
--- a/membership/models.py
+++ b/membership/models.py
@@ -7,6 +7,7 @@ from django.core.validators import RegexValidator
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.conf import settings
+from django.utils.crypto import get_random_string
from utils.stripe_utils import StripeUtils
from utils.mailer import DigitalGlarusRegistrationMailer
@@ -74,7 +75,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
REQUIRED_FIELDS = ['name', 'password']
@classmethod
- def register(cls, name, password, email, app='digital_glarus', base_url=None):
+ def register(cls, name, password, email, app='digital_glarus', base_url=None, send_email=True):
user = cls.objects.filter(email=email).first()
if not user:
user = cls.objects.create_user(name=name, email=email, password=password)
@@ -86,19 +87,20 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
dcl_text = settings.DCL_TEXT
dcl_from_address = settings.DCL_SUPPORT_FROM_ADDRESS
user.is_active = False
- email_data = {
- 'subject': str(_('Activate your ')) + dcl_text + str(_(' account')),
- 'from_address': settings.DCL_SUPPORT_FROM_ADDRESS,
- 'to': user.email,
- 'context': {'base_url' : base_url,
- 'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug}),
- 'dcl_text' : dcl_text
- },
- 'template_name': 'user_activation',
- 'template_path': 'datacenterlight/emails/'
- }
- email = BaseEmail(**email_data)
- email.send()
+ if send_email is True:
+ email_data = {
+ 'subject': str(_('Activate your ')) + dcl_text + str(_(' account')),
+ 'from_address': settings.DCL_SUPPORT_FROM_ADDRESS,
+ 'to': user.email,
+ 'context': {'base_url' : base_url,
+ 'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug}),
+ 'dcl_text' : dcl_text
+ },
+ 'template_name': 'user_activation',
+ 'template_path': 'datacenterlight/emails/'
+ }
+ email = BaseEmail(**email_data)
+ email.send()
return user
else:
return None
@@ -118,6 +120,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
return True
return False
+ @classmethod
+ def get_random_password(cls):
+ return get_random_string(24)
+
def is_superuser(self):
return False
diff --git a/opennebula_api/models.py b/opennebula_api/models.py
index 397c0f0c..d18524c5 100644
--- a/opennebula_api/models.py
+++ b/opennebula_api/models.py
@@ -239,7 +239,7 @@ class OpenNebulaManager():
)
)
- def create_vm(self, template_id, specs, ssh_key=None):
+ def create_vm(self, template_id, specs, ssh_key=None, vm_name=None):
template = self.get_template(template_id)
vm_specs_formatter = """
@@ -286,15 +286,14 @@ class OpenNebulaManager():
""".format(size=1024 * int(specs['disk_size']),
image=image,
image_uname=image_uname)
-
-
+
+ vm_specs += ""
if ssh_key:
- vm_specs += """
- {ssh}
- YES
+ vm_specs += "{ssh}".format(ssh=ssh_key)
+ vm_specs += """YES
-
- """.format(ssh=ssh_key)
+
+ """
vm_id = self.client.call(oca.VmTemplate.METHODS['instantiate'],
template.id,
'',
@@ -307,6 +306,13 @@ class OpenNebulaManager():
'release',
vm_id
)
+
+ if vm_name is not None:
+ self.oneadmin_client.call(
+ 'vm.rename',
+ vm_id,
+ vm_name
+ )
return vm_id
def delete_vm(self, vm_id):