Use save_key_in_opennebula_user and save_key_in_vm_template
This commit is contained in:
parent
3602bb0eb7
commit
65c9ccb671
1 changed files with 15 additions and 6 deletions
|
@ -463,7 +463,11 @@ class SSHKeyDeleteView(LoginRequiredMixin, DeleteView):
|
||||||
public_key = UserHostingKey.objects.get(pk=pk).public_key
|
public_key = UserHostingKey.objects.get(pk=pk).public_key
|
||||||
keys = UserHostingKey.objects.filter(user=self.request.user)
|
keys = UserHostingKey.objects.filter(user=self.request.user)
|
||||||
keys_to_save = [k.public_key for k in keys if k != public_key]
|
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)
|
return super(SSHKeyDeleteView, self).delete(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -513,7 +517,11 @@ class SSHKeyChoiceView(LoginRequiredMixin, View):
|
||||||
password=owner.password
|
password=owner.password
|
||||||
)
|
)
|
||||||
keys = get_all_public_keys(request.user)
|
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')
|
return redirect(reverse_lazy('hosting:ssh_keys'), foo='bar')
|
||||||
|
|
||||||
|
|
||||||
|
@ -563,12 +571,13 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView):
|
||||||
email=owner.email,
|
email=owner.email,
|
||||||
password=owner.password
|
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 = UserHostingKey.objects.filter(user=self.request.user)
|
||||||
keys_to_save = [k.public_key for k in keys]
|
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)
|
return HttpResponseRedirect(self.success_url)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue