Skip to content

Commit c8459e5

Browse files
Milan FencikMilan Fencik
authored andcommitted
add method for trunk driver to check if vlan segment is present for current physnet
1 parent 7b72a57 commit c8459e5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

python/neutron-understack/neutron_understack/trunk.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ def _handle_segment_allocation(
171171
subport_network_id = utils.fetch_subport_network_id(
172172
subport_id=subport["port_id"]
173173
)
174-
network_segment = utils.allocate_dynamic_segment(
174+
current_segment = utils.network_segment_by_physnet(
175+
network_id=subport_network_id,
176+
physnet=vlan_group_name,
177+
)
178+
network_segment = current_segment or utils.allocate_dynamic_segment(
175179
network_id=subport_network_id,
176180
physnet=vlan_group_name,
177181
)

python/neutron-understack/neutron_understack/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ def network_segment_by_id(id: str) -> NetworkSegment:
7777
return NetworkSegment.get_object(context, id=id)
7878

7979

80+
def network_segment_by_physnet(network_id: str, physnet: str) -> NetworkSegment | None:
81+
"""Fetches vlan network segments for network in particular physnet.
82+
83+
We return first segment on purpose, there shouldn't be more, but if
84+
that is the case, it may be intended for some reason and we don't want
85+
to halt the code.
86+
"""
87+
context = n_context.get_admin_context()
88+
89+
segments = NetworkSegment.get_objects(
90+
context,
91+
network_id=network_id,
92+
physical_network=physnet,
93+
network_type=constants.TYPE_VLAN,
94+
)
95+
if not segments:
96+
return
97+
return segments[0]
98+
99+
80100
def release_dynamic_segment(segment_id: str) -> None:
81101
context = n_context.get_admin_context()
82102
core_plugin = directory.get_plugin() # Get the core plugin

0 commit comments

Comments
 (0)