diff --git a/hosting/forms.py b/hosting/forms.py
index 7323bdf3..b143140d 100644
--- a/hosting/forms.py
+++ b/hosting/forms.py
@@ -101,7 +101,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
@@ -109,8 +111,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/models.py b/hosting/models.py
index 9fa4a100..892aa45d 100644
--- a/hosting/models.py
+++ b/hosting/models.py
@@ -185,18 +185,31 @@ class VirtualMachinePlan(AssignPermissionsMixin, models.Model):
instance.assign_permissions(user)
return instance
- def cancel_plan(self):
+ def cancel_plan(self, vm_id):
self.status = self.CANCELED_STATUS
self.save(update_fields=['status'])
+ @classmethod
+ def terminate_opennebula_vm(self, user, vm_id):
+
+ opennebula_client = OpenNebulaManager(
+ user.email,
+ user.password,
+ )
+
+ return opennebula_client.terminate_vm(vm_id)
+
+
@classmethod
def create_opennebula_vm(self, user, specs):
+ # import pdb
+ # pdb.set_trace()
+
# Init opennebula manager using given user
opennebula_client = OpenNebulaManager(
user.email,
- user.password[0:20],
- create_user=True
+ user.password,
)
# Create a vm in opennebula using given specs
diff --git a/hosting/opennebula_functions.py b/hosting/opennebula_functions.py
index d2796ec8..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: