mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
2 years ago
|
from celery import shared_task
|
||
|
from django.utils.translation import gettext_noop
|
||
2 years ago
|
from django.utils.translation import ugettext as _
|
||
2 years ago
|
|
||
|
from common.utils import get_logger
|
||
2 years ago
|
from accounts.tasks.common import automation_execute_start
|
||
|
from accounts.const import AutomationTypes
|
||
|
from orgs.utils import org_aware_func
|
||
2 years ago
|
|
||
|
logger = get_logger(__name__)
|
||
|
__all__ = [
|
||
|
'verify_accounts_connectivity'
|
||
|
]
|
||
|
|
||
|
|
||
|
@org_aware_func("assets")
|
||
|
def verify_accounts_connectivity_util(accounts, assets, task_name):
|
||
2 years ago
|
from accounts.models import VerifyAccountAutomation
|
||
2 years ago
|
task_name = VerifyAccountAutomation.generate_unique_name(task_name)
|
||
|
account_usernames = list(accounts.values_list('username', flat=True))
|
||
|
|
||
2 years ago
|
child_snapshot = {
|
||
2 years ago
|
'accounts': account_usernames,
|
||
2 years ago
|
'assets': [str(asset.id) for asset in assets],
|
||
2 years ago
|
}
|
||
2 years ago
|
tp = AutomationTypes.verify_account
|
||
|
automation_execute_start(task_name, tp, child_snapshot)
|
||
2 years ago
|
|
||
|
|
||
2 years ago
|
@shared_task(queue="ansible", verbose_name=_('Verify asset account availability'))
|
||
2 years ago
|
def verify_accounts_connectivity(account_ids, asset_ids):
|
||
2 years ago
|
from assets.models import Asset
|
||
|
from accounts.models import Account
|
||
|
assets = Asset.objects.filter(id__in=asset_ids)
|
||
|
accounts = Account.objects.filter(id__in=account_ids)
|
||
2 years ago
|
task_name = gettext_noop("Verify accounts connectivity")
|
||
|
return verify_accounts_connectivity_util(accounts, assets, task_name)
|