Skip to content

Commit 5a7f86a

Browse files
committed
Clean up cable profiles
1 parent 576c0db commit 5a7f86a

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

netbox/dcim/cable_profiles.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ class BaseCableProfile:
99
a_max_connections = None
1010
b_max_connections = None
1111

12-
# Number of A & B terminations must match
13-
symmetrical = True
14-
1512
def clean(self, cable):
13+
# Enforce maximum connection limits
1614
if self.a_max_connections and len(cable.a_terminations) > self.a_max_connections:
1715
raise ValidationError({
1816
'a_terminations': _(
@@ -31,14 +29,6 @@ def clean(self, cable):
3129
max=self.b_max_connections,
3230
)
3331
})
34-
if self.symmetrical and len(cable.a_terminations) != len(cable.b_terminations):
35-
raise ValidationError({
36-
'b_terminations': _(
37-
'Number of A and B terminations must be equal for profile {profile}'
38-
).format(
39-
profile=cable.get_profile_display(),
40-
)
41-
})
4232

4333
def get_mapped_position(self, side, position):
4434
"""
@@ -80,18 +70,19 @@ class StraightMultiCableProfile(BaseCableProfile):
8070
class Shuffle2x2MPO8CableProfile(BaseCableProfile):
8171
a_max_connections = 8
8272
b_max_connections = 8
73+
_mapping = {
74+
1: 1,
75+
2: 2,
76+
3: 5,
77+
4: 6,
78+
5: 3,
79+
6: 4,
80+
7: 7,
81+
8: 8,
82+
}
8383

8484
def get_mapped_position(self, side, position):
85-
return {
86-
1: 1,
87-
2: 2,
88-
3: 5,
89-
4: 6,
90-
5: 3,
91-
6: 4,
92-
7: 7,
93-
8: 8,
94-
}.get(position)
85+
return self._mapping.get(position)
9586

9687

9788
class Shuffle4x4MPO8CableProfile(BaseCableProfile):

netbox/dcim/tests/test_cablepaths2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,14 @@ def test_202_single_path_via_pass_through_with_breakouts(self):
377377
a_terminations=[interfaces[0], interfaces[1]],
378378
b_terminations=[frontport1],
379379
)
380+
cable1.clean()
380381
cable1.save()
381382
cable2 = Cable(
382383
profile=CableProfileChoices.STRAIGHT_MULTI,
383384
a_terminations=[rearport1],
384385
b_terminations=[interfaces[2], interfaces[3]]
385386
)
387+
cable2.clean()
386388
cable2.save()
387389

388390
paths = [
@@ -456,30 +458,35 @@ def test_204_multiple_paths_via_pass_through_with_breakouts(self):
456458
a_terminations=[interfaces[0], interfaces[1]],
457459
b_terminations=[frontport1_1]
458460
)
461+
cable1.clean()
459462
cable1.save()
460463
cable2 = Cable(
461464
profile=CableProfileChoices.STRAIGHT_MULTI,
462465
a_terminations=[interfaces[2], interfaces[3]],
463466
b_terminations=[frontport1_2]
464467
)
468+
cable2.clean()
465469
cable2.save()
466470
cable3 = Cable(
467471
profile=CableProfileChoices.STRAIGHT_SINGLE,
468472
a_terminations=[rearport1],
469473
b_terminations=[rearport2]
470474
)
475+
cable3.clean()
471476
cable3.save()
472477
cable4 = Cable(
473478
profile=CableProfileChoices.STRAIGHT_MULTI,
474479
a_terminations=[frontport2_1],
475480
b_terminations=[interfaces[4], interfaces[5]]
476481
)
482+
cable4.clean()
477483
cable4.save()
478484
cable5 = Cable(
479485
profile=CableProfileChoices.STRAIGHT_MULTI,
480486
a_terminations=[frontport2_2],
481487
b_terminations=[interfaces[6], interfaces[7]]
482488
)
489+
cable5.clean()
483490
cable5.save()
484491

485492
paths = [
@@ -592,12 +599,14 @@ def test_212_interface_to_interface_via_circuit_with_breakouts(self):
592599
a_terminations=[interfaces[0], interfaces[1]],
593600
b_terminations=[circuittermination1]
594601
)
602+
cable1.clean()
595603
cable1.save()
596604
cable2 = Cable(
597605
profile=CableProfileChoices.STRAIGHT_MULTI,
598606
a_terminations=[circuittermination2],
599607
b_terminations=[interfaces[2], interfaces[3]]
600608
)
609+
cable2.clean()
601610
cable2.save()
602611

603612
# Check for two complete paths in either direction
@@ -671,17 +680,20 @@ def test_217_interface_to_interface_via_rear_ports(self):
671680
a_terminations=[interfaces[0]],
672681
b_terminations=[front_ports[0], front_ports[1]]
673682
)
683+
cable1.clean()
674684
cable1.save()
675685
cable2 = Cable(
676686
a_terminations=[rear_ports[0], rear_ports[1]],
677687
b_terminations=[rear_ports[2], rear_ports[3]]
678688
)
689+
cable2.clean()
679690
cable2.save()
680691
cable3 = Cable(
681692
profile=CableProfileChoices.STRAIGHT_MULTI,
682693
a_terminations=[interfaces[1]],
683694
b_terminations=[front_ports[2], front_ports[3]]
684695
)
696+
cable3.clean()
685697
cable3.save()
686698

687699
# Check for one complete path in either direction
@@ -739,12 +751,14 @@ def test_223_single_path_via_multiple_pass_throughs_with_breakouts(self):
739751
a_terminations=[interfaces[0], interfaces[1]],
740752
b_terminations=[frontport1, frontport2]
741753
)
754+
cable1.clean()
742755
cable1.save()
743756
cable2 = Cable(
744757
profile=CableProfileChoices.STRAIGHT_MULTI,
745758
a_terminations=[rearport1, rearport2],
746759
b_terminations=[interfaces[2], interfaces[3]]
747760
)
761+
cable2.clean()
748762
cable2.save()
749763

750764
for path in CablePath.objects.all():

0 commit comments

Comments
 (0)