From 2731ea86359d406a772b6368cafb565a7e4bdd17 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Fri, 15 Sep 2017 11:32:17 +0200 Subject: [PATCH] Fixed getting custom_user when calling create_vm for hosting --- datacenterlight/tasks.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/datacenterlight/tasks.py b/datacenterlight/tasks.py index b9efb328..795697c8 100644 --- a/datacenterlight/tasks.py +++ b/datacenterlight/tasks.py @@ -7,7 +7,7 @@ from django.core.mail import EmailMessage from dynamicweb.celery import app from hosting.models import HostingOrder, HostingBill -from membership.models import StripeCustomer +from membership.models import StripeCustomer, CustomUser from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import VirtualMachineSerializer from utils.hosting_utils import get_all_public_keys @@ -135,24 +135,28 @@ def create_vm_task(self, vm_template_id, user, specs, template, } email = EmailMessage(**email_data) email.send() - + if 'pass' in user: # try to see if we have the IP and that if the ssh keys can # be configured new_host = manager.get_primary_ipv4(vm_id) + logger.debug("New VM ID is {vm_id}".format(vm_id=vm_id)) if new_host is not None: - public_keys = get_all_public_keys(owner) - keys = [{'value': key, 'state': True} for key in public_keys] - if len(keys) > 0: - logger.debug( - "Calling configure on {host} for {num_keys} keys".format( - host=new_host, num_keys=len(keys))) - # Let's delay the task by 75 seconds to be sure - # that we run the cdist configure after the host - # is up - manager.manage_public_key(keys, - hosts=[new_host], - countdown=75) + custom_user = CustomUser.objects.get(email=user.get('email')) + if custom_user is not None: + public_keys = get_all_public_keys(custom_user) + keys = [{'value': key, 'state': True} for key in + public_keys] + if len(keys) > 0: + logger.debug( + "Calling configure on {host} for {num_keys} keys".format( + host=new_host, num_keys=len(keys))) + # Let's delay the task by 75 seconds to be sure + # that we run the cdist configure after the host + # is up + manager.manage_public_key(keys, + hosts=[new_host], + countdown=75) except Exception as e: logger.error(str(e)) try: