2022-04-30 15:19:43 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2022-08-24 08:14:32 +00:00
|
|
|
from assets.models import DeviceInfo, Host, Database, Networking, Cloud
|
2022-04-30 15:19:43 +00:00
|
|
|
from .common import AssetSerializer
|
|
|
|
|
|
|
|
__all__ = [
|
2022-08-23 02:23:48 +00:00
|
|
|
'DeviceSerializer', 'HostSerializer', 'DatabaseSerializer',
|
2022-08-24 08:14:32 +00:00
|
|
|
'NetworkingSerializer', 'CloudSerializer',
|
2022-04-30 15:19:43 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = DeviceInfo
|
|
|
|
fields = [
|
|
|
|
'id', 'vendor', 'model', 'sn', 'cpu_model', 'cpu_count',
|
|
|
|
'cpu_cores', 'cpu_vcpus', 'memory', 'disk_total', 'disk_info',
|
2022-08-11 07:45:03 +00:00
|
|
|
'os', 'os_version', 'os_arch', 'hostname_raw', 'number',
|
2022-04-30 15:19:43 +00:00
|
|
|
'cpu_info', 'hardware_info', 'date_updated'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class HostSerializer(AssetSerializer):
|
|
|
|
device_info = DeviceSerializer(read_only=True, allow_null=True)
|
|
|
|
|
|
|
|
class Meta(AssetSerializer.Meta):
|
|
|
|
model = Host
|
|
|
|
fields = AssetSerializer.Meta.fields + ['device_info']
|
|
|
|
|
|
|
|
|
|
|
|
class DatabaseSerializer(AssetSerializer):
|
|
|
|
class Meta(AssetSerializer.Meta):
|
|
|
|
model = Database
|
2022-08-23 02:23:48 +00:00
|
|
|
fields = AssetSerializer.Meta.fields + ['db_name']
|
|
|
|
|
|
|
|
|
2022-08-24 08:14:32 +00:00
|
|
|
class NetworkingSerializer(AssetSerializer):
|
2022-08-23 02:23:48 +00:00
|
|
|
class Meta(AssetSerializer.Meta):
|
2022-08-24 08:14:32 +00:00
|
|
|
model = Networking
|
2022-08-23 02:23:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CloudSerializer(AssetSerializer):
|
|
|
|
class Meta(AssetSerializer.Meta):
|
|
|
|
model = Cloud
|
2022-08-29 07:50:25 +00:00
|
|
|
fields = AssetSerializer.Meta.fields + ['cluster']
|