mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-14 12:29:35 -06:00
Simplify A/B side popping logic
This commit is contained in:
parent
2fe5323dd2
commit
fb2ea37443
@ -12,9 +12,9 @@ class BaseCableProfile:
|
|||||||
# Number of A & B terminations must match
|
# Number of A & B terminations must match
|
||||||
symmetrical = True
|
symmetrical = True
|
||||||
|
|
||||||
# Whether to pop the position stack when tracing a cable from this end
|
# Whether terminations on either side of the cable have a numeric position
|
||||||
pop_stack_a_side = True
|
a_side_numbered = True
|
||||||
pop_stack_b_side = True
|
b_side_numbered = True
|
||||||
|
|
||||||
def clean(self, cable):
|
def clean(self, cable):
|
||||||
if self.a_max_connections and len(cable.a_terminations) > self.a_max_connections:
|
if self.a_max_connections and len(cable.a_terminations) > self.a_max_connections:
|
||||||
@ -52,7 +52,7 @@ class BaseCableProfile:
|
|||||||
position = None
|
position = None
|
||||||
|
|
||||||
# Pop the position stack if necessary
|
# Pop the position stack if necessary
|
||||||
if (local_end == 'A' and self.pop_stack_a_side) or (local_end == 'B' and self.pop_stack_b_side):
|
if (local_end == 'A' and self.b_side_numbered) or (local_end == 'B' and self.a_side_numbered):
|
||||||
try:
|
try:
|
||||||
position = position_stack.pop()[0]
|
position = position_stack.pop()[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -83,14 +83,14 @@ class AToManyCableProfile(BaseCableProfile):
|
|||||||
a_max_connections = 1
|
a_max_connections = 1
|
||||||
b_max_connections = None
|
b_max_connections = None
|
||||||
symmetrical = False
|
symmetrical = False
|
||||||
pop_stack_b_side = False
|
a_side_numbered = False
|
||||||
|
|
||||||
|
|
||||||
class BToManyCableProfile(BaseCableProfile):
|
class BToManyCableProfile(BaseCableProfile):
|
||||||
a_max_connections = None
|
a_max_connections = None
|
||||||
b_max_connections = 1
|
b_max_connections = 1
|
||||||
symmetrical = False
|
symmetrical = False
|
||||||
pop_stack_a_side = False
|
b_side_numbered = False
|
||||||
|
|
||||||
|
|
||||||
class Shuffle2x2MPOCableProfile(BaseCableProfile):
|
class Shuffle2x2MPOCableProfile(BaseCableProfile):
|
||||||
|
|||||||
@ -1733,20 +1733,6 @@ class CableProfileChoices(ChoiceSet):
|
|||||||
(SHUFFLE_2X2_MPO, _('Shuffle (2x2 MPO)')),
|
(SHUFFLE_2X2_MPO, _('Shuffle (2x2 MPO)')),
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Move these designations into the profiles
|
|
||||||
A_SIDE_NUMBERED = (
|
|
||||||
STRAIGHT_SINGLE,
|
|
||||||
STRAIGHT_MULTI,
|
|
||||||
B_TO_MANY,
|
|
||||||
SHUFFLE_2X2_MPO,
|
|
||||||
)
|
|
||||||
B_SIDE_NUMBERED = (
|
|
||||||
STRAIGHT_SINGLE,
|
|
||||||
STRAIGHT_MULTI,
|
|
||||||
A_TO_MANY,
|
|
||||||
SHUFFLE_2X2_MPO,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CableTypeChoices(ChoiceSet):
|
class CableTypeChoices(ChoiceSet):
|
||||||
# Copper - Twisted Pair (UTP/STP)
|
# Copper - Twisted Pair (UTP/STP)
|
||||||
|
|||||||
@ -327,6 +327,7 @@ class Cable(PrimaryModel):
|
|||||||
Create/delete CableTerminations for this Cable to reflect its current state.
|
Create/delete CableTerminations for this Cable to reflect its current state.
|
||||||
"""
|
"""
|
||||||
a_terminations, b_terminations = self.get_terminations()
|
a_terminations, b_terminations = self.get_terminations()
|
||||||
|
profile = self.profile_class if self.profile else None
|
||||||
|
|
||||||
# Delete any stale CableTerminations
|
# Delete any stale CableTerminations
|
||||||
for termination, ct in a_terminations.items():
|
for termination, ct in a_terminations.items():
|
||||||
@ -339,11 +340,11 @@ class Cable(PrimaryModel):
|
|||||||
# Save any new CableTerminations
|
# Save any new CableTerminations
|
||||||
for i, termination in enumerate(self.a_terminations, start=1):
|
for i, termination in enumerate(self.a_terminations, start=1):
|
||||||
if not termination.pk or termination not in a_terminations:
|
if not termination.pk or termination not in a_terminations:
|
||||||
position = i if self.profile in CableProfileChoices.A_SIDE_NUMBERED else None
|
position = i if profile and profile.a_side_numbered else None
|
||||||
CableTermination(cable=self, cable_end='A', position=position, termination=termination).save()
|
CableTermination(cable=self, cable_end='A', position=position, termination=termination).save()
|
||||||
for i, termination in enumerate(self.b_terminations, start=1):
|
for i, termination in enumerate(self.b_terminations, start=1):
|
||||||
if not termination.pk or termination not in b_terminations:
|
if not termination.pk or termination not in b_terminations:
|
||||||
position = i if self.profile in CableProfileChoices.B_SIDE_NUMBERED else None
|
position = i if profile and profile.b_side_numbered else None
|
||||||
CableTermination(cable=self, cable_end='B', position=position, termination=termination).save()
|
CableTermination(cable=self, cable_end='B', position=position, termination=termination).save()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user