Skip to content
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
5 changes: 5 additions & 0 deletions docs/models/dcim/devicebay.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ The device bay's name. Must be unique to the parent device.
### Label

An alternative physical label identifying the device bay.

### Enabled

Whether this device bay is enabled. Disabled device bays are not available for installation.

7 changes: 6 additions & 1 deletion docs/models/dcim/modulebay.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Module Bays

Module bays represent a space or slot within a device in which a field-replaceable [module](./module.md) may be installed. A common example is that of a chassis-based switch such as the Cisco Nexus 9000 or Juniper EX9200. Modules in turn hold additional components that become available to the parent device.
Module bays represent a space or slot within a device in which a field-replaceable [module](./module.md) may be installed. A common example is that of a chassis-based switch such as the Cisco Nexus 9000 or Juniper EX9200. Modules, in turn, hold additional components that become available to the parent device.

!!! note
If you need to model child devices rather than modules, use a [device bay](./devicebay.md) instead.
Expand Down Expand Up @@ -29,3 +29,8 @@ An alternative physical label identifying the module bay.
### Position

The numeric position in which this module bay is situated. For example, this would be the number assigned to a slot within a chassis-based switch.

### Enabled

Whether this module bay is enabled. Disabled module bays are not available for installation.

14 changes: 8 additions & 6 deletions netbox/dcim/api/serializers_/device_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,27 +423,29 @@ class ModuleBaySerializer(OwnerMixin, NetBoxModelSerializer):
required=False,
allow_null=True
)
_occupied = serializers.BooleanField(required=False, read_only=True)

class Meta:
model = ModuleBay
fields = [
'id', 'url', 'display_url', 'display', 'device', 'module', 'name', 'installed_module', 'label', 'position',
'description', 'owner', 'tags', 'custom_fields', 'created', 'last_updated',
'id', 'url', 'display_url', 'display', 'device', 'module', 'name', 'label', 'position', 'enabled',
'description', 'installed_module', 'owner', 'tags', 'custom_fields', 'created', 'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'installed_module', 'name', 'description')
brief_fields = ('id', 'url', 'display', 'installed_module', 'name', 'enabled', 'description', '_occupied')


class DeviceBaySerializer(OwnerMixin, NetBoxModelSerializer):
device = DeviceSerializer(nested=True)
installed_device = DeviceSerializer(nested=True, required=False, allow_null=True)
_occupied = serializers.BooleanField(required=False, read_only=True)

class Meta:
model = DeviceBay
fields = [
'id', 'url', 'display_url', 'display', 'device', 'name', 'label', 'description', 'installed_device',
'owner', 'tags', 'custom_fields', 'created', 'last_updated',
'id', 'url', 'display_url', 'display', 'device', 'name', 'label', 'enabled', 'description',
'installed_device', 'owner', 'tags', 'custom_fields', 'created', 'last_updated', '_occupied',
]
brief_fields = ('id', 'url', 'display', 'device', 'name', 'description')
brief_fields = ('id', 'url', 'display', 'device', 'name', 'enabled', 'description', '_occupied',)


class InventoryItemSerializer(OwnerMixin, NetBoxModelSerializer):
Expand Down
8 changes: 4 additions & 4 deletions netbox/dcim/api/serializers_/devicetype_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ class ModuleBayTemplateSerializer(ComponentTemplateSerializer):
class Meta:
model = ModuleBayTemplate
fields = [
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'position', 'description',
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'position', 'enabled', 'description',
'created', 'last_updated',
]
brief_fields = ('id', 'url', 'display', 'name', 'description')
brief_fields = ('id', 'url', 'display', 'name', 'enabled', 'description')


class DeviceBayTemplateSerializer(ComponentTemplateSerializer):
Expand All @@ -331,10 +331,10 @@ class DeviceBayTemplateSerializer(ComponentTemplateSerializer):
class Meta:
model = DeviceBayTemplate
fields = [
'id', 'url', 'display', 'device_type', 'name', 'label', 'description',
'id', 'url', 'display', 'device_type', 'name', 'label', 'enabled', 'description',
'created', 'last_updated'
]
brief_fields = ('id', 'url', 'display', 'name', 'description')
brief_fields = ('id', 'url', 'display', 'name', 'enabled', 'description')


class InventoryItemTemplateSerializer(ComponentTemplateSerializer):
Expand Down
8 changes: 4 additions & 4 deletions netbox/dcim/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,15 +1032,15 @@ class ModuleBayTemplateFilterSet(ChangeLoggedModelFilterSet, ModularDeviceTypeCo

class Meta:
model = ModuleBayTemplate
fields = ('id', 'name', 'label', 'position', 'description')
fields = ('id', 'name', 'label', 'position', 'enabled', 'description')


@register_filterset
class DeviceBayTemplateFilterSet(ChangeLoggedModelFilterSet, DeviceTypeComponentFilterSet):

class Meta:
model = DeviceBayTemplate
fields = ('id', 'name', 'label', 'description')
fields = ('id', 'name', 'label', 'enabled', 'description')


@register_filterset
Expand Down Expand Up @@ -2397,7 +2397,7 @@ class ModuleBayFilterSet(ModularDeviceComponentFilterSet):

class Meta:
model = ModuleBay
fields = ('id', 'name', 'label', 'position', 'description')
fields = ('id', 'name', 'label', 'position', 'enabled', 'description')


@register_filterset
Expand All @@ -2417,7 +2417,7 @@ class DeviceBayFilterSet(DeviceComponentFilterSet):

class Meta:
model = DeviceBay
fields = ('id', 'name', 'label', 'description')
fields = ('id', 'name', 'label', 'enabled', 'description')


@register_filterset
Expand Down
16 changes: 11 additions & 5 deletions netbox/dcim/forms/bulk_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,26 @@ class RearPortBulkCreateForm(
field_order = ('name', 'label', 'type', 'positions', 'mark_connected', 'description', 'tags')


class ModuleBayBulkCreateForm(DeviceBulkAddComponentForm):
class ModuleBayBulkCreateForm(
form_from_model(ModuleBay, ['enabled']),
DeviceBulkAddComponentForm
):
model = ModuleBay
field_order = ('name', 'label', 'position', 'description', 'tags')
replication_fields = ('name', 'label', 'position')
field_order = ('name', 'label', 'position', 'enabled', 'description', 'tags')
replication_fields = ('name', 'label', 'position', 'enabled')
position = ExpandableNameField(
label=_('Position'),
required=False,
help_text=_('Alphanumeric ranges are supported. (Must match the number of names being created.)')
)


class DeviceBayBulkCreateForm(DeviceBulkAddComponentForm):
class DeviceBayBulkCreateForm(
form_from_model(DeviceBay, ['enabled']),
DeviceBulkAddComponentForm
):
model = DeviceBay
field_order = ('name', 'label', 'description', 'tags')
field_order = ('name', 'label', 'enabled', 'description', 'tags')


class InventoryItemBulkCreateForm(
Expand Down
18 changes: 14 additions & 4 deletions netbox/dcim/forms/bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,11 @@ class ModuleBayTemplateBulkEditForm(ComponentTemplateBulkEditForm):
label=_('Description'),
required=False
)
enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False,
widget=BulkEditNullBooleanSelect,
)

nullable_fields = ('label', 'position', 'description')

Expand All @@ -1263,6 +1268,11 @@ class DeviceBayTemplateBulkEditForm(ComponentTemplateBulkEditForm):
label=_('Description'),
required=False
)
enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False,
widget=BulkEditNullBooleanSelect,
)

nullable_fields = ('label', 'description')

Expand Down Expand Up @@ -1687,23 +1697,23 @@ class RearPortBulkEditForm(


class ModuleBayBulkEditForm(
form_from_model(ModuleBay, ['label', 'position', 'description']),
form_from_model(ModuleBay, ['label', 'position', 'enabled', 'description']),
NetBoxModelBulkEditForm
):
model = ModuleBay
fieldsets = (
FieldSet('label', 'position', 'description'),
FieldSet('label', 'position', 'enabled', 'description'),
)
nullable_fields = ('label', 'position', 'description')


class DeviceBayBulkEditForm(
form_from_model(DeviceBay, ['label', 'description']),
form_from_model(DeviceBay, ['label', 'enabled', 'description']),
NetBoxModelBulkEditForm
):
model = DeviceBay
fieldsets = (
FieldSet('label', 'description'),
FieldSet('label', 'enabled', 'description'),
)
nullable_fields = ('label', 'description')

Expand Down
16 changes: 14 additions & 2 deletions netbox/dcim/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,13 @@ class ModuleBayImportForm(OwnerCSVMixin, NetBoxModelImportForm):

class Meta:
model = ModuleBay
fields = ('device', 'name', 'label', 'position', 'description', 'owner', 'tags')
fields = ('device', 'name', 'label', 'position', 'enabled', 'description', 'owner', 'tags')

def clean_enabled(self):
# Make sure enabled is True when it's not included in the uploaded data
if 'enabled' not in self.data:
return True
return self.cleaned_data['enabled']


class DeviceBayImportForm(OwnerCSVMixin, NetBoxModelImportForm):
Expand All @@ -1176,7 +1182,7 @@ class DeviceBayImportForm(OwnerCSVMixin, NetBoxModelImportForm):

class Meta:
model = DeviceBay
fields = ('device', 'name', 'label', 'installed_device', 'description', 'owner', 'tags')
fields = ('device', 'name', 'label', 'enabled', 'installed_device', 'description', 'owner', 'tags')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -1204,6 +1210,12 @@ def __init__(self, *args, **kwargs):
else:
self.fields['installed_device'].queryset = Device.objects.none()

def clean_enabled(self):
# Make sure enabled is True when it's not included in the uploaded data
if 'enabled' not in self.data:
return True
return self.cleaned_data['enabled']


class InventoryItemImportForm(OwnerCSVMixin, NetBoxModelImportForm):
device = CSVModelChoiceField(
Expand Down
30 changes: 25 additions & 5 deletions netbox/dcim/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1870,56 +1870,76 @@ class ModuleBayFilterForm(DeviceComponentFilterForm):
model = ModuleBay
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('name', 'label', 'position', name=_('Attributes')),
FieldSet('name', 'label', 'position', 'enabled', name=_('Attributes')),
FieldSet('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id', name=_('Location')),
FieldSet(
'tenant_id', 'device_type_id', 'device_role_id', 'device_id', 'device_status', 'virtual_chassis_id',
name=_('Device')
),
FieldSet('owner_group_id', 'owner_id', name=_('Ownership')),
)
tag = TagFilterField(model)
position = forms.CharField(
label=_('Position'),
required=False
)
enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False,
widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES),
)
tag = TagFilterField(model)


class ModuleBayTemplateFilterForm(ModularDeviceComponentTemplateFilterForm):
model = ModuleBayTemplate
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('name', 'label', 'position', name=_('Attributes')),
FieldSet('name', 'label', 'position', 'enabled', name=_('Attributes')),
FieldSet('device_type_id', 'module_type_id', name=_('Device')),
)
position = forms.CharField(
label=_('Position'),
required=False,
)
enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False,
widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES),
)


class DeviceBayFilterForm(DeviceComponentFilterForm):
model = DeviceBay
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('name', 'label', name=_('Attributes')),
FieldSet('name', 'label', 'enabled', name=_('Attributes')),
FieldSet('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id', name=_('Location')),
FieldSet(
'tenant_id', 'device_type_id', 'device_role_id', 'device_id', 'device_status', 'virtual_chassis_id',
name=_('Device')
),
FieldSet('owner_group_id', 'owner_id', name=_('Ownership')),
)
enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False,
widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES),
)
tag = TagFilterField(model)


class DeviceBayTemplateFilterForm(DeviceComponentTemplateFilterForm):
model = DeviceBayTemplate
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('name', 'label', name=_('Attributes')),
FieldSet('name', 'label', 'enabled', name=_('Attributes')),
FieldSet('device_type_id', name=_('Device')),
)
enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False,
widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES),
)


class InventoryItemFilterForm(DeviceComponentFilterForm):
Expand Down
18 changes: 9 additions & 9 deletions netbox/dcim/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ class ModuleForm(ModuleCommonForm, PrimaryModelForm):
'device_id': '$device',
},
context={
'disabled': 'installed_module',
'disabled': '_occupied',
},
)
module_type = DynamicModelChoiceField(
Expand Down Expand Up @@ -1233,26 +1233,26 @@ class ModuleBayTemplateForm(ModularComponentTemplateForm):
FieldSet('device_type', name=_('Device Type')),
FieldSet('module_type', name=_('Module Type')),
),
'name', 'label', 'position', 'description',
'name', 'label', 'position', 'enabled', 'description',
),
)

class Meta:
model = ModuleBayTemplate
fields = [
'device_type', 'module_type', 'name', 'label', 'position', 'description',
'device_type', 'module_type', 'name', 'label', 'position', 'enabled', 'description',
]


class DeviceBayTemplateForm(ComponentTemplateForm):
fieldsets = (
FieldSet('device_type', 'name', 'label', 'description'),
FieldSet('device_type', 'name', 'label', 'enabled', 'description'),
)

class Meta:
model = DeviceBayTemplate
fields = [
'device_type', 'name', 'label', 'description',
'device_type', 'name', 'label', 'enabled', 'description',
]


Expand Down Expand Up @@ -1698,25 +1698,25 @@ class Meta:

class ModuleBayForm(ModularDeviceComponentForm):
fieldsets = (
FieldSet('device', 'module', 'name', 'label', 'position', 'description', 'tags',),
FieldSet('device', 'module', 'name', 'label', 'position', 'enabled', 'description', 'tags',),
)

class Meta:
model = ModuleBay
fields = [
'device', 'module', 'name', 'label', 'position', 'description', 'owner', 'tags',
'device', 'module', 'name', 'label', 'position', 'enabled', 'description', 'owner', 'tags',
]


class DeviceBayForm(DeviceComponentForm):
fieldsets = (
FieldSet('device', 'name', 'label', 'description', 'tags',),
FieldSet('device', 'name', 'label', 'enabled', 'description', 'tags',),
)

class Meta:
model = DeviceBay
fields = [
'device', 'name', 'label', 'description', 'owner', 'tags',
'device', 'name', 'label', 'enabled', 'description', 'owner', 'tags',
]


Expand Down
Loading
Loading