mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 05:21:55 -06:00
Remove max_length from signals/outer functions
This commit is contained in:
parent
bfe6d393a7
commit
4626649754
@ -17,11 +17,11 @@ def update_circuit(instance, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@receiver((post_save, post_delete), sender=CircuitTermination)
|
@receiver((post_save, post_delete), sender=CircuitTermination)
|
||||||
def rebuild_cablepaths(instance, raw=False, max_length=None, **kwargs):
|
def rebuild_cablepaths(instance, raw=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
Rebuild any CablePaths which traverse the peer CircuitTermination.
|
Rebuild any CablePaths which traverse the peer CircuitTermination.
|
||||||
"""
|
"""
|
||||||
if not raw:
|
if not raw:
|
||||||
peer_termination = instance.get_peer_termination()
|
peer_termination = instance.get_peer_termination()
|
||||||
if peer_termination:
|
if peer_termination:
|
||||||
rebuild_paths([peer_termination], max_length=max_length)
|
rebuild_paths([peer_termination])
|
||||||
|
@ -205,7 +205,6 @@ class Cable(PrimaryModel):
|
|||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
_created = self.pk is None
|
_created = self.pk is None
|
||||||
max_length = kwargs.pop('max_length', None)
|
|
||||||
|
|
||||||
# Store the given length (if any) in meters for use in database ordering
|
# Store the given length (if any) in meters for use in database ordering
|
||||||
if self.length is not None and self.length_unit:
|
if self.length is not None and self.length_unit:
|
||||||
@ -244,7 +243,7 @@ class Cable(PrimaryModel):
|
|||||||
if not termination.pk or termination not in b_terminations:
|
if not termination.pk or termination not in b_terminations:
|
||||||
CableTermination(cable=self, cable_end='B', termination=termination).save()
|
CableTermination(cable=self, cable_end='B', termination=termination).save()
|
||||||
|
|
||||||
trace_paths.send(Cable, instance=self, created=_created, max_length=max_length)
|
trace_paths.send(Cable, instance=self, created=_created)
|
||||||
|
|
||||||
def get_status_color(self):
|
def get_status_color(self):
|
||||||
return LinkStatusChoices.colors.get(self.status)
|
return LinkStatusChoices.colors.get(self.status)
|
||||||
@ -741,11 +740,11 @@ class CablePath(models.Model):
|
|||||||
is_split=is_split
|
is_split=is_split
|
||||||
)
|
)
|
||||||
|
|
||||||
def retrace(self, max_length=None):
|
def retrace(self):
|
||||||
"""
|
"""
|
||||||
Retrace the path from the currently-defined originating termination(s)
|
Retrace the path from the currently-defined originating termination(s)
|
||||||
"""
|
"""
|
||||||
_new = self.from_origin(self.origins, max_length=max_length)
|
_new = self.from_origin(self.origins)
|
||||||
if _new:
|
if _new:
|
||||||
self.path = _new.path
|
self.path = _new.path
|
||||||
self.is_complete = _new.is_complete
|
self.is_complete = _new.is_complete
|
||||||
|
@ -72,7 +72,7 @@ def clear_virtualchassis_members(instance, **kwargs):
|
|||||||
#
|
#
|
||||||
|
|
||||||
@receiver(trace_paths, sender=Cable)
|
@receiver(trace_paths, sender=Cable)
|
||||||
def update_connected_endpoints(instance, created, raw=False, max_length=None, **kwargs):
|
def update_connected_endpoints(instance, created, raw=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
When a Cable is saved with new terminations, retrace any affected cable paths.
|
When a Cable is saved with new terminations, retrace any affected cable paths.
|
||||||
"""
|
"""
|
||||||
@ -95,29 +95,29 @@ def update_connected_endpoints(instance, created, raw=False, max_length=None, **
|
|||||||
if not nodes:
|
if not nodes:
|
||||||
continue
|
continue
|
||||||
if isinstance(nodes[0], PathEndpoint):
|
if isinstance(nodes[0], PathEndpoint):
|
||||||
create_cablepath(nodes, max_length=max_length)
|
create_cablepath(nodes)
|
||||||
else:
|
else:
|
||||||
rebuild_paths(nodes, max_length=max_length)
|
rebuild_paths(nodes)
|
||||||
|
|
||||||
# Update status of CablePaths if Cable status has been changed
|
# Update status of CablePaths if Cable status has been changed
|
||||||
elif instance.status != instance._orig_status:
|
elif instance.status != instance._orig_status:
|
||||||
if instance.status != LinkStatusChoices.STATUS_CONNECTED:
|
if instance.status != LinkStatusChoices.STATUS_CONNECTED:
|
||||||
CablePath.objects.filter(_nodes__contains=instance).update(is_active=False)
|
CablePath.objects.filter(_nodes__contains=instance).update(is_active=False)
|
||||||
else:
|
else:
|
||||||
rebuild_paths([instance], max_length=max_length)
|
rebuild_paths([instance])
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=Cable)
|
@receiver(post_delete, sender=Cable)
|
||||||
def retrace_cable_paths(instance, max_length=None, **kwargs):
|
def retrace_cable_paths(instance, **kwargs):
|
||||||
"""
|
"""
|
||||||
When a Cable is deleted, check for and update its connected endpoints
|
When a Cable is deleted, check for and update its connected endpoints
|
||||||
"""
|
"""
|
||||||
for cablepath in CablePath.objects.filter(_nodes__contains=instance):
|
for cablepath in CablePath.objects.filter(_nodes__contains=instance):
|
||||||
cablepath.retrace(max_length=max_length)
|
cablepath.retrace()
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=CableTermination)
|
@receiver(post_delete, sender=CableTermination)
|
||||||
def nullify_connected_endpoints(instance, max_length=None, **kwargs):
|
def nullify_connected_endpoints(instance, **kwargs):
|
||||||
"""
|
"""
|
||||||
Disassociate the Cable from the termination object, and retrace any affected CablePaths.
|
Disassociate the Cable from the termination object, and retrace any affected CablePaths.
|
||||||
"""
|
"""
|
||||||
@ -128,15 +128,15 @@ def nullify_connected_endpoints(instance, max_length=None, **kwargs):
|
|||||||
# Remove the deleted CableTermination if it's one of the path's originating nodes
|
# Remove the deleted CableTermination if it's one of the path's originating nodes
|
||||||
if instance.termination in cablepath.origins:
|
if instance.termination in cablepath.origins:
|
||||||
cablepath.origins.remove(instance.termination)
|
cablepath.origins.remove(instance.termination)
|
||||||
cablepath.retrace(max_length=max_length)
|
cablepath.retrace()
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=FrontPort)
|
@receiver(post_save, sender=FrontPort)
|
||||||
def extend_rearport_cable_paths(instance, created, raw, max_length=None, **kwargs):
|
def extend_rearport_cable_paths(instance, created, raw, **kwargs):
|
||||||
"""
|
"""
|
||||||
When a new FrontPort is created, add it to any CablePaths which end at its corresponding RearPort.
|
When a new FrontPort is created, add it to any CablePaths which end at its corresponding RearPort.
|
||||||
"""
|
"""
|
||||||
if created and not raw:
|
if created and not raw:
|
||||||
rearport = instance.rear_port
|
rearport = instance.rear_port
|
||||||
for cablepath in CablePath.objects.filter(_nodes__contains=rearport):
|
for cablepath in CablePath.objects.filter(_nodes__contains=rearport):
|
||||||
cablepath.retrace(max_length=max_length)
|
cablepath.retrace()
|
||||||
|
@ -2382,9 +2382,9 @@ class CablePathTestCase(TestCase):
|
|||||||
CableTermination.objects.create(cable=cable_2, cable_end='A', termination_type=ct_frontport, termination_id=front_port_2.id)
|
CableTermination.objects.create(cable=cable_2, cable_end='A', termination_type=ct_frontport, termination_id=front_port_2.id)
|
||||||
CableTermination.objects.create(cable=cable_2, cable_end='B', termination_type=ct_rearport, termination_id=rear_splice.id)
|
CableTermination.objects.create(cable=cable_2, cable_end='B', termination_type=ct_rearport, termination_id=rear_splice.id)
|
||||||
|
|
||||||
max_length = 50
|
cable_1.save()
|
||||||
|
|
||||||
cable_1.save(max_length=max_length)
|
max_length = 50
|
||||||
a_terminations = []
|
a_terminations = []
|
||||||
b_terminations = []
|
b_terminations = []
|
||||||
for t in cable_1.terminations.all():
|
for t in cable_1.terminations.all():
|
||||||
|
@ -30,21 +30,20 @@ def path_node_to_object(repr):
|
|||||||
return ct.model_class().objects.filter(pk=object_id).first()
|
return ct.model_class().objects.filter(pk=object_id).first()
|
||||||
|
|
||||||
|
|
||||||
def create_cablepath(terminations, max_length=None):
|
def create_cablepath(terminations):
|
||||||
"""
|
"""
|
||||||
Create CablePaths for all paths originating from the specified set of nodes.
|
Create CablePaths for all paths originating from the specified set of nodes.
|
||||||
|
|
||||||
:param terminations: Iterable of CableTermination objects
|
:param terminations: Iterable of CableTermination objects
|
||||||
:max_length: Optional limit of cable path to trace
|
|
||||||
"""
|
"""
|
||||||
from dcim.models import CablePath
|
from dcim.models import CablePath
|
||||||
|
|
||||||
cp = CablePath.from_origin(terminations, max_length=max_length)
|
cp = CablePath.from_origin(terminations)
|
||||||
if cp:
|
if cp:
|
||||||
cp.save()
|
cp.save()
|
||||||
|
|
||||||
|
|
||||||
def rebuild_paths(terminations, max_length=None):
|
def rebuild_paths(terminations):
|
||||||
"""
|
"""
|
||||||
Rebuild all CablePaths which traverse the specified nodes.
|
Rebuild all CablePaths which traverse the specified nodes.
|
||||||
"""
|
"""
|
||||||
@ -56,4 +55,4 @@ def rebuild_paths(terminations, max_length=None):
|
|||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for cp in cable_paths:
|
for cp in cable_paths:
|
||||||
cp.delete()
|
cp.delete()
|
||||||
create_cablepath(cp.origins, max_length=max_length)
|
create_cablepath(cp.origins)
|
||||||
|
@ -13,7 +13,7 @@ from .models import WirelessLink
|
|||||||
#
|
#
|
||||||
|
|
||||||
@receiver(post_save, sender=WirelessLink)
|
@receiver(post_save, sender=WirelessLink)
|
||||||
def update_connected_interfaces(instance, created, raw=False, max_length=None, **kwargs):
|
def update_connected_interfaces(instance, created, raw=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
When a WirelessLink is saved, save a reference to it on each connected interface.
|
When a WirelessLink is saved, save a reference to it on each connected interface.
|
||||||
"""
|
"""
|
||||||
@ -34,7 +34,7 @@ def update_connected_interfaces(instance, created, raw=False, max_length=None, *
|
|||||||
# Create/update cable paths
|
# Create/update cable paths
|
||||||
if created:
|
if created:
|
||||||
for interface in (instance.interface_a, instance.interface_b):
|
for interface in (instance.interface_a, instance.interface_b):
|
||||||
create_cablepath([interface], max_length=max_length)
|
create_cablepath([interface])
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=WirelessLink)
|
@receiver(post_delete, sender=WirelessLink)
|
||||||
|
Loading…
Reference in New Issue
Block a user