perf: 主机硬件信息 (#9429)

Co-authored-by: feng <1304903146@qq.com>
This commit is contained in:
fit2bot 2023-02-03 18:23:38 +08:00 committed by GitHub
parent 431725b315
commit 20d2efc407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 18 deletions

View File

@ -1,5 +1,5 @@
- hosts: windows - hosts: windows
gather_facts: yes gather_facts: no
tasks: tasks:
- name: Verify account - name: Verify account
ansible.windows.win_ping: ansible.windows.win_ping:

View File

@ -17,15 +17,14 @@ class AccountSerializerCreateValidateMixin:
replace_attrs: callable replace_attrs: callable
def to_internal_value(self, data): def to_internal_value(self, data):
self.id = data.pop('id', None) _id = data.pop('id', None)
ret = super().to_internal_value(data) ret = super().to_internal_value(data)
self.push_now = ret.pop('push_now', False) self.id = _id
self.template = ret.pop('template', False)
return ret return ret
def set_secret(self, attrs): def set_secret(self, attrs):
_id = self.id _id = self.id
template = self.template template = attrs.pop('template', None)
if _id and template: if _id and template:
account_template = AccountTemplate.objects.get(id=_id) account_template = AccountTemplate.objects.get(id=_id)
@ -33,14 +32,16 @@ class AccountSerializerCreateValidateMixin:
elif _id and not template: elif _id and not template:
account = Account.objects.get(id=_id) account = Account.objects.get(id=_id)
attrs['secret'] = account.secret attrs['secret'] = account.secret
return attrs
def validate(self, attrs): def validate(self, attrs):
self.set_secret(attrs) attrs = super().validate(attrs)
return super().validate(attrs) return self.set_secret(attrs)
def create(self, validated_data): def create(self, validated_data):
push_now = validated_data.pop('push_now', None)
instance = super().create(validated_data) instance = super().create(validated_data)
if self.push_now: if push_now:
push_accounts_to_assets.delay([instance.id], [instance.asset_id]) push_accounts_to_assets.delay([instance.id], [instance.asset_id])
return instance return instance

View File

@ -4,16 +4,21 @@
- name: Get info - name: Get info
ansible.builtin.set_fact: ansible.builtin.set_fact:
info: info:
arch: "{{ ansible_architecture }}"
distribution: "{{ ansible_distribution }}"
distribution_version: "{{ ansible_distribution_version }}"
kernel: "{{ ansible_kernel }}"
vendor: "{{ ansible_system_vendor }}" vendor: "{{ ansible_system_vendor }}"
model: "{{ ansible_product_name }}" model: "{{ ansible_product_name }}"
sn: "{{ ansible_product_serial }}" sn: "{{ ansible_product_serial }}"
cpu_model: "{{ ansible_processor }}"
cpu_count: "{{ ansible_processor_count }}"
cpu_cores: "{{ ansible_processor_cores }}"
cpu_vcpus: "{{ ansible_processor_vcpus }}" cpu_vcpus: "{{ ansible_processor_vcpus }}"
memory: "{{ ansible_memtotal_mb }}" memory: "{{ ansible_memtotal_mb }}"
disk_total: "{{ (ansible_mounts | map(attribute='size_total') | sum / 1024 / 1024 / 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 }}"
arch: "{{ ansible_architecture }}"
kernel: "{{ ansible_kernel }}"
- debug: - debug:
var: info var: info

View File

@ -19,13 +19,10 @@ class HostInfoSerializer(serializers.Serializer):
cpu_vcpus = serializers.IntegerField(required=False, label=_('CPU vcpus')) cpu_vcpus = serializers.IntegerField(required=False, label=_('CPU vcpus'))
memory = serializers.CharField(max_length=64, allow_blank=True, required=False, label=_('Memory')) 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')) disk_total = serializers.CharField(max_length=1024, allow_blank=True, required=False, label=_('Disk total'))
disk_info = serializers.CharField(max_length=1024, allow_blank=True, required=False, label=_('Disk info'))
os = serializers.CharField(max_length=128, allow_blank=True, required=False, label=_('OS')) distribution = serializers.CharField(max_length=128, allow_blank=True, required=False, label=_('OS'))
os_version = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS version')) distribution_version = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS version'))
os_arch = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS arch')) arch = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS arch'))
hostname_raw = serializers.CharField(max_length=128, allow_blank=True, required=False, label=_('Hostname raw'))
number = serializers.CharField(max_length=128, allow_blank=True, required=False, label=_('Asset number'))
class HostSerializer(AssetSerializer): class HostSerializer(AssetSerializer):