22from uuid import UUID
33
44import neutron_lib .api .definitions .portbindings as portbindings
5+ from neutron .plugins .ml2 .driver_context import PortContext
56from neutron_lib import constants as p_const
67from neutron_lib .plugins .ml2 import api
78from neutron_lib .plugins .ml2 .api import MechanismDriver
@@ -223,31 +224,6 @@ def _configure_trunk(
223224 def update_port_postcommit (self , context ):
224225 self ._delete_tenant_port_on_unbound (context )
225226
226- vif_type = context .current ["binding:vif_type" ]
227-
228- if vif_type != portbindings .VIF_TYPE_OTHER :
229- return
230-
231- trunk_details = context .current .get ("trunk_details" , {})
232- network_id = context .current ["network_id" ]
233- network_type = context .network .current .get ("provider:network_type" )
234- connected_interface_uuid = self .fetch_connected_interface_uuid (context .current )
235-
236- if trunk_details :
237- self ._configure_trunk (trunk_details , connected_interface_uuid )
238- if network_type == p_const .TYPE_VLAN :
239- vlan_tag = int (context .network .current .get ("provider:segmentation_id" ))
240- else :
241- vlan_tag = None
242- nb_vlan_group_id = self .update_nautobot (
243- network_id , connected_interface_uuid , vlan_tag
244- )
245-
246- self .undersync .sync_devices (
247- vlan_group_uuids = str (nb_vlan_group_id ),
248- dry_run = cfg .CONF .ml2_understack .undersync_dry_run ,
249- )
250-
251227 def delete_port_precommit (self , context ):
252228 pass
253229
@@ -273,7 +249,28 @@ def delete_port_postcommit(self, context):
273249 dry_run = cfg .CONF .ml2_understack .undersync_dry_run ,
274250 )
275251
276- def bind_port (self , context ):
252+ def _configure_switchport_on_bind (self , context : PortContext ) -> None :
253+ trunk_details = context .current .get ("trunk_details" , {})
254+ network_id = context .current ["network_id" ]
255+ network_type = context .network .current .get ("provider:network_type" )
256+ connected_interface_uuid = self .fetch_connected_interface_uuid (context .current )
257+
258+ if trunk_details :
259+ self ._configure_trunk (trunk_details , connected_interface_uuid )
260+ if network_type == p_const .TYPE_VLAN :
261+ vlan_tag = int (context .network .current .get ("provider:segmentation_id" ))
262+ else :
263+ vlan_tag = None
264+ nb_vlan_group_id = self .update_nautobot (
265+ network_id , connected_interface_uuid , vlan_tag
266+ )
267+
268+ self .undersync .sync_devices (
269+ vlan_group_uuids = str (nb_vlan_group_id ),
270+ dry_run = cfg .CONF .ml2_understack .undersync_dry_run ,
271+ )
272+
273+ def bind_port (self , context : PortContext ) -> None :
277274 for segment in context .network .network_segments :
278275 if self .check_segment (segment ):
279276 context .set_binding (
@@ -283,6 +280,7 @@ def bind_port(self, context):
283280 status = p_const .PORT_STATUS_ACTIVE ,
284281 )
285282 LOG .debug ("Bound segment: %s" , segment )
283+ self ._configure_switchport_on_bind (context )
286284 return
287285 else :
288286 LOG .debug (
0 commit comments