From 6a1faa52e470a3923a331ce45ad99df84a9b9d72 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 11 May 2019 00:25:49 +0200 Subject: [PATCH] Set user's own ssh keys when creating VM --- datacenterlight/tasks.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/datacenterlight/tasks.py b/datacenterlight/tasks.py index 12c1cf38..a4d2ebe7 100644 --- a/datacenterlight/tasks.py +++ b/datacenterlight/tasks.py @@ -79,10 +79,12 @@ def create_vm_task(self, vm_template_id, user, specs, template, order_id): # Create OpenNebulaManager manager = OpenNebulaManager(email=on_user, password=on_pass) + custom_user = CustomUser.objects.get(email=user.get('email')) + pub_keys = get_all_public_keys(custom_user) vm_id = manager.create_vm( template_id=vm_template_id, specs=specs, - ssh_key=settings.ONEADMIN_USER_SSH_PUBLIC_KEY, + ssh_key='\n'.join(pub_keys), vm_name=vm_name ) @@ -193,7 +195,6 @@ def create_vm_task(self, vm_template_id, user, specs, template, order_id): vm_ipv6 = manager.get_ipv6(vm_id) logger.debug("New VM ID is {vm_id}".format(vm_id=vm_id)) if vm_ipv6 is not None: - custom_user = CustomUser.objects.get(email=user.get('email')) get_or_create_vm_detail(custom_user, manager, vm_id) if custom_user is not None: public_keys = get_all_public_keys(custom_user)