From 4c9ba04f129a94be1a412cdd2d3688775a12ff90 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Wed, 24 Jul 2024 15:45:42 +0700 Subject: [PATCH] 11960 Add airflow --- ...e_airflow_rack_airflow_racktype_airflow.py | 28 +++++++++++++++++++ netbox/dcim/models/devices.py | 21 ++++---------- netbox/dcim/models/mixins.py | 12 ++++++++ netbox/dcim/models/racks.py | 6 ++-- 4 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 netbox/dcim/migrations/0189_module_airflow_rack_airflow_racktype_airflow.py diff --git a/netbox/dcim/migrations/0189_module_airflow_rack_airflow_racktype_airflow.py b/netbox/dcim/migrations/0189_module_airflow_rack_airflow_racktype_airflow.py new file mode 100644 index 000000000..4523ec49c --- /dev/null +++ b/netbox/dcim/migrations/0189_module_airflow_rack_airflow_racktype_airflow.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.7 on 2024-07-24 08:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0188_racktype'), + ] + + operations = [ + migrations.AddField( + model_name='module', + name='airflow', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AddField( + model_name='rack', + name='airflow', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AddField( + model_name='racktype', + name='airflow', + field=models.CharField(blank=True, max_length=50), + ), + ] diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index abc9e0b08..14f17f4ce 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -25,7 +25,7 @@ from netbox.models.features import ContactsMixin, ImageAttachmentsMixin from utilities.fields import ColorField, CounterCacheField, NaturalOrderingField from utilities.tracking import TrackingModelMixin from .device_components import * -from .mixins import RenderConfigMixin, WeightMixin +from .mixins import AirflowMixin, RenderConfigMixin, WeightMixin __all__ = ( @@ -58,7 +58,7 @@ class Manufacturer(ContactsMixin, OrganizationalModel): return reverse('dcim:manufacturer', args=[self.pk]) -class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin): +class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin, AirflowMixin): """ A DeviceType represents a particular make (Manufacturer) and model of device. It specifies rack height and depth, as well as high-level functional role(s). @@ -124,12 +124,6 @@ class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin): help_text=_('Parent devices house child devices in device bays. Leave blank ' 'if this device type is neither a parent nor a child.') ) - airflow = models.CharField( - verbose_name=_('airflow'), - max_length=50, - choices=DeviceAirflowChoices, - blank=True - ) front_image = models.ImageField( upload_to='devicetype-images', blank=True @@ -541,6 +535,7 @@ class Device( RenderConfigMixin, ConfigContextModel, TrackingModelMixin, + AirflowMixin, PrimaryModel ): """ @@ -645,12 +640,6 @@ class Device( choices=DeviceStatusChoices, default=DeviceStatusChoices.STATUS_ACTIVE ) - airflow = models.CharField( - verbose_name=_('airflow'), - max_length=50, - choices=DeviceAirflowChoices, - blank=True - ) primary_ip4 = models.OneToOneField( to='ipam.IPAddress', on_delete=models.SET_NULL, @@ -1131,7 +1120,7 @@ class Device( return round(total_weight / 1000, 2) -class Module(PrimaryModel, ConfigContextModel): +class Module(PrimaryModel, ConfigContextModel, AirflowMixin): """ A Module represents a field-installable component within a Device which may itself hold multiple device components (for example, a line card within a chassis switch). Modules are instantiated from ModuleTypes. @@ -1171,7 +1160,7 @@ class Module(PrimaryModel, ConfigContextModel): help_text=_('A unique tag used to identify this device') ) - clone_fields = ('device', 'module_type', 'status') + clone_fields = ('device', 'module_type', 'status', 'airflow') class Meta: ordering = ('module_bay',) diff --git a/netbox/dcim/models/mixins.py b/netbox/dcim/models/mixins.py index d4a05699c..fc30b05c7 100644 --- a/netbox/dcim/models/mixins.py +++ b/netbox/dcim/models/mixins.py @@ -73,3 +73,15 @@ class RenderConfigMixin(models.Model): return self.role.config_template if self.platform and self.platform.config_template: return self.platform.config_template + + +class AirflowMixin(models.Model): + airflow = models.CharField( + verbose_name=_('airflow'), + max_length=50, + choices=DeviceAirflowChoices, + blank=True + ) + + class Meta: + abstract = True diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index e6487c705..f0f1dbea2 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -22,7 +22,7 @@ from utilities.data import array_to_string, drange from utilities.fields import ColorField, NaturalOrderingField from .device_components import PowerPort from .devices import Device, Module -from .mixins import WeightMixin +from .mixins import AirflowMixin, WeightMixin from .power import PowerFeed __all__ = ( @@ -37,7 +37,7 @@ __all__ = ( # Rack Types # -class RackBase(WeightMixin, PrimaryModel): +class RackBase(WeightMixin, PrimaryModel, AirflowMixin): """ Base class for RackType & Rack. Holds """ @@ -317,7 +317,7 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, RackBase): clone_fields = ( 'site', 'location', 'tenant', 'status', 'role', 'form_factor', 'width', 'u_height', 'desc_units', 'outer_width', - 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', + 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'airflow', ) prerequisite_models = ( 'dcim.Site',