Repository: netbox-community/netbox

Issue:
support color attribute on module type and device type import and export
### NetBox version

v3.2.7

### Feature type

Change to existing functionality

### Proposed functionality

When importing module types via the web interface (Devices -> Module Types -> Import), allow specifying `color` attribute for front and rear ports.   Also, when exporting module types via the web interface (Devices -> Module Types -> Export -> All Data (YAML)) include the `color` attribute for front and rear ports, if defined.

An example import file:

```yaml
manufacturer: Generic
model: test-device
part_number: ''
comments: ''
front-ports:
- name: '1'
  type: lc
  rear_port: '1'
  rear_port_position: 1
  label: ''
  color: '3f51b5'
  description: ''
- name: '2'
  type: lc
  rear_port: '1'
  rear_port_position: 2
  label: ''
  color: '3f51b5'
  description: ''
rear-ports:
- name: '1'
  type: mpo
  positions: 2
  label: ''
  color: '000000'
  description: ''
```

Currently, it appears that the `color` field is ignored.

An export of that module type does not show the color.

```yaml
manufacturer: Generic
model: test-device
part_number: ''
comments: ''
front-ports:
- name: '1'
  type: lc
  rear_port: '1'
  rear_port_position: 1
  label: ''
  description: ''
- name: '2'
  type: lc
  rear_port: '1'
  rear_port_position: 2
  label: ''
  description: ''
rear-ports:
- name: '1'
  type: mpo
  positions: 2
  label: ''
  description: ''
```

I see similar behavior with device types.

I'm not sure to consider this omission a bug or not, so am submitting as a FR.

### Use case

It is useful to create a library of device type and module types outside of netbox for easy import into new installations.  This would allow the inclusion of the color field in the objects in this library.

### Database changes

none

### External dependencies

none


Discussion:

Resolving patch:
diff --git a/netbox/dcim/forms/object_import.py b/netbox/dcim/forms/object_import.py
--- a/netbox/dcim/forms/object_import.py
+++ b/netbox/dcim/forms/object_import.py
@@ -146,7 +146,7 @@ def clean_module_type(self):
     class Meta:
         model = FrontPortTemplate
         fields = [
-            'device_type', 'module_type', 'name', 'type', 'rear_port', 'rear_port_position', 'label', 'description',
+            'device_type', 'module_type', 'name', 'type', 'color', 'rear_port', 'rear_port_position', 'label', 'description',
         ]
 
 
@@ -158,7 +158,7 @@ class RearPortTemplateImportForm(ComponentTemplateImportForm):
     class Meta:
         model = RearPortTemplate
         fields = [
-            'device_type', 'module_type', 'name', 'type', 'positions', 'label', 'description',
+            'device_type', 'module_type', 'name', 'type', 'color', 'positions', 'label', 'description',
         ]
 
 
diff --git a/netbox/dcim/models/device_component_templates.py b/netbox/dcim/models/device_component_templates.py
--- a/netbox/dcim/models/device_component_templates.py
+++ b/netbox/dcim/models/device_component_templates.py
@@ -462,6 +462,7 @@ def to_yaml(self):
         return {
             'name': self.name,
             'type': self.type,
+            'color': self.color,
             'rear_port': self.rear_port.name,
             'rear_port_position': self.rear_port_position,
             'label': self.label,
@@ -511,6 +512,7 @@ def to_yaml(self):
         return {
             'name': self.name,
             'type': self.type,
+            'color': self.color,
             'positions': self.positions,
             'label': self.label,
             'description': self.description,


Test patch: