Code cleanup: remove updating ssh keys on live VMs

This commit is contained in:
PCoder 2019-06-25 02:11:57 +02:00
commit 08608c726f
5 changed files with 4 additions and 229 deletions

View file

@ -2,7 +2,6 @@ import logging
import uuid
from datetime import datetime
from time import sleep
from urllib import parse
from django import forms
from django.conf import settings
@ -35,7 +34,6 @@ from stored_messages.settings import stored_messages_settings
from datacenterlight.cms_models import DCLCalculatorPluginModel
from datacenterlight.models import VMTemplate, VMPricing
from datacenterlight.tasks import save_ssh_key_in_vm_template_task
from datacenterlight.utils import create_vm, get_cms_integration
from hosting.models import UserCardDetail
from membership.models import CustomUser, StripeCustomer
@ -1514,59 +1512,6 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
return redirect(reverse('hosting:payment'))
class AddSshKeyToVMView(LoginRequiredMixin, View):
def respond_with_error(self):
response = {'status': False}
response['msg_title'] = str(_("No ssh keys provided"))
response['msg_body'] = str(
_("Please retry and select one of the keys"))
json_response = JsonResponse(response)
return json_response
@method_decorator(decorators)
def post(self, request, *args, **kwargs):
try:
vm_id = int(self.kwargs.get('pk'))
except ValueError as ve:
logger.error("Value error {}".format(str(ve)))
return self.respond_with_error()
if 'selected_key' not in request.POST:
return self.respond_with_error()
else:
posted_keys = parse.unquote_plus(request.POST['selected_key'])
if posted_keys.strip() == "":
return self.respond_with_error()
keys = posted_keys.split(",")
uh_keys = [
UserHostingKey.objects.get(
user=request.user, name=key)
for key in keys if key is not None and key is not ""
]
# Add public_keys to vm_id now
public_keys = [uh_key.public_key for uh_key in uh_keys]
keys_str = '\n'.join(public_keys)
user = {
'email': request.user.email,
'pass': request.user.password,
'request_scheme': request.scheme,
'request_host': request.get_host(),
'language': get_language(),
}
save_ssh_key_in_vm_template_task.delay(user,vm_id, keys_str)
response = dict()
response['status'] = True
response['msg_title'] = str(_(
"Adding of your SSH key add is under process"
))
response['msg_body'] = str(_(
"Your keys %s will be added to the VM in the next couple of "
"minutes. You will receive a confirmation email once this has "
"been done. Thank you." % posted_keys
))
return JsonResponse(response)
class VirtualMachineView(LoginRequiredMixin, View):
template_name = "hosting/virtual_machine_detail.html"
login_url = reverse_lazy('hosting:login')