mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 08:38:16 -06:00
Create base classes for Rack & RackType models, serializers
This commit is contained in:
parent
32c5994462
commit
5811f9ecad
@ -35,10 +35,7 @@ class RackRoleSerializer(NetBoxModelSerializer):
|
|||||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'rack_count')
|
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'rack_count')
|
||||||
|
|
||||||
|
|
||||||
class RackTypeSerializer(NetBoxModelSerializer):
|
class RackBaseSerializer(NetBoxModelSerializer):
|
||||||
manufacturer = ManufacturerSerializer(
|
|
||||||
nested=True
|
|
||||||
)
|
|
||||||
form_factor = ChoiceField(
|
form_factor = ChoiceField(
|
||||||
choices=RackFormFactorChoices,
|
choices=RackFormFactorChoices,
|
||||||
allow_blank=True,
|
allow_blank=True,
|
||||||
@ -62,6 +59,12 @@ class RackTypeSerializer(NetBoxModelSerializer):
|
|||||||
allow_null=True
|
allow_null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RackTypeSerializer(RackBaseSerializer):
|
||||||
|
manufacturer = ManufacturerSerializer(
|
||||||
|
nested=True
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = RackType
|
model = RackType
|
||||||
fields = [
|
fields = [
|
||||||
@ -73,19 +76,43 @@ class RackTypeSerializer(NetBoxModelSerializer):
|
|||||||
brief_fields = ('id', 'url', 'display', 'manufacturer', 'name', 'slug', 'description')
|
brief_fields = ('id', 'url', 'display', 'manufacturer', 'name', 'slug', 'description')
|
||||||
|
|
||||||
|
|
||||||
class RackSerializer(NetBoxModelSerializer):
|
class RackSerializer(RackBaseSerializer):
|
||||||
site = SiteSerializer(nested=True)
|
site = SiteSerializer(
|
||||||
location = LocationSerializer(nested=True, required=False, allow_null=True, default=None)
|
nested=True
|
||||||
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
|
)
|
||||||
status = ChoiceField(choices=RackStatusChoices, required=False)
|
location = LocationSerializer(
|
||||||
role = RackRoleSerializer(nested=True, required=False, allow_null=True)
|
nested=True,
|
||||||
form_factor = ChoiceField(choices=RackFormFactorChoices, allow_blank=True, required=False, allow_null=True)
|
required=False,
|
||||||
facility_id = serializers.CharField(max_length=50, allow_blank=True, allow_null=True, label=_('Facility ID'),
|
allow_null=True,
|
||||||
default=None)
|
default=None
|
||||||
rack_type = RackTypeSerializer(nested=True, required=False, allow_null=True, default=None)
|
)
|
||||||
width = ChoiceField(choices=RackWidthChoices, required=False)
|
tenant = TenantSerializer(
|
||||||
outer_unit = ChoiceField(choices=RackDimensionUnitChoices, allow_blank=True, required=False, allow_null=True)
|
nested=True,
|
||||||
weight_unit = ChoiceField(choices=WeightUnitChoices, allow_blank=True, required=False, allow_null=True)
|
required=False,
|
||||||
|
allow_null=True
|
||||||
|
)
|
||||||
|
status = ChoiceField(
|
||||||
|
choices=RackStatusChoices,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
role = RackRoleSerializer(
|
||||||
|
nested=True,
|
||||||
|
required=False,
|
||||||
|
allow_null=True
|
||||||
|
)
|
||||||
|
facility_id = serializers.CharField(
|
||||||
|
max_length=50,
|
||||||
|
allow_blank=True,
|
||||||
|
allow_null=True,
|
||||||
|
label=_('Facility ID'),
|
||||||
|
default=None
|
||||||
|
)
|
||||||
|
rack_type = RackTypeSerializer(
|
||||||
|
nested=True,
|
||||||
|
required=False,
|
||||||
|
allow_null=True,
|
||||||
|
default=None
|
||||||
|
)
|
||||||
|
|
||||||
# Related object counts
|
# Related object counts
|
||||||
device_count = RelatedObjectCountField('devices')
|
device_count = RelatedObjectCountField('devices')
|
||||||
|
@ -37,7 +37,91 @@ __all__ = (
|
|||||||
# Rack Types
|
# Rack Types
|
||||||
#
|
#
|
||||||
|
|
||||||
class RackType(WeightMixin, PrimaryModel):
|
class RackBase(WeightMixin, PrimaryModel):
|
||||||
|
"""
|
||||||
|
Base class for RackType & Rack. Holds
|
||||||
|
"""
|
||||||
|
# Rack type
|
||||||
|
form_factor = models.CharField(
|
||||||
|
choices=RackFormFactorChoices,
|
||||||
|
max_length=50,
|
||||||
|
blank=True,
|
||||||
|
verbose_name=_('form factor')
|
||||||
|
)
|
||||||
|
width = models.PositiveSmallIntegerField(
|
||||||
|
choices=RackWidthChoices,
|
||||||
|
default=RackWidthChoices.WIDTH_19IN,
|
||||||
|
verbose_name=_('width'),
|
||||||
|
help_text=_('Rail-to-rail width')
|
||||||
|
)
|
||||||
|
|
||||||
|
# Numbering
|
||||||
|
u_height = models.PositiveSmallIntegerField(
|
||||||
|
default=RACK_U_HEIGHT_DEFAULT,
|
||||||
|
verbose_name=_('height (U)'),
|
||||||
|
validators=[MinValueValidator(1), MaxValueValidator(RACK_U_HEIGHT_MAX)],
|
||||||
|
help_text=_('Height in rack units')
|
||||||
|
)
|
||||||
|
starting_unit = models.PositiveSmallIntegerField(
|
||||||
|
default=RACK_STARTING_UNIT_DEFAULT,
|
||||||
|
verbose_name=_('starting unit'),
|
||||||
|
validators=[MinValueValidator(1)],
|
||||||
|
help_text=_('Starting unit for rack')
|
||||||
|
)
|
||||||
|
desc_units = models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
verbose_name=_('descending units'),
|
||||||
|
help_text=_('Units are numbered top-to-bottom')
|
||||||
|
)
|
||||||
|
|
||||||
|
# Dimensions
|
||||||
|
outer_width = models.PositiveSmallIntegerField(
|
||||||
|
verbose_name=_('outer width'),
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
help_text=_('Outer dimension of rack (width)')
|
||||||
|
)
|
||||||
|
outer_depth = models.PositiveSmallIntegerField(
|
||||||
|
verbose_name=_('outer depth'),
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
help_text=_('Outer dimension of rack (depth)')
|
||||||
|
)
|
||||||
|
outer_unit = models.CharField(
|
||||||
|
verbose_name=_('outer unit'),
|
||||||
|
max_length=50,
|
||||||
|
choices=RackDimensionUnitChoices,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
mounting_depth = models.PositiveSmallIntegerField(
|
||||||
|
verbose_name=_('mounting depth'),
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
help_text=(_(
|
||||||
|
'Maximum depth of a mounted device, in millimeters. For four-post racks, this is the distance between the '
|
||||||
|
'front and rear rails.'
|
||||||
|
))
|
||||||
|
)
|
||||||
|
|
||||||
|
# Weight
|
||||||
|
# WeightMixin provides weight, weight_unit, and _abs_weight
|
||||||
|
max_weight = models.PositiveIntegerField(
|
||||||
|
verbose_name=_('max weight'),
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
help_text=_('Maximum load capacity for the rack')
|
||||||
|
)
|
||||||
|
# Stores the normalized max weight (in grams) for database ordering
|
||||||
|
_abs_max_weight = models.PositiveBigIntegerField(
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
class RackType(RackBase):
|
||||||
"""
|
"""
|
||||||
Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face.
|
Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face.
|
||||||
Each Rack is assigned to a Site and (optionally) a Location.
|
Each Rack is assigned to a Site and (optionally) a Location.
|
||||||
@ -67,73 +151,6 @@ class RackType(WeightMixin, PrimaryModel):
|
|||||||
max_length=100,
|
max_length=100,
|
||||||
unique=True
|
unique=True
|
||||||
)
|
)
|
||||||
form_factor = models.CharField(
|
|
||||||
choices=RackFormFactorChoices,
|
|
||||||
max_length=50,
|
|
||||||
blank=True,
|
|
||||||
verbose_name=_('form factor')
|
|
||||||
)
|
|
||||||
width = models.PositiveSmallIntegerField(
|
|
||||||
choices=RackWidthChoices,
|
|
||||||
default=RackWidthChoices.WIDTH_19IN,
|
|
||||||
verbose_name=_('width'),
|
|
||||||
help_text=_('Rail-to-rail width')
|
|
||||||
)
|
|
||||||
u_height = models.PositiveSmallIntegerField(
|
|
||||||
default=RACK_U_HEIGHT_DEFAULT,
|
|
||||||
verbose_name=_('height (U)'),
|
|
||||||
validators=[MinValueValidator(1), MaxValueValidator(RACK_U_HEIGHT_MAX)],
|
|
||||||
help_text=_('Height in rack units')
|
|
||||||
)
|
|
||||||
starting_unit = models.PositiveSmallIntegerField(
|
|
||||||
default=RACK_STARTING_UNIT_DEFAULT,
|
|
||||||
verbose_name=_('starting unit'),
|
|
||||||
validators=[MinValueValidator(1)],
|
|
||||||
help_text=_('Starting unit for rack')
|
|
||||||
)
|
|
||||||
desc_units = models.BooleanField(
|
|
||||||
default=False,
|
|
||||||
verbose_name=_('descending units'),
|
|
||||||
help_text=_('Units are numbered top-to-bottom')
|
|
||||||
)
|
|
||||||
outer_width = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('outer width'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=_('Outer dimension of rack (width)')
|
|
||||||
)
|
|
||||||
outer_depth = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('outer depth'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=_('Outer dimension of rack (depth)')
|
|
||||||
)
|
|
||||||
outer_unit = models.CharField(
|
|
||||||
verbose_name=_('outer unit'),
|
|
||||||
max_length=50,
|
|
||||||
choices=RackDimensionUnitChoices,
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
max_weight = models.PositiveIntegerField(
|
|
||||||
verbose_name=_('max weight'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=_('Maximum load capacity for the rack')
|
|
||||||
)
|
|
||||||
# Stores the normalized max weight (in grams) for database ordering
|
|
||||||
_abs_max_weight = models.PositiveBigIntegerField(
|
|
||||||
blank=True,
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
mounting_depth = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('mounting depth'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=(_(
|
|
||||||
'Maximum depth of a mounted device, in millimeters. For four-post racks, this is the distance between the '
|
|
||||||
'front and rear rails.'
|
|
||||||
))
|
|
||||||
)
|
|
||||||
|
|
||||||
clone_fields = (
|
clone_fields = (
|
||||||
'manufacturer', 'form_factor', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit',
|
'manufacturer', 'form_factor', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit',
|
||||||
@ -228,7 +245,7 @@ class RackRole(OrganizationalModel):
|
|||||||
return reverse('dcim:rackrole', args=[self.pk])
|
return reverse('dcim:rackrole', args=[self.pk])
|
||||||
|
|
||||||
|
|
||||||
class Rack(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, WeightMixin):
|
class Rack(ContactsMixin, ImageAttachmentsMixin, RackBase):
|
||||||
"""
|
"""
|
||||||
Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face.
|
Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face.
|
||||||
Each Rack is assigned to a Site and (optionally) a Location.
|
Each Rack is assigned to a Site and (optionally) a Location.
|
||||||
@ -302,73 +319,6 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, WeightMixin):
|
|||||||
verbose_name=_('asset tag'),
|
verbose_name=_('asset tag'),
|
||||||
help_text=_('A unique tag used to identify this rack')
|
help_text=_('A unique tag used to identify this rack')
|
||||||
)
|
)
|
||||||
form_factor = models.CharField(
|
|
||||||
choices=RackFormFactorChoices,
|
|
||||||
max_length=50,
|
|
||||||
blank=True,
|
|
||||||
verbose_name=_('form factor')
|
|
||||||
)
|
|
||||||
width = models.PositiveSmallIntegerField(
|
|
||||||
choices=RackWidthChoices,
|
|
||||||
default=RackWidthChoices.WIDTH_19IN,
|
|
||||||
verbose_name=_('width'),
|
|
||||||
help_text=_('Rail-to-rail width')
|
|
||||||
)
|
|
||||||
u_height = models.PositiveSmallIntegerField(
|
|
||||||
default=RACK_U_HEIGHT_DEFAULT,
|
|
||||||
verbose_name=_('height (U)'),
|
|
||||||
validators=[MinValueValidator(1), MaxValueValidator(RACK_U_HEIGHT_MAX)],
|
|
||||||
help_text=_('Height in rack units')
|
|
||||||
)
|
|
||||||
starting_unit = models.PositiveSmallIntegerField(
|
|
||||||
default=RACK_STARTING_UNIT_DEFAULT,
|
|
||||||
verbose_name=_('starting unit'),
|
|
||||||
validators=[MinValueValidator(1),],
|
|
||||||
help_text=_('Starting unit for rack')
|
|
||||||
)
|
|
||||||
desc_units = models.BooleanField(
|
|
||||||
default=False,
|
|
||||||
verbose_name=_('descending units'),
|
|
||||||
help_text=_('Units are numbered top-to-bottom')
|
|
||||||
)
|
|
||||||
outer_width = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('outer width'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=_('Outer dimension of rack (width)')
|
|
||||||
)
|
|
||||||
outer_depth = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('outer depth'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=_('Outer dimension of rack (depth)')
|
|
||||||
)
|
|
||||||
outer_unit = models.CharField(
|
|
||||||
verbose_name=_('outer unit'),
|
|
||||||
max_length=50,
|
|
||||||
choices=RackDimensionUnitChoices,
|
|
||||||
blank=True,
|
|
||||||
)
|
|
||||||
max_weight = models.PositiveIntegerField(
|
|
||||||
verbose_name=_('max weight'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=_('Maximum load capacity for the rack')
|
|
||||||
)
|
|
||||||
# Stores the normalized max weight (in grams) for database ordering
|
|
||||||
_abs_max_weight = models.PositiveBigIntegerField(
|
|
||||||
blank=True,
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
mounting_depth = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('mounting depth'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
help_text=(
|
|
||||||
_('Maximum depth of a mounted device, in millimeters. For four-post racks, this is the '
|
|
||||||
'distance between the front and rear rails.')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generic relations
|
# Generic relations
|
||||||
vlan_groups = GenericRelation(
|
vlan_groups = GenericRelation(
|
||||||
|
Loading…
Reference in New Issue
Block a user