File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
python/neutron-understack/neutron_understack Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,11 @@ def _handle_segment_allocation(
171
171
subport_network_id = utils .fetch_subport_network_id (
172
172
subport_id = subport ["port_id" ]
173
173
)
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 (
175
179
network_id = subport_network_id ,
176
180
physnet = vlan_group_name ,
177
181
)
Original file line number Diff line number Diff line change @@ -77,6 +77,26 @@ def network_segment_by_id(id: str) -> NetworkSegment:
77
77
return NetworkSegment .get_object (context , id = id )
78
78
79
79
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
+
80
100
def release_dynamic_segment (segment_id : str ) -> None :
81
101
context = n_context .get_admin_context ()
82
102
core_plugin = directory .get_plugin () # Get the core plugin
You can’t perform that action at this time.
0 commit comments