1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Rename parent attribute on CableTerminations to parent_object

This commit is contained in:
Jeremy Stretch
2021-03-05 13:06:21 -05:00
parent 7a5cf80412
commit 8e1fe6339e
8 changed files with 28 additions and 28 deletions

View File

@@ -84,8 +84,8 @@ class ComponentModel(PrimaryModel):
return super().to_objectchange(action, related_object=device)
@property
def parent(self):
return getattr(self, 'device', None)
def parent_object(self):
return self.device
class CableTermination(models.Model):
@@ -152,6 +152,10 @@ class CableTermination(models.Model):
def _occupied(self):
return bool(self.mark_connected or self.cable_id)
@property
def parent_object(self):
raise NotImplementedError("CableTermination models must implement parent_object()")
class PathEndpoint(models.Model):
"""
@@ -207,7 +211,7 @@ class PathEndpoint(models.Model):
#
@extras_features('custom_fields', 'export_templates', 'webhooks')
class ConsolePort(CableTermination, PathEndpoint, ComponentModel):
class ConsolePort(ComponentModel, CableTermination, PathEndpoint):
"""
A physical console port within a Device. ConsolePorts connect to ConsoleServerPorts.
"""
@@ -251,7 +255,7 @@ class ConsolePort(CableTermination, PathEndpoint, ComponentModel):
#
@extras_features('custom_fields', 'export_templates', 'webhooks')
class ConsoleServerPort(CableTermination, PathEndpoint, ComponentModel):
class ConsoleServerPort(ComponentModel, CableTermination, PathEndpoint):
"""
A physical port within a Device (typically a designated console server) which provides access to ConsolePorts.
"""
@@ -295,7 +299,7 @@ class ConsoleServerPort(CableTermination, PathEndpoint, ComponentModel):
#
@extras_features('custom_fields', 'export_templates', 'webhooks')
class PowerPort(CableTermination, PathEndpoint, ComponentModel):
class PowerPort(ComponentModel, CableTermination, PathEndpoint):
"""
A physical power supply (intake) port within a Device. PowerPorts connect to PowerOutlets.
"""
@@ -407,7 +411,7 @@ class PowerPort(CableTermination, PathEndpoint, ComponentModel):
#
@extras_features('custom_fields', 'export_templates', 'webhooks')
class PowerOutlet(CableTermination, PathEndpoint, ComponentModel):
class PowerOutlet(ComponentModel, CableTermination, PathEndpoint):
"""
A physical power outlet (output) within a Device which provides power to a PowerPort.
"""
@@ -508,7 +512,7 @@ class BaseInterface(models.Model):
@extras_features('custom_fields', 'export_templates', 'webhooks')
class Interface(CableTermination, PathEndpoint, ComponentModel, BaseInterface):
class Interface(ComponentModel, BaseInterface, CableTermination, PathEndpoint):
"""
A network interface within a Device. A physical Interface can connect to exactly one other Interface.
"""
@@ -619,16 +623,12 @@ class Interface(CableTermination, PathEndpoint, ComponentModel, BaseInterface):
raise ValidationError({'lag': "A LAG interface cannot be its own parent."})
# Validate untagged VLAN
if self.untagged_vlan and self.untagged_vlan.site not in [self.parent.site, None]:
if self.untagged_vlan and self.untagged_vlan.site not in [self.device.site, None]:
raise ValidationError({
'untagged_vlan': "The untagged VLAN ({}) must belong to the same site as the interface's parent "
"device, or it must be global".format(self.untagged_vlan)
})
@property
def parent(self):
return self.device
@property
def is_connectable(self):
return self.type not in NONCONNECTABLE_IFACE_TYPES
@@ -655,7 +655,7 @@ class Interface(CableTermination, PathEndpoint, ComponentModel, BaseInterface):
#
@extras_features('custom_fields', 'export_templates', 'webhooks')
class FrontPort(CableTermination, ComponentModel):
class FrontPort(ComponentModel, CableTermination):
"""
A pass-through port on the front of a Device.
"""
@@ -721,7 +721,7 @@ class FrontPort(CableTermination, ComponentModel):
@extras_features('custom_fields', 'export_templates', 'webhooks')
class RearPort(CableTermination, ComponentModel):
class RearPort(ComponentModel, CableTermination):
"""
A pass-through port on the rear of a Device.
"""

View File

@@ -201,7 +201,7 @@ class PowerFeed(PrimaryModel, PathEndpoint, CableTermination):
super().save(*args, **kwargs)
@property
def parent(self):
def parent_object(self):
return self.power_panel
def get_type_class(self):