jumpserver/apps/accounts/tasks/remove_account.py

32 lines
988 B
Python
Raw Normal View History

2023-12-06 10:48:35 +00:00
from celery import shared_task
from django.utils.translation import gettext_noop, gettext_lazy as _
from accounts.const import AutomationTypes
from accounts.tasks.common import quickstart_automation_by_snapshot
from common.utils import get_logger
logger = get_logger(__file__)
__all__ = ['remove_accounts_task']
@shared_task(
2023-12-08 08:06:17 +00:00
queue="ansible", verbose_name=_('Remove account'),
2023-12-06 10:48:35 +00:00
activity_callback=lambda self, gather_account_ids, *args, **kwargs: (gather_account_ids, None)
)
def remove_accounts_task(gather_account_ids):
from accounts.models import GatheredAccount
gather_accounts = GatheredAccount.objects.filter(
id__in=gather_account_ids
)
2023-12-08 08:06:17 +00:00
task_name = gettext_noop("Remove account")
2023-12-06 10:48:35 +00:00
task_snapshot = {
'assets': [str(i.asset_id) for i in gather_accounts],
'gather_accounts': [str(i.id) for i in gather_accounts],
}
tp = AutomationTypes.remove_account
quickstart_automation_by_snapshot(task_name, tp, task_snapshot)