mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-10-21 15:58:52 +00:00
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
from celery import shared_task
|
|
from django.utils.translation import gettext_noop
|
|
|
|
from common.utils import get_logger
|
|
from orgs.utils import org_aware_func, tmp_to_root_org
|
|
|
|
logger = get_logger(__file__)
|
|
__all__ = [
|
|
'update_assets_hardware_info_util',
|
|
'update_node_assets_hardware_info_manual',
|
|
'update_assets_hardware_info_manual',
|
|
]
|
|
|
|
|
|
@org_aware_func('assets')
|
|
def update_assets_hardware_info_util(assets, task_name=None):
|
|
from assets.models import GatherFactsAutomation
|
|
if task_name is None:
|
|
task_name = gettext_noop("Update some assets hardware info. ")
|
|
|
|
task_name = GatherFactsAutomation.generate_unique_name(task_name)
|
|
data = {
|
|
'name': task_name,
|
|
'comment': ', '.join([str(i) for i in assets])
|
|
}
|
|
instance = GatherFactsAutomation.objects.create(**data)
|
|
instance.assets.add(*assets)
|
|
instance.execute()
|
|
|
|
|
|
@shared_task(queue="ansible")
|
|
def update_assets_hardware_info_manual(asset_ids):
|
|
from assets.models import Asset
|
|
with tmp_to_root_org():
|
|
assets = Asset.objects.filter(id__in=asset_ids)
|
|
task_name = gettext_noop("Update assets hardware info: ")
|
|
update_assets_hardware_info_util(assets, task_name=task_name)
|
|
|
|
|
|
@shared_task(queue="ansible")
|
|
def update_node_assets_hardware_info_manual(node_id):
|
|
from assets.models import Node
|
|
with tmp_to_root_org():
|
|
node = Node.objects.get(id=node_id)
|
|
|
|
task_name = gettext_noop("Update node asset hardware information: ")
|
|
assets = node.get_all_assets()
|
|
update_assets_hardware_info_util(assets, task_name=task_name)
|