From 38a8997e29d7e9789a2fe17264c8d456d24b9f3d Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 10 Sep 2017 15:26:29 +0530 Subject: [PATCH] Refactored code --- datacenterlight/tasks.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/datacenterlight/tasks.py b/datacenterlight/tasks.py index 1d9af626..943e4139 100644 --- a/datacenterlight/tasks.py +++ b/datacenterlight/tasks.py @@ -53,22 +53,24 @@ def create_vm_task(self, vm_template_id, user, specs, template, billing_address = BillingAddress.objects.filter( id=billing_address_id).first() customer = StripeCustomer.objects.filter(id=stripe_customer_id).first() - # Create OpenNebulaManager + if 'pass' in user: - manager = OpenNebulaManager(email=user.get('email'), - password=user.get('pass')) - logger.debug("Using user {user} to create VM".format( - user=user.get('email'))) + on_user = user.get('email') + on_pass = user.get('pass') + logger.debug("Using user {user} to create VM".format(user=on_user)) vm_name = None else: - manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME, - password=settings.OPENNEBULA_PASSWORD) + on_user = settings.OPENNEBULA_USERNAME + on_pass = settings.OPENNEBULA_PASSWORD logger.debug("Using OpenNebula admin user to create VM") vm_name = "{email}-{template_name}-{date}".format( email=user.get('email'), template_name=template.get('name'), date=int(datetime.now().strftime("%s"))) + # Create OpenNebulaManager + manager = OpenNebulaManager(email=on_user, password=on_pass) + vm_id = manager.create_vm( template_id=vm_template_id, specs=specs,