@@ -376,7 +376,7 @@ def update_port_postcommit(self, context):
376
376
{'switch_port' : port_id , 'switch_info' : switch_info ,
377
377
'segmentation_id' : segmentation_id })
378
378
# Move port to network
379
- if is_802_3ad and hasattr ( switch , 'plug_bond_to_network' ) :
379
+ if is_802_3ad :
380
380
switch .plug_bond_to_network (port_id , segmentation_id )
381
381
else :
382
382
switch .plug_port_to_network (port_id , segmentation_id )
@@ -466,6 +466,10 @@ def bind_port(self, context):
466
466
can use with ports.
467
467
"""
468
468
469
+ # NOTE(vsaienko): Important that this method remains lightweight.
470
+ # The actual port handling is done in update_port_postcommit.
471
+ # For more info please read docstring.
472
+
469
473
port = context .current
470
474
network = context .network .current
471
475
binding_profile = port ['binding:profile' ]
@@ -477,44 +481,7 @@ def bind_port(self, context):
477
481
if not self ._is_link_valid (port , network ):
478
482
return
479
483
480
- is_802_3ad = self ._is_802_3ad (port )
481
- for link in local_link_information :
482
- port_id = link .get ('port_id' )
483
- switch_info = link .get ('switch_info' )
484
- switch_id = link .get ('switch_id' )
485
- switch = device_utils .get_switch_device (
486
- self .switches , switch_info = switch_info ,
487
- ngs_mac_address = switch_id )
488
-
489
- segments = context .segments_to_bind
490
- # If segmentation ID is None, set vlan 1
491
- segmentation_id = segments [0 ].get ('segmentation_id' ) or 1
492
-
493
- # Fail if port or vlan not in allow list
494
- if not switch .is_allowed (port_id , segmentation_id ):
495
- LOG .warn ("Skipped binding port %(port_id)s, "
496
- "port %(port)s in segment "
497
- "%(segment_id)s on device %(device)s, as either "
498
- "the port or vlan is not on the allow list" ,
499
- {'port_id' : port ['id' ], 'port' : port_id ,
500
- 'device' : switch_info ,
501
- 'segment_id' : segmentation_id })
502
- return
503
-
504
- LOG .debug ("Putting port %(port_id)s on %(switch_info)s "
505
- "to vlan: %(segmentation_id)s" ,
506
- {'port_id' : port_id , 'switch_info' : switch_info ,
507
- 'segmentation_id' : segmentation_id })
508
- # Move port to network
509
- if is_802_3ad and hasattr (switch , 'plug_bond_to_network' ):
510
- switch .plug_bond_to_network (port_id , segmentation_id )
511
- else :
512
- switch .plug_port_to_network (port_id , segmentation_id )
513
- LOG .info ("Successfully bound port %(port_id)s in segment "
514
- "%(segment_id)s on device %(device)s" ,
515
- {'port_id' : port ['id' ], 'device' : switch_info ,
516
- 'segment_id' : segmentation_id })
517
-
484
+ segments = context .segments_to_bind
518
485
context .set_binding (segments [0 ][api .ID ],
519
486
portbindings .VIF_TYPE_OTHER , {})
520
487
@@ -540,6 +507,7 @@ def _is_link_valid(self, port, network):
540
507
local_link_information = binding_profile .get ('local_link_information' )
541
508
542
509
for link in local_link_information :
510
+ port_id = link .get ('port_id' )
543
511
switch_info = link .get ('switch_info' )
544
512
switch_id = link .get ('switch_id' )
545
513
switch = device_utils .get_switch_device (
@@ -555,6 +523,7 @@ def _is_link_valid(self, port, network):
555
523
556
524
physnet = network ['provider:physical_network' ]
557
525
switch_physnets = switch ._get_physical_networks ()
526
+ segmentation_id = network .get ('provider:segmentation_id' ) or 1
558
527
559
528
if switch_physnets and physnet not in switch_physnets :
560
529
LOG .error ("Cannot bind port %(port)s as device %(device)s "
@@ -563,6 +532,17 @@ def _is_link_valid(self, port, network):
563
532
{'port' : port ['id' ], 'device' : switch_info ,
564
533
'physnet' : physnet })
565
534
return False
535
+
536
+ # Fail if port or vlan not in allow list
537
+ if not switch .is_allowed (port_id , segmentation_id ):
538
+ LOG .warn ("Skipped binding port %(port_id)s, "
539
+ "port %(port)s in segment "
540
+ "%(segment_id)s on device %(device)s, as either "
541
+ "the port or vlan is not on the allow list" ,
542
+ {'port_id' : port ['id' ], 'port' : port_id ,
543
+ 'device' : switch_info ,
544
+ 'segment_id' : segmentation_id })
545
+ return False
566
546
return True
567
547
568
548
@staticmethod
@@ -639,7 +619,7 @@ def _unplug_port_from_network(self, port, network):
639
619
{'port' : port_id , 'switch_info' : switch_info ,
640
620
'segmentation_id' : segmentation_id })
641
621
try :
642
- if is_802_3ad and hasattr ( switch , 'unplug_bond_from_network' ) :
622
+ if is_802_3ad :
643
623
switch .unplug_bond_from_network (port_id , segmentation_id )
644
624
else :
645
625
switch .delete_port (port_id , segmentation_id )
0 commit comments