2022-09-01 06:46:31 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-02-28 10:45:38 +00:00
|
|
|
from rest_framework import serializers
|
2022-09-01 06:46:31 +00:00
|
|
|
|
|
|
|
from assets.models import Host
|
|
|
|
from .common import AssetSerializer
|
|
|
|
|
|
|
|
__all__ = ['HostInfoSerializer', 'HostSerializer']
|
|
|
|
|
|
|
|
|
|
|
|
class HostInfoSerializer(serializers.Serializer):
|
|
|
|
vendor = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Vendor'))
|
2023-02-28 10:45:38 +00:00
|
|
|
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.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'))
|
2022-09-01 06:46:31 +00:00
|
|
|
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'))
|
|
|
|
|
2023-02-03 10:23:38 +00:00
|
|
|
distribution = serializers.CharField(max_length=128, allow_blank=True, required=False, label=_('OS'))
|
2023-02-28 10:45:38 +00:00
|
|
|
distribution_version = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS version'))
|
2023-02-03 10:23:38 +00:00
|
|
|
arch = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS arch'))
|
2022-09-01 06:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HostSerializer(AssetSerializer):
|
2023-02-23 11:14:58 +00:00
|
|
|
info = HostInfoSerializer(required=False, label=_('Info'))
|
2022-09-01 06:46:31 +00:00
|
|
|
|
|
|
|
class Meta(AssetSerializer.Meta):
|
|
|
|
model = Host
|
|
|
|
fields = AssetSerializer.Meta.fields + ['info']
|
2022-10-19 10:56:46 +00:00
|
|
|
extra_kwargs = {
|
|
|
|
**AssetSerializer.Meta.extra_kwargs,
|
|
|
|
'address': {
|
|
|
|
'label': _("IP/Host")
|
|
|
|
},
|
|
|
|
}
|