mirror of https://github.com/jumpserver/jumpserver
parent
410668c209
commit
797c7635a7
|
@ -60,4 +60,6 @@ class GatherAccountsFilter:
|
|||
if not run_method_name:
|
||||
return info
|
||||
|
||||
if hasattr(self, f'{run_method_name}_filter'):
|
||||
return getattr(self, f'{run_method_name}_filter')(info)
|
||||
return info
|
||||
|
|
|
@ -22,8 +22,8 @@ class GatherAccountsManager(AccountBasePlaybookManager):
|
|||
self.host_asset_mapper[host['name']] = asset
|
||||
return host
|
||||
|
||||
def filter_success_result(self, host, result):
|
||||
result = GatherAccountsFilter(host).run(self.method_id_meta_mapper, result)
|
||||
def filter_success_result(self, tp, result):
|
||||
result = GatherAccountsFilter(tp).run(self.method_id_meta_mapper, result)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
__all__ = ['FormatAssetInfo']
|
||||
|
||||
|
||||
class FormatAssetInfo:
|
||||
|
||||
def __init__(self, tp):
|
||||
self.tp = tp
|
||||
|
||||
@staticmethod
|
||||
def posix_format(info):
|
||||
for cpu_model in info.get('cpu_model', []):
|
||||
if cpu_model.endswith('GHz') or cpu_model.startswith("Intel"):
|
||||
break
|
||||
else:
|
||||
cpu_model = ''
|
||||
info['cpu_model'] = cpu_model[:48]
|
||||
info['cpu_count'] = info.get('cpu_count', 0)
|
||||
return info
|
||||
|
||||
def run(self, method_id_meta_mapper, info):
|
||||
for k, v in info.items():
|
||||
info[k] = v.strip() if isinstance(v, str) else v
|
||||
|
||||
run_method_name = None
|
||||
for k, v in method_id_meta_mapper.items():
|
||||
if self.tp not in v['type']:
|
||||
continue
|
||||
run_method_name = k.replace(f'{v["method"]}_', '')
|
||||
|
||||
if not run_method_name:
|
||||
return info
|
||||
|
||||
if hasattr(self, f'{run_method_name}_format'):
|
||||
return getattr(self, f'{run_method_name}_format')(info)
|
||||
return info
|
|
@ -11,7 +11,7 @@
|
|||
cpu_count: "{{ ansible_processor_count }}"
|
||||
cpu_cores: "{{ ansible_processor_cores }}"
|
||||
cpu_vcpus: "{{ ansible_processor_vcpus }}"
|
||||
memory: "{{ ansible_memtotal_mb }}"
|
||||
memory: "{{ ansible_memtotal_mb / 1024 | round(2) }}"
|
||||
disk_total: "{{ (ansible_mounts | map(attribute='size_total') | sum / 1024 / 1024 / 1024) | round(2) }}"
|
||||
distribution: "{{ ansible_distribution }}"
|
||||
distribution_version: "{{ ansible_distribution_version }}"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from common.utils import get_logger
|
||||
from assets.const import AutomationTypes
|
||||
from common.utils import get_logger
|
||||
from .format_asset_info import FormatAssetInfo
|
||||
from ..base.manager import BasePlaybookManager
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
@ -19,12 +20,15 @@ class GatherFactsManager(BasePlaybookManager):
|
|||
self.host_asset_mapper[host['name']] = asset
|
||||
return host
|
||||
|
||||
def format_asset_info(self, tp, info):
|
||||
info = FormatAssetInfo(tp).run(self.method_id_meta_mapper, info)
|
||||
return info
|
||||
|
||||
def on_host_success(self, host, result):
|
||||
info = result.get('debug', {}).get('res', {}).get('info', {})
|
||||
asset = self.host_asset_mapper.get(host)
|
||||
if asset and info:
|
||||
for k, v in info.items():
|
||||
info[k] = v.strip() if isinstance(v, str) else v
|
||||
info = self.format_asset_info(asset.type, info)
|
||||
asset.info = info
|
||||
asset.save()
|
||||
else:
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from rest_framework import serializers
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from assets.models import Host
|
||||
from .common import AssetSerializer
|
||||
|
||||
|
||||
__all__ = ['HostInfoSerializer', 'HostSerializer']
|
||||
|
||||
|
||||
|
@ -12,10 +11,10 @@ class HostInfoSerializer(serializers.Serializer):
|
|||
vendor = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Vendor'))
|
||||
model = serializers.CharField(max_length=54, required=False, allow_blank=True, label=_('Model'))
|
||||
sn = serializers.CharField(max_length=128, required=False, allow_blank=True, label=_('Serial number'))
|
||||
cpu_model = serializers.ListField(child=serializers.CharField(max_length=64, allow_blank=True), required=False, label=_('CPU model'))
|
||||
cpu_count = serializers.IntegerField(required=False, label=_('CPU count'))
|
||||
cpu_cores = serializers.IntegerField(required=False, label=_('CPU cores'))
|
||||
cpu_vcpus = serializers.IntegerField(required=False, label=_('CPU vcpus'))
|
||||
cpu_model = serializers.CharField(max_length=64, allow_blank=True, required=False, label=_('CPU model'))
|
||||
cpu_count = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU count'))
|
||||
cpu_cores = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU cores'))
|
||||
cpu_vcpus = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU vcpus'))
|
||||
memory = serializers.CharField(max_length=64, allow_blank=True, required=False, label=_('Memory'))
|
||||
disk_total = serializers.CharField(max_length=1024, allow_blank=True, required=False, label=_('Disk total'))
|
||||
|
||||
|
@ -36,5 +35,3 @@ class HostSerializer(AssetSerializer):
|
|||
'label': _("IP/Host")
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue