diff --git a/netbox/dcim/models/device_component_templates.py b/netbox/dcim/models/device_component_templates.py index ff5df9721..1799e1265 100644 --- a/netbox/dcim/models/device_component_templates.py +++ b/netbox/dcim/models/device_component_templates.py @@ -549,6 +549,14 @@ class PortTemplateMapping(PortMappingBase): self.module_type = self.front_port.module_type super().save(*args, **kwargs) + def to_yaml(self): + return { + 'front_port': self.front_port.name, + 'front_port_position': self.front_port_position, + 'rear_port': self.rear_port.name, + 'rear_port_position': self.rear_port_position, + } + class FrontPortTemplate(ModularComponentTemplateModel): """ diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 4a5d0b3cd..aa4a794e2 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -275,6 +275,15 @@ class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin): data['rear-ports'] = [ c.to_yaml() for c in self.rearporttemplates.all() ] + + # Port mappings + port_mapping_data = [ + c.to_yaml() for c in self.port_mappings.all() + ] + + if port_mapping_data: + data['port-mappings'] = port_mapping_data + if self.modulebaytemplates.exists(): data['module-bays'] = [ c.to_yaml() for c in self.modulebaytemplates.all() diff --git a/netbox/dcim/models/modules.py b/netbox/dcim/models/modules.py index 89e914366..56cc333ff 100644 --- a/netbox/dcim/models/modules.py +++ b/netbox/dcim/models/modules.py @@ -192,6 +192,14 @@ class ModuleType(ImageAttachmentsMixin, PrimaryModel, WeightMixin): c.to_yaml() for c in self.rearporttemplates.all() ] + # Port mappings + port_mapping_data = [ + c.to_yaml() for c in self.port_mappings.all() + ] + + if port_mapping_data: + data['port-mappings'] = port_mapping_data + return yaml.dump(dict(data), sort_keys=False)