From 0f777e66d83ac6f9d7f87547f970958c832409a9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 6 May 2019 08:08:51 +0200 Subject: [PATCH] Add entry to DeletedUser + fix code to delete user from opennebula --- .../management/commands/deleteuser.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/datacenterlight/management/commands/deleteuser.py b/datacenterlight/management/commands/deleteuser.py index a1ab1e94..e3be76f1 100644 --- a/datacenterlight/management/commands/deleteuser.py +++ b/datacenterlight/management/commands/deleteuser.py @@ -4,7 +4,7 @@ import sys import stripe from django.core.management.base import BaseCommand -from membership.models import CustomUser +from membership.models import CustomUser, DeletedUser from hosting.models import ( HostingOrder, HostingBill, VMDetail, UserCardDetail, UserHostingKey ) @@ -124,14 +124,32 @@ class Command(BaseCommand): # delete stripe customer stripe_customer.delete() + # add user to deleteduser + DeletedUser.objects.create( + email=cus_user.email, name=cus_user.name, + user_id = cus_user.id + ) + # delete CustomUser cus_user.delete() # remove user from OpenNebula manager = OpenNebulaManager() - manager.oneadmin_client.call( - oca.User.METHODS['delete'], email - ) + user_pool = manager._get_user_pool() + on_user = user_pool.get_by_name(email) + if on_user.id > 0: + logger.debug( + "Deleting user {} => ID={} from opennebula".format( + email, on_user.id) + ) + manager.oneadmin_client.call( + oca.User.METHODS['delete'], on_user.id + ) + else: + logger.error( + "User not found with email {}. " + "Not doing anything".format(email) + ) logger.debug("Deleted {} SUCCESSFULLY.".format(email)) except Exception as e: