mirror of https://github.com/jumpserver/jumpserver
parent
2705c38ba1
commit
1cc983b2eb
|
@ -82,10 +82,11 @@ class AssetsTaskMixin:
|
||||||
def perform_assets_task(self, serializer):
|
def perform_assets_task(self, serializer):
|
||||||
data = serializer.validated_data
|
data = serializer.validated_data
|
||||||
assets = data.get('assets', [])
|
assets = data.get('assets', [])
|
||||||
|
asset_ids = [asset.id for asset in assets]
|
||||||
if data['action'] == "refresh":
|
if data['action'] == "refresh":
|
||||||
task = update_assets_hardware_info_manual.delay(assets)
|
task = update_assets_hardware_info_manual.delay(asset_ids)
|
||||||
else:
|
else:
|
||||||
task = test_assets_connectivity_manual.delay(assets)
|
task = test_assets_connectivity_manual.delay(asset_ids)
|
||||||
return task
|
return task
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
|
|
|
@ -221,6 +221,7 @@ class BasePlaybookManager:
|
||||||
else:
|
else:
|
||||||
print(">>> 开始执行任务\n")
|
print(">>> 开始执行任务\n")
|
||||||
|
|
||||||
|
self.execution.date_start = timezone.now()
|
||||||
for i, runner in enumerate(runners, start=1):
|
for i, runner in enumerate(runners, start=1):
|
||||||
if len(runners) > 1:
|
if len(runners) > 1:
|
||||||
print(">>> 开始执行第 {} 批任务".format(i))
|
print(">>> 开始执行第 {} 批任务".format(i))
|
||||||
|
@ -231,3 +232,5 @@ class BasePlaybookManager:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.on_runner_failed(runner, e)
|
self.on_runner_failed(runner, e)
|
||||||
print('\n')
|
print('\n')
|
||||||
|
self.execution.date_finished = timezone.now()
|
||||||
|
self.execution.save()
|
||||||
|
|
|
@ -4,16 +4,18 @@ from .gather_accounts.manager import GatherAccountsManager
|
||||||
from .verify_account.manager import VerifyAccountManager
|
from .verify_account.manager import VerifyAccountManager
|
||||||
from .push_account.manager import PushAccountManager
|
from .push_account.manager import PushAccountManager
|
||||||
from .backup_account.manager import AccountBackupManager
|
from .backup_account.manager import AccountBackupManager
|
||||||
|
from .ping.manager import PingManager
|
||||||
from ..const import AutomationTypes
|
from ..const import AutomationTypes
|
||||||
|
|
||||||
|
|
||||||
class ExecutionManager:
|
class ExecutionManager:
|
||||||
manager_type_mapper = {
|
manager_type_mapper = {
|
||||||
AutomationTypes.change_secret: ChangeSecretManager,
|
AutomationTypes.ping: PingManager,
|
||||||
AutomationTypes.gather_facts: GatherFactsManager,
|
|
||||||
AutomationTypes.gather_accounts: GatherAccountsManager,
|
|
||||||
AutomationTypes.verify_account: VerifyAccountManager,
|
|
||||||
AutomationTypes.push_account: PushAccountManager,
|
AutomationTypes.push_account: PushAccountManager,
|
||||||
|
AutomationTypes.gather_facts: GatherFactsManager,
|
||||||
|
AutomationTypes.change_secret: ChangeSecretManager,
|
||||||
|
AutomationTypes.verify_account: VerifyAccountManager,
|
||||||
|
AutomationTypes.gather_accounts: GatherAccountsManager,
|
||||||
# TODO 后期迁移到自动化策略中
|
# TODO 后期迁移到自动化策略中
|
||||||
'backup_account': AccountBackupManager,
|
'backup_account': AccountBackupManager,
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ class AssetSerializer(OrgResourceSerializerMixin, WritableNestedModelSerializer)
|
||||||
'nodes', 'labels', 'protocols', 'accounts', 'nodes_display',
|
'nodes', 'labels', 'protocols', 'accounts', 'nodes_display',
|
||||||
]
|
]
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
'category', 'type', 'specific',
|
'category', 'type', 'specific', 'info',
|
||||||
'connectivity', 'date_verified',
|
'connectivity', 'date_verified',
|
||||||
'created_by', 'date_created',
|
'created_by', 'date_created',
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,3 +9,4 @@ from .gather_facts import *
|
||||||
from .nodes_amount import *
|
from .nodes_amount import *
|
||||||
from .push_account import *
|
from .push_account import *
|
||||||
from .verify_account import *
|
from .verify_account import *
|
||||||
|
from .gather_accounts import *
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# ~*~ coding: utf-8 ~*~
|
||||||
|
from celery import shared_task
|
||||||
|
from django.utils.translation import gettext_noop
|
||||||
|
|
||||||
|
from orgs.utils import tmp_to_root_org, org_aware_func
|
||||||
|
from common.utils import get_logger
|
||||||
|
from assets.models import Node
|
||||||
|
|
||||||
|
__all__ = ['gather_asset_accounts']
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@org_aware_func("nodes")
|
||||||
|
def gather_asset_accounts_util(nodes, task_name):
|
||||||
|
from assets.models import GatherAccountsAutomation
|
||||||
|
task_name = GatherAccountsAutomation.generate_unique_name(task_name)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'name': task_name,
|
||||||
|
'comment': ', '.join([str(i) for i in nodes])
|
||||||
|
}
|
||||||
|
instance = GatherAccountsAutomation.objects.create(**data)
|
||||||
|
instance.nodes.add(*nodes)
|
||||||
|
instance.execute()
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task(queue="ansible")
|
||||||
|
def gather_asset_accounts(node_ids, task_name=None):
|
||||||
|
if task_name is None:
|
||||||
|
task_name = gettext_noop("Gather assets accounts")
|
||||||
|
|
||||||
|
with tmp_to_root_org():
|
||||||
|
nodes = Node.objects.filter(id__in=node_ids)
|
||||||
|
gather_asset_accounts_util(nodes=nodes, task_name=task_name)
|
Loading…
Reference in New Issue