Skip to content

Commit cc04cda

Browse files
authored
Merge pull request #899 from rackerlabs/PUC-904
feat: refactor mechanism driver part 1
2 parents fa470d1 + f1fa10a commit cc04cda

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

python/neutron-understack/neutron_understack/ml2_type_annotations.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ class PortContext:
163163
segments_to_bind: Any
164164

165165
def set_binding(
166-
self, new_segment: str, vif_type: str, _: dict, status: str
166+
self, segment_id: str, vif_type: str, vif_details: dict, status: str
167167
) -> None: ...
168168

169+
def allocate_dynamic_segment(self, segment: dict) -> dict: ...
170+
171+
def release_dynamic_segment(self, segment_id: str) -> dict: ...
172+
169173

170174
class BindingLevelsDict(TypedDict):
171175
bound_driver: Literal["understack"]

python/neutron-understack/neutron_understack/neutron_understack_mech.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -229,25 +229,15 @@ def create_port_postcommit(self, context):
229229
def update_port_precommit(self, context):
230230
pass
231231

232-
def update_port_postcommit(self, context):
233-
"""Tenant network port cleanup in the UnderCloud infrastructure.
234-
235-
This is triggered in the update_port_postcommit call as in the
236-
delete_port_postcommit call there is no binding profile information
237-
anymore, hence there is no way for us to identify which baremetal port
238-
needs cleanup.
232+
def update_port_postcommit(self, context: PortContext) -> None:
233+
if utils.is_baremetal_port(context):
234+
self._update_port_baremetal(context)
239235

240-
Only in the update_port_postcommit do we have access to the original
241-
context, from which we can access the binding information.
242-
"""
243-
baremetal_vnic = context.current["binding:vnic_type"] == "baremetal"
236+
def _update_port_baremetal(self, context: PortContext) -> None:
244237
current_vif_unbound = context.vif_type == portbindings.VIF_TYPE_UNBOUND
245238
original_vif_other = context.original_vif_type == portbindings.VIF_TYPE_OTHER
246239
current_vif_other = context.vif_type == portbindings.VIF_TYPE_OTHER
247240

248-
if not baremetal_vnic:
249-
return
250-
251241
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
252242
context.current["mac_address"]
253243
)
@@ -260,6 +250,16 @@ def update_port_postcommit(self, context):
260250
self.invoke_undersync(vlan_group_name)
261251

262252
def _tenant_network_port_cleanup(self, context: PortContext):
253+
"""Tenant network port cleanup in the UnderCloud infrastructure.
254+
255+
This is triggered in the update_port_postcommit call as in the
256+
delete_port_postcommit call there is no binding profile information
257+
anymore, hence there is no way for us to identify which baremetal port
258+
needs cleanup.
259+
260+
Only in the update_port_postcommit do we have access to the original
261+
context, from which we can access the binding information.
262+
"""
263263
trunk_details = context.current.get("trunk_details", {})
264264
segment_id = context.original_top_bound_segment["id"]
265265
original_binding = context.original["binding:profile"]
@@ -293,13 +293,13 @@ def _tenant_network_port_cleanup(self, context: PortContext):
293293
def delete_port_precommit(self, context):
294294
pass
295295

296-
def delete_port_postcommit(self, context):
297-
# Only clean up provisioning ports. Everything else is left to get
298-
# cleaned up upon the next change in that cabinet.
296+
def delete_port_postcommit(self, context: PortContext) -> None:
297+
if utils.is_baremetal_port(context):
298+
self._delete_port_baremetal(context)
299299

300-
baremetal_vnic = context.current["binding:vnic_type"] == "baremetal"
301-
if not baremetal_vnic:
302-
return
300+
def _delete_port_baremetal(self, context: PortContext) -> None:
301+
# Only clean up provisioning ports. Ports with tenant networks are cleaned
302+
# up in _tenant_network_port_cleanup
303303

304304
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
305305
context.current["mac_address"]

python/neutron-understack/neutron_understack/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from neutron_lib.api.definitions import segment as segment_def
99
from neutron_lib.plugins import directory
1010

11+
from neutron_understack.ml2_type_annotations import PortContext
1112
from neutron_understack.nautobot import Nautobot
1213

1314

@@ -112,7 +113,7 @@ def parent_port_is_bound(port: port_obj.Port) -> bool:
112113
return bool(
113114
port_binding
114115
and port_binding.vif_type == portbindings.VIF_TYPE_OTHER
115-
and port_binding.vnic_type == "baremetal"
116+
and port_binding.vnic_type == portbindings.VNIC_BAREMETAL
116117
and port_binding.profile
117118
)
118119

@@ -127,3 +128,7 @@ def is_valid_vlan_network_segment(network_segment: dict):
127128
network_segment.get(segment_def.NETWORK_TYPE) == constants.TYPE_VLAN
128129
and network_segment.get(segment_def.PHYSICAL_NETWORK) is not None
129130
)
131+
132+
133+
def is_baremetal_port(context: PortContext) -> bool:
134+
return context.current[portbindings.VNIC_TYPE] == portbindings.VNIC_BAREMETAL

0 commit comments

Comments
 (0)