|
@@ -89,6 +89,13 @@ class DeviceSerializer(PrimaryModelSerializer):
|
|
|
vc_position = serializers.IntegerField(allow_null=True, max_value=255, min_value=0, default=None)
|
|
vc_position = serializers.IntegerField(allow_null=True, max_value=255, min_value=0, default=None)
|
|
|
config_template = ConfigTemplateSerializer(nested=True, required=False, allow_null=True, default=None)
|
|
config_template = ConfigTemplateSerializer(nested=True, required=False, allow_null=True, default=None)
|
|
|
config_context = serializers.SerializerMethodField(read_only=True)
|
|
config_context = serializers.SerializerMethodField(read_only=True)
|
|
|
|
|
+ replicate_components = serializers.BooleanField(
|
|
|
|
|
+ required=False,
|
|
|
|
|
+ default=True,
|
|
|
|
|
+ write_only=True,
|
|
|
|
|
+ label=_('Replicate components'),
|
|
|
|
|
+ help_text=_('Automatically populate components associated with this device type (default: true)')
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# Counter fields
|
|
# Counter fields
|
|
|
console_port_count = serializers.IntegerField(read_only=True)
|
|
console_port_count = serializers.IntegerField(read_only=True)
|
|
@@ -109,14 +116,19 @@ class DeviceSerializer(PrimaryModelSerializer):
|
|
|
'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'latitude', 'longitude', 'parent_device',
|
|
'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'latitude', 'longitude', 'parent_device',
|
|
|
'status', 'airflow', 'cooling_method', 'primary_ip', 'primary_ip4', 'primary_ip6', 'oob_ip', 'cluster',
|
|
'status', 'airflow', 'cooling_method', 'primary_ip', 'primary_ip4', 'primary_ip6', 'oob_ip', 'cluster',
|
|
|
'virtual_chassis', 'vc_position', 'vc_priority', 'description', 'owner', 'comments', 'config_template',
|
|
'virtual_chassis', 'vc_position', 'vc_priority', 'description', 'owner', 'comments', 'config_template',
|
|
|
- 'config_context',
|
|
|
|
|
- 'local_context_data', 'tags', 'custom_fields', 'created', 'last_updated', 'console_port_count',
|
|
|
|
|
- 'console_server_port_count', 'power_port_count', 'power_outlet_count', 'cooling_intake_count',
|
|
|
|
|
- 'cooling_outflow_count', 'interface_count', 'front_port_count', 'rear_port_count', 'device_bay_count',
|
|
|
|
|
- 'module_bay_count', 'inventory_item_count',
|
|
|
|
|
|
|
+ 'config_context', 'local_context_data', 'tags', 'custom_fields', 'created', 'last_updated',
|
|
|
|
|
+ 'console_port_count', 'console_server_port_count', 'power_port_count', 'power_outlet_count',
|
|
|
|
|
+ 'cooling_intake_count', 'cooling_outflow_count', 'interface_count', 'front_port_count', 'rear_port_count',
|
|
|
|
|
+ 'device_bay_count', 'module_bay_count', 'inventory_item_count', 'replicate_components',
|
|
|
]
|
|
]
|
|
|
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
|
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
|
|
|
|
|
|
|
|
|
+ def validate(self, data):
|
|
|
|
|
+ # replicate_components applies only when creating a new device
|
|
|
|
|
+ if self.instance is not None and not self.nested:
|
|
|
|
|
+ data.pop('replicate_components', None)
|
|
|
|
|
+ return super().validate(data)
|
|
|
|
|
+
|
|
|
@cached_property
|
|
@cached_property
|
|
|
def _parent_device_serializer(self):
|
|
def _parent_device_serializer(self):
|
|
|
return NestedDeviceSerializer(context={'request': self.context['request']})
|
|
return NestedDeviceSerializer(context={'request': self.context['request']})
|