Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #15235: Use primary serializers for REST API "brief" mode #15246

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions netbox/circuits/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'accounts', 'description', 'comments', 'asns', 'tags',
'custom_fields', 'created', 'last_updated', 'circuit_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'circuit_count')


#
Expand All @@ -56,6 +57,7 @@ class Meta:
'id', 'url', 'display', 'provider', 'name', 'account', 'description', 'comments', 'tags', 'custom_fields',
'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name', 'account')


#
Expand All @@ -72,6 +74,7 @@ class Meta:
'id', 'url', 'display', 'provider', 'name', 'service_id', 'description', 'comments', 'tags',
'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


#
Expand All @@ -90,6 +93,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'color', 'description', 'tags', 'custom_fields', 'created',
'last_updated', 'circuit_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'circuit_count')


class CircuitCircuitTerminationSerializer(WritableNestedSerializer):
Expand Down Expand Up @@ -122,6 +126,7 @@ class Meta:
'termination_date', 'commit_rate', 'description', 'termination_a', 'termination_z', 'comments', 'tags',
'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'cid')


class CircuitTerminationSerializer(NetBoxModelSerializer, CabledObjectSerializer):
Expand All @@ -137,3 +142,4 @@ class Meta:
'xconnect_id', 'pp_info', 'description', 'mark_connected', 'cable', 'cable_end', 'link_peers',
'link_peers_type', 'tags', 'custom_fields', 'created', 'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'circuit', 'term_side', 'cable', '_occupied')
3 changes: 3 additions & 0 deletions netbox/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Meta:
'id', 'url', 'display', 'name', 'type', 'source_url', 'enabled', 'status', 'description', 'comments',
'parameters', 'ignore_rules', 'custom_fields', 'created', 'last_updated', 'file_count',
]
brief_fields = ('id', 'url', 'display', 'name')


class DataFileSerializer(NetBoxModelSerializer):
Expand All @@ -51,6 +52,7 @@ class Meta:
fields = [
'id', 'url', 'display', 'source', 'path', 'last_updated', 'size', 'hash',
]
brief_fields = ('id', 'url', 'display', 'path')


class JobSerializer(BaseModelSerializer):
Expand All @@ -69,3 +71,4 @@ class Meta:
'id', 'url', 'display', 'object_type', 'object_id', 'name', 'status', 'created', 'scheduled', 'interval',
'started', 'completed', 'user', 'data', 'error', 'job_id',
]
brief_fields = ('url', 'created', 'completed', 'user', 'status')
43 changes: 41 additions & 2 deletions netbox/dcim/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',
'last_updated', 'site_count', '_depth',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'site_count', '_depth')


class SiteGroupSerializer(NestedGroupModelSerializer):
Expand All @@ -127,6 +128,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',
'last_updated', 'site_count', '_depth',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'site_count', '_depth')


class SiteSerializer(NetBoxModelSerializer):
Expand Down Expand Up @@ -159,6 +161,7 @@ class Meta:
'custom_fields', 'created', 'last_updated', 'circuit_count', 'device_count', 'prefix_count', 'rack_count',
'virtualmachine_count', 'vlan_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug')


#
Expand All @@ -180,6 +183,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'site', 'parent', 'status', 'tenant', 'description', 'tags',
'custom_fields', 'created', 'last_updated', 'rack_count', 'device_count', '_depth',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'rack_count', '_depth')


class RackRoleSerializer(NetBoxModelSerializer):
Expand All @@ -194,6 +198,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'color', 'description', 'tags', 'custom_fields', 'created',
'last_updated', 'rack_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'rack_count')


class RackSerializer(NetBoxModelSerializer):
Expand Down Expand Up @@ -222,6 +227,7 @@ class Meta:
'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'description', 'comments',
'tags', 'custom_fields', 'created', 'last_updated', 'device_count', 'powerfeed_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'device_count')


class RackUnitSerializer(serializers.Serializer):
Expand Down Expand Up @@ -256,6 +262,7 @@ class Meta:
'id', 'url', 'display', 'rack', 'units', 'created', 'last_updated', 'user', 'tenant', 'description',
'comments', 'tags', 'custom_fields',
]
brief_fields = ('id', 'url', 'display', 'user', 'units')


class RackElevationDetailFilterSerializer(serializers.Serializer):
Expand Down Expand Up @@ -315,6 +322,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'description', 'tags', 'custom_fields', 'created', 'last_updated',
'devicetype_count', 'inventoryitem_count', 'platform_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'devicetype_count')


class DeviceTypeSerializer(NetBoxModelSerializer):
Expand Down Expand Up @@ -360,6 +368,7 @@ class Meta:
'rear_port_template_count', 'device_bay_template_count', 'module_bay_template_count',
'inventory_item_template_count',
]
brief_fields = ('id', 'url', 'display', 'manufacturer', 'model', 'slug', 'device_count')


class ModuleTypeSerializer(NetBoxModelSerializer):
Expand All @@ -373,6 +382,7 @@ class Meta:
'id', 'url', 'display', 'manufacturer', 'model', 'part_number', 'weight', 'weight_unit', 'description',
'comments', 'tags', 'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'manufacturer', 'model')


#
Expand Down Expand Up @@ -403,6 +413,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type', 'description', 'created',
'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class ConsoleServerPortTemplateSerializer(ValidatedModelSerializer):
Expand All @@ -429,6 +440,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type', 'description', 'created',
'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class PowerPortTemplateSerializer(ValidatedModelSerializer):
Expand Down Expand Up @@ -456,6 +468,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type', 'maximum_draw',
'allocated_draw', 'description', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class PowerOutletTemplateSerializer(ValidatedModelSerializer):
Expand Down Expand Up @@ -493,6 +506,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type', 'power_port', 'feed_leg',
'description', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class InterfaceTemplateSerializer(ValidatedModelSerializer):
Expand Down Expand Up @@ -537,6 +551,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type', 'enabled', 'mgmt_only',
'description', 'bridge', 'poe_mode', 'poe_type', 'rf_role', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class RearPortTemplateSerializer(ValidatedModelSerializer):
Expand All @@ -559,6 +574,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type', 'color', 'positions',
'description', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class FrontPortTemplateSerializer(ValidatedModelSerializer):
Expand All @@ -582,6 +598,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type', 'color', 'rear_port',
'rear_port_position', 'description', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class ModuleBayTemplateSerializer(ValidatedModelSerializer):
Expand All @@ -594,6 +611,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'name', 'label', 'position', 'description', 'created',
'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name')


class DeviceBayTemplateSerializer(ValidatedModelSerializer):
Expand All @@ -603,6 +621,7 @@ class DeviceBayTemplateSerializer(ValidatedModelSerializer):
class Meta:
model = DeviceBayTemplate
fields = ['id', 'url', 'display', 'device_type', 'name', 'label', 'description', 'created', 'last_updated']
brief_fields = ('id', 'url', 'display', 'name')


class InventoryItemTemplateSerializer(ValidatedModelSerializer):
Expand All @@ -629,6 +648,7 @@ class Meta:
'id', 'url', 'display', 'device_type', 'parent', 'name', 'label', 'role', 'manufacturer', 'part_id',
'description', 'component_type', 'component_id', 'component', 'created', 'last_updated', '_depth',
]
brief_fields = ('id', 'url', 'display', 'name', '_depth')

@extend_schema_field(serializers.JSONField(allow_null=True))
def get_component(self, obj):
Expand Down Expand Up @@ -657,6 +677,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'color', 'vm_role', 'config_template', 'description', 'tags',
'custom_fields', 'created', 'last_updated', 'device_count', 'virtualmachine_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'device_count', 'virtualmachine_count')


class PlatformSerializer(NetBoxModelSerializer):
Expand All @@ -674,6 +695,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'manufacturer', 'config_template', 'description', 'tags',
'custom_fields', 'created', 'last_updated', 'device_count', 'virtualmachine_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'device_count', 'virtualmachine_count')


class DeviceSerializer(NetBoxModelSerializer):
Expand Down Expand Up @@ -730,6 +752,7 @@ class Meta:
'power_port_count', 'power_outlet_count', 'interface_count', 'front_port_count', 'rear_port_count',
'device_bay_count', 'module_bay_count', 'inventory_item_count',
]
brief_fields = ('id', 'url', 'display', 'name')

@extend_schema_field(NestedDeviceSerializer)
def get_parent_device(self, obj):
Expand Down Expand Up @@ -784,6 +807,7 @@ class Meta:
'primary_ip6', 'status', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
'interface_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'identifier', 'device')


class ModuleSerializer(NetBoxModelSerializer):
Expand All @@ -799,6 +823,7 @@ class Meta:
'id', 'url', 'display', 'device', 'module_bay', 'module_type', 'status', 'serial', 'asset_tag',
'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'device', 'module_bay', 'module_type')


#
Expand Down Expand Up @@ -831,6 +856,7 @@ class Meta:
'connected_endpoints_type', 'connected_endpoints_reachable', 'tags', 'custom_fields', 'created',
'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'cable', '_occupied')


class ConsolePortSerializer(NetBoxModelSerializer, CabledObjectSerializer, ConnectedEndpointsSerializer):
Expand Down Expand Up @@ -859,6 +885,7 @@ class Meta:
'connected_endpoints_type', 'connected_endpoints_reachable', 'tags', 'custom_fields', 'created',
'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'cable', '_occupied')


class PowerOutletSerializer(NetBoxModelSerializer, CabledObjectSerializer, ConnectedEndpointsSerializer):
Expand Down Expand Up @@ -893,6 +920,7 @@ class Meta:
'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable', 'tags', 'custom_fields',
'created', 'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'cable', '_occupied')


class PowerPortSerializer(NetBoxModelSerializer, CabledObjectSerializer, ConnectedEndpointsSerializer):
Expand All @@ -917,6 +945,7 @@ class Meta:
'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable', 'tags', 'custom_fields',
'created', 'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'cable', '_occupied')


class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, ConnectedEndpointsSerializer):
Expand Down Expand Up @@ -979,6 +1008,7 @@ class Meta:
'connected_endpoints_type', 'connected_endpoints_reachable', 'tags', 'custom_fields', 'created',
'last_updated', 'count_ipaddresses', 'count_fhrp_groups', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'cable', '_occupied')

def validate(self, data):

Expand Down Expand Up @@ -1010,6 +1040,7 @@ class Meta:
'mark_connected', 'cable', 'cable_end', 'link_peers', 'link_peers_type', 'tags', 'custom_fields', 'created',
'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'cable', '_occupied')


class FrontPortRearPortSerializer(WritableNestedSerializer):
Expand Down Expand Up @@ -1040,6 +1071,7 @@ class Meta:
'rear_port_position', 'description', 'mark_connected', 'cable', 'cable_end', 'link_peers',
'link_peers_type', 'tags', 'custom_fields', 'created', 'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'cable', '_occupied')


class ModuleBaySerializer(NetBoxModelSerializer):
Expand All @@ -1051,9 +1083,9 @@ class Meta:
model = ModuleBay
fields = [
'id', 'url', 'display', 'device', 'name', 'installed_module', 'label', 'position', 'description', 'tags',
'custom_fields',
'created', 'last_updated',
'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'installed_module', 'name')


class DeviceBaySerializer(NetBoxModelSerializer):
Expand All @@ -1067,6 +1099,7 @@ class Meta:
'id', 'url', 'display', 'device', 'name', 'label', 'description', 'installed_device', 'tags',
'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'device', 'name')


class InventoryItemSerializer(NetBoxModelSerializer):
Expand All @@ -1090,6 +1123,7 @@ class Meta:
'asset_tag', 'discovered', 'description', 'component_type', 'component_id', 'component', 'tags',
'custom_fields', 'created', 'last_updated', '_depth',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', '_depth')

@extend_schema_field(serializers.JSONField(allow_null=True))
def get_component(self, obj):
Expand All @@ -1116,6 +1150,7 @@ class Meta:
'id', 'url', 'display', 'name', 'slug', 'color', 'description', 'tags', 'custom_fields', 'created',
'last_updated', 'inventoryitem_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'inventoryitem_count')


#
Expand All @@ -1136,6 +1171,7 @@ class Meta:
'id', 'url', 'display', 'type', 'a_terminations', 'b_terminations', 'status', 'tenant', 'label', 'color',
'length', 'length_unit', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'label')


class TracedCableSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -1206,6 +1242,7 @@ class Meta:
'id', 'url', 'display', 'name', 'domain', 'master', 'description', 'comments', 'tags', 'custom_fields',
'created', 'last_updated', 'member_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'master', 'member_count')


#
Expand All @@ -1230,6 +1267,7 @@ class Meta:
'id', 'url', 'display', 'site', 'location', 'name', 'description', 'comments', 'tags', 'custom_fields',
'powerfeed_count', 'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name', 'powerfeed_count')


class PowerFeedSerializer(NetBoxModelSerializer, CabledObjectSerializer, ConnectedEndpointsSerializer):
Expand Down Expand Up @@ -1269,3 +1307,4 @@ class Meta:
'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable', 'description',
'tenant', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'name', 'cable', '_occupied')
2 changes: 1 addition & 1 deletion netbox/dcim/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ def setUpTestData(cls):

class ModuleBayTest(APIViewTestCases.APIViewTestCase):
model = ModuleBay
brief_fields = ['display', 'id', 'module', 'name', 'url']
brief_fields = ['display', 'id', 'installed_module', 'name', 'url']
bulk_update_data = {
'description': 'New description',
}
Expand Down
Loading
Loading