From 65c9ccb671fa8e3d690b4cf01b47a99c8c72234c Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 11 May 2019 01:54:35 +0200 Subject: [PATCH] Use save_key_in_opennebula_user and save_key_in_vm_template --- hosting/views.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 209df30b..450875e5 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -463,7 +463,11 @@ class SSHKeyDeleteView(LoginRequiredMixin, DeleteView): public_key = UserHostingKey.objects.get(pk=pk).public_key keys = UserHostingKey.objects.filter(user=self.request.user) keys_to_save = [k.public_key for k in keys if k != public_key] - manager.save_key_in_opennebula('\n'.join(keys_to_save)) + manager.save_key_in_opennebula_user('\n'.join(keys_to_save)) + vm_ids = manager.get_all_vmids() + if len(vm_ids) > 0 and len(keys_to_save) > 0: + for vm_id in vm_ids: + manager.save_key_in_vm_template(vm_id, '\n'.join(keys_to_save)) return super(SSHKeyDeleteView, self).delete(request, *args, **kwargs) @@ -513,7 +517,11 @@ class SSHKeyChoiceView(LoginRequiredMixin, View): password=owner.password ) keys = get_all_public_keys(request.user) - manager.save_key_in_opennebula('\n'.join(keys)) + vm_ids = manager.get_all_vmids() + manager.save_key_in_opennebula_user('\n'.join(keys)) + if len(vm_ids) > 0 and len(keys) > 0: + for vm_id in vm_ids: + manager.save_key_in_vm_template(vm_id, '\n'.join(keys)) return redirect(reverse_lazy('hosting:ssh_keys'), foo='bar') @@ -563,12 +571,13 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): email=owner.email, password=owner.password ) - public_key = form.cleaned_data['public_key'] - if type(public_key) is bytes: - public_key = public_key.decode() keys = UserHostingKey.objects.filter(user=self.request.user) keys_to_save = [k.public_key for k in keys] - manager.save_key_in_opennebula('\n'.join(keys_to_save)) + manager.save_key_in_opennebula_user('\n'.join(keys_to_save)) + vm_ids = manager.get_all_vmids() + if len(vm_ids) > 0 and len(keys) > 0: + for vm_id in vm_ids: + manager.save_key_in_vm_template(vm_id, '\n'.join(keys_to_save)) return HttpResponseRedirect(self.success_url) def post(self, request, *args, **kwargs):