Skip to content

Commit ed07c08

Browse files
committed
switch to cables
1 parent 70311e6 commit ed07c08

File tree

8 files changed

+455
-28
lines changed

8 files changed

+455
-28
lines changed

generators/common.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from infrahub_sdk.protocols import CoreIPAddressPool
88
from netutils.interface import sort_interface_list
99

10-
from .schema_protocols import DcimConsoleInterface, InterfacePhysical
10+
from .schema_protocols import DcimCable, DcimConsoleInterface, InterfacePhysical
1111

1212
# Range expansion pattern from infrahub_sdk
1313
RANGE_PATTERN = re.compile(r"(\[[\w,-]*[-,][\w,-]*\])")
@@ -944,19 +944,28 @@ async def create_oob_connections(
944944
source_endpoint.description.value = (
945945
f"Connection to {' -> '.join(target_endpoint.hfid or [])}"
946946
)
947-
# Infrahub handles bidirectional connector relationships automatically
948-
source_endpoint.connector = target_endpoint.id # type: ignore[assignment]
949947
target_endpoint.status.value = "active"
950948
target_endpoint.description.value = (
951949
f"Connection to {' -> '.join(source_endpoint.hfid or [])}"
952950
)
953-
# Note: Don't set target_endpoint.connector - Infrahub creates bidirectional relationship automatically
951+
952+
# Create cable to connect the endpoints
953+
cable = await self.client.create(kind=DcimCable)
954+
cable.status.value = "connected"
955+
# Use cat6 for management/console connections
956+
cable.cable_type.value = "cat6"
957+
cable.connected_endpoints.add(source_endpoint.id)
958+
cable.connected_endpoints.add(target_endpoint.id)
959+
954960
batch.add(
955961
task=source_endpoint.save, allow_upsert=True, node=source_endpoint
956962
)
957963
batch.add(
958964
task=target_endpoint.save, allow_upsert=True, node=target_endpoint
959965
)
966+
batch.add(
967+
task=cable.save, allow_upsert=True, node=cable
968+
)
960969
try:
961970
async for node, _ in batch.execute():
962971
self.log.info(

generators/generate_dc.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from infrahub_sdk.protocols import CoreNumberPool
55

66
from .common import TopologyCreator, clean_data, safe_sort_interface_list
7-
from .schema_protocols import InterfacePhysical, InterfaceVirtual
7+
from .schema_protocols import DcimCable, InterfacePhysical, InterfaceVirtual
88

99

1010
class DCTopologyCreator(TopologyCreator):
@@ -109,21 +109,28 @@ async def create_fabric_peering(self) -> None:
109109
f"Peering connection to {' -> '.join(target_endpoint.hfid or [])}"
110110
)
111111
source_endpoint.role.value = interface_role
112-
# Infrahub handles bidirectional connector relationships automatically
113-
source_endpoint.connector = target_endpoint.id # type: ignore[assignment]
114112
target_endpoint.status.value = "active"
115113
target_endpoint.description.value = (
116114
f"Peering connection to {' -> '.join(source_endpoint.hfid or [])}"
117115
)
118116
target_endpoint.role.value = interface_role
119-
# Note: Don't set target_endpoint.connector - Infrahub creates bidirectional relationship automatically
117+
118+
# Create cable to connect the endpoints
119+
cable = await self.client.create(kind=DcimCable)
120+
cable.status.value = "connected"
121+
cable.cable_type.value = "dac-passive"
122+
cable.connected_endpoints.add(source_endpoint.id)
123+
cable.connected_endpoints.add(target_endpoint.id)
120124

121125
batch.add(
122126
task=source_endpoint.save, allow_upsert=True, node=source_endpoint
123127
)
124128
batch.add(
125129
task=target_endpoint.save, allow_upsert=True, node=target_endpoint
126130
)
131+
batch.add(
132+
task=cable.save, allow_upsert=True, node=cable
133+
)
127134

128135
async for node, _ in batch.execute():
129136
self.log.info(

generators/schema_protocols.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,18 @@ class InterfacePhysical(DcimInterface, InterfaceLayer2, InterfaceLayer3, DcimEnd
394394
pass
395395

396396

397+
class DcimConnector(CoreNode):
398+
connected_endpoints: RelationshipManager
399+
400+
401+
class DcimCable(DcimConnector):
402+
status: DropdownOptional
403+
cable_type: DropdownOptional
404+
color: DropdownOptional
405+
label: StringOptional
406+
length: IntegerOptional
407+
408+
397409
class DcimPlatform(CoreNode):
398410
ansible_network_os: StringOptional
399411
containerlab_os: StringOptional

queries/topology/cabling.gql

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,54 @@ query topology_cables($name: String!) {
1919
node {
2020
hfid
2121
display_label
22+
... on DcimCable {
23+
status {
24+
value
25+
}
26+
cable_type {
27+
value
28+
}
29+
color {
30+
value
31+
}
32+
label {
33+
value
34+
}
35+
length {
36+
value
37+
}
38+
}
39+
connected_endpoints {
40+
edges {
41+
node {
42+
__typename
43+
... on InterfacePhysical {
44+
name {
45+
value
46+
}
47+
device {
48+
node {
49+
name {
50+
value
51+
}
52+
}
53+
}
54+
}
55+
... on DcimConsoleInterface {
56+
name {
57+
value
58+
}
59+
device {
60+
node {
61+
name {
62+
value
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
2270
}
2371
}
2472
}
@@ -27,6 +75,54 @@ query topology_cables($name: String!) {
2775
node {
2876
hfid
2977
display_label
78+
... on DcimCable {
79+
status {
80+
value
81+
}
82+
cable_type {
83+
value
84+
}
85+
color {
86+
value
87+
}
88+
label {
89+
value
90+
}
91+
length {
92+
value
93+
}
94+
}
95+
connected_endpoints {
96+
edges {
97+
node {
98+
__typename
99+
... on InterfacePhysical {
100+
name {
101+
value
102+
}
103+
device {
104+
node {
105+
name {
106+
value
107+
}
108+
}
109+
}
110+
}
111+
... on DcimConsoleInterface {
112+
name {
113+
value
114+
}
115+
device {
116+
node {
117+
name {
118+
value
119+
}
120+
}
121+
}
122+
}
123+
}
124+
}
125+
}
30126
}
31127
}
32128
}

queries/topology/clab.gql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,36 @@ query topology_info($name: String!) {
8383
node {
8484
hfid
8585
display_label
86+
... on DcimCable {
87+
status {
88+
value
89+
}
90+
cable_type {
91+
value
92+
}
93+
}
94+
connected_endpoints {
95+
edges {
96+
node {
97+
__typename
98+
... on InterfacePhysical {
99+
name {
100+
value
101+
}
102+
role {
103+
value
104+
}
105+
device {
106+
node {
107+
name {
108+
value
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}
86116
}
87117
}
88118
}

0 commit comments

Comments
 (0)