Skip to content

Commit

Permalink
add delete port handling for ports in tenant networks
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Fencik committed Nov 28, 2024
1 parent 46f06cf commit af1480e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
17 changes: 17 additions & 0 deletions python/neutron-understack/neutron_understack/nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ def prep_switch_interface(

return resp_data["vlan_group_id"]

def detach_port(self, connected_interface_id: str, ucvni_uuid: str) -> str:
"""Runs a Nautobot Job to cleanup a switch interface.
The nautobot job will find a VLAN that is bound to the UCVNI, remove it
from the Interface and if the VLAN is unused it will delete it.
The vlan group ID is returned.
"""
url = "/api/plugins/undercloud-vni/detach_port"
payload = {
"ucvni_uuid": str(ucvni_uuid),
"connected_interface_id": str(connected_interface_id),
}
resp_data = self.make_api_request(url, "post", payload)

return resp_data["vlan_group_id"]

def configure_port_status(self, interface_uuid: str, status: str) -> dict:
url = f"/api/dcim/interfaces/{interface_uuid}/"
payload = {"status": {"name": status}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,8 @@ def update_port_precommit(self, context):

def update_port_postcommit(self, context):
log_call("update_port_postcommit", context)
print("Original context: ")
pprint(context.original)
print("Binding levels: ")
pprint(context.binding_levels)

self._delete_tenant_port_on_unbound(context)

vif_type = context.current["binding:vif_type"]

Expand Down Expand Up @@ -340,3 +338,31 @@ def update_nautobot(self, network_id: str, connected_interface_uuid: str) -> UUI
return UUID(
self.nb.prep_switch_interface(connected_interface_uuid, network_id)
)

def _delete_tenant_port_on_unbound(self, context):
"""Tenant network port cleanup in the UnderCloud infrastructure.
This is triggered in the update_port_postcommit call as in the
delete_port_postcommit call there is no binding profile information
anymore, hence there is no way for us to identify which baremetal port
needs cleanup.
Only in the update_port_postcommit we have access to the original context,
from which we can access the binding information.
"""
if (
context.current["binding:vnic_type"] == "baremetal"
and context.vif_type == portbindings.VIF_TYPE_UNBOUND
and context.original_vif_type == portbindings.VIF_TYPE_OTHER
):
connected_interface_uuid = self.fetch_connected_interface_uuid(
context.original
)
network_id = context.current["network_id"]
nb_vlan_group_id = UUID(
self.nb.detach_port(connected_interface_uuid, network_id)
)
self.undersync.sync_devices(
vlan_group_uuids=str(nb_vlan_group_id),
dry_run=cfg.CONF.ml2_understack.undersync_dry_run,
)

0 comments on commit af1480e

Please sign in to comment.