Add entry to DeletedUser + fix code to delete user from opennebula
This commit is contained in:
parent
c40331fcc1
commit
0f777e66d8
1 changed files with 22 additions and 4 deletions
|
@ -4,7 +4,7 @@ import sys
|
||||||
import stripe
|
import stripe
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from membership.models import CustomUser
|
from membership.models import CustomUser, DeletedUser
|
||||||
from hosting.models import (
|
from hosting.models import (
|
||||||
HostingOrder, HostingBill, VMDetail, UserCardDetail, UserHostingKey
|
HostingOrder, HostingBill, VMDetail, UserCardDetail, UserHostingKey
|
||||||
)
|
)
|
||||||
|
@ -124,13 +124,31 @@ class Command(BaseCommand):
|
||||||
# delete stripe customer
|
# delete stripe customer
|
||||||
stripe_customer.delete()
|
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
|
# delete CustomUser
|
||||||
cus_user.delete()
|
cus_user.delete()
|
||||||
|
|
||||||
# remove user from OpenNebula
|
# remove user from OpenNebula
|
||||||
manager = OpenNebulaManager()
|
manager = OpenNebulaManager()
|
||||||
|
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(
|
manager.oneadmin_client.call(
|
||||||
oca.User.METHODS['delete'], email
|
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))
|
logger.debug("Deleted {} SUCCESSFULLY.".format(email))
|
||||||
|
|
Loading…
Reference in a new issue