diff --git a/hosting/forms.py b/hosting/forms.py
index a8a60678..c94c4822 100644
--- a/hosting/forms.py
+++ b/hosting/forms.py
@@ -69,7 +69,9 @@ class UserHostingKeyForm(forms.ModelForm):
# print(self.fields)
def clean_name(self):
- return ''.join(random.choice(string.ascii_lowercase) for i in range(7))
+ return "dcl-priv-key-%s" % (
+ ''.join(random.choice(string.ascii_lowercase) for i in range(7))
+ )
def clean_user(self):
return self.request.user
@@ -77,8 +79,6 @@ class UserHostingKeyForm(forms.ModelForm):
def clean(self):
cleaned_data = self.cleaned_data
- print(cleaned_data)
-
if not cleaned_data.get('public_key'):
private_key, public_key = UserHostingKey.generate_keys()
cleaned_data.update({
diff --git a/hosting/migrations/0039_hostingorder_price.py b/hosting/migrations/0039_hostingorder_price.py
new file mode 100644
index 00000000..0d4945fa
--- /dev/null
+++ b/hosting/migrations/0039_hostingorder_price.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.4 on 2017-05-12 16:37
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('hosting', '0038_auto_20170512_1006'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='hostingorder',
+ name='price',
+ field=models.FloatField(default=0),
+ preserve_default=False,
+ ),
+ ]
diff --git a/hosting/models.py b/hosting/models.py
index 6eb0aa24..188f1733 100644
--- a/hosting/models.py
+++ b/hosting/models.py
@@ -1,5 +1,7 @@
import os
import socket
+import logging
+
import oca
from django.db import models
@@ -19,9 +21,9 @@ from .managers import VMPlansManager
from oca.exceptions import OpenNebulaException
from oca.pool import WrongNameError
-import logging
logger = logging.getLogger(__name__)
+
class HostingOrder(AssignPermissionsMixin, models.Model):
ORDER_APPROVED_STATUS = 'Approved'
@@ -35,6 +37,7 @@ class HostingOrder(AssignPermissionsMixin, models.Model):
last4 = models.CharField(max_length=4)
cc_brand = models.CharField(max_length=10)
stripe_charge_id = models.CharField(max_length=100, null=True)
+ price = models.FloatField()
permissions = ('view_hostingorder',)
@@ -51,9 +54,13 @@ class HostingOrder(AssignPermissionsMixin, models.Model):
return self.ORDER_APPROVED_STATUS if self.approved else self.ORDER_DECLINED_STATUS
@classmethod
- def create(cls, vm_plan=None, customer=None, billing_address=None):
- instance = cls.objects.create(vm_plan=vm_plan, customer=customer,
- billing_address=billing_address)
+ def create(cls, price=None, vm_id=None, customer=None, billing_address=None):
+ instance = cls.objects.create(
+ price=price,
+ vm_id=vm_id,
+ customer=customer,
+ billing_address=billing_address
+ )
instance.assign_permissions(customer.user)
return instance
@@ -67,6 +74,12 @@ class HostingOrder(AssignPermissionsMixin, models.Model):
self.cc_brand = stripe_charge.source.brand
self.save()
+ def get_cc_data(self):
+ return {
+ 'last4': self.last4,
+ 'cc_brand': self.cc_brand,
+ } if self.last4 and self.cc_brand else None
+
class UserHostingKey(models.Model):
user = models.ForeignKey(CustomUser)
diff --git a/hosting/opennebula_functions.py b/hosting/opennebula_functions.py
index a00bb037..aca5424d 100644
--- a/hosting/opennebula_functions.py
+++ b/hosting/opennebula_functions.py
@@ -35,7 +35,7 @@ class OpenNebulaManager:
'11': 'CLONING_FAILURE',
}
- def __init__(self, email=None, password=None, create_user=True):
+ def __init__(self, email=None, password=None):
# Get oneadmin client
self.oneadmin_client = self._get_opennebula_client(
@@ -43,9 +43,6 @@ class OpenNebulaManager:
settings.OPENNEBULA_PASSWORD
)
- if not create_user:
- return
-
# Get or create oppenebula user using given credentials
self.opennebula_user = self._get_or_create_user(
email,
@@ -121,9 +118,17 @@ class OpenNebulaManager:
return vm_data
+ def change_user_password(self, new_password):
+ self.oneadmin_client.call(
+ oca.User.METHODS['passwd'],
+ self.opennebula_user.id,
+ new_password
+ )
+
def create_vm(self, specs):
vm_id = None
try:
+
# We do have the vm_template param set. Get and parse it
# and check it to be in the desired range.
# We have 8 possible VM templates for the moment which are 1x, 2x, 4x ...
@@ -136,6 +141,9 @@ class OpenNebulaManager: