@@ -627,7 +627,6 @@ def __init__(self, driver):
627627 @log_helpers .log_method_call
628628 def create (self , context , loadbalancer ):
629629 """Create a loadbalancer."""
630-
631630 self ._log_entity (loadbalancer )
632631
633632 driver = self .driver
@@ -638,7 +637,6 @@ def create(self, context, loadbalancer):
638637 service = {}
639638 agent , device = self ._schedule_agent_and_device (
640639 context , loadbalancer )
641- agent_host = agent ['host' ]
642640 agent_config = agent .get ('configurations' , {})
643641 LOG .debug ("agent configurations: %s" % agent_config )
644642
@@ -647,54 +645,14 @@ def create(self, context, loadbalancer):
647645 context .session .expire (agent , ['heartbeat_timestamp' ])
648646 LOG .info (agent )
649647
650- # Update the port for the VIP to show ownership by this driver
651- port_data = {
652- 'admin_state_up' : True ,
653- 'device_owner' : 'network:f5lbaasv2' ,
654- 'status' : n_const .PORT_STATUS_ACTIVE
655- }
656- port_data [portbindings .HOST_ID ] = agent_host
657- port_data [portbindings .VNIC_TYPE ] = "baremetal"
658-
659- port_data [portbindings .PROFILE ] = {}
660-
661- device_info = device .get ('device_info' )
662-
663- vip_masq_mac = device_info .get ('masquerade_mac' )
664- if not vip_masq_mac :
665- LOG .error (
666- "Can not find masquerade_mac in device %s, when"
667- " creating loadbalancer %s." % (
668- device , loadbalancer
669- )
670- )
671-
672- # llinfo is a list of dict type
673- llinfo = device_info .get ('local_link_information' )
674-
675- if llinfo :
676- link_info = llinfo [0 ]
677- else :
678- link_info = dict ()
679- llinfo = [link_info ]
680-
681- link_info .update ({"lb_mac" : vip_masq_mac })
682-
683- port_data [portbindings .PROFILE ] = {
684- "local_link_information" : llinfo
685- }
686-
687- driver .plugin .db ._core_plugin .update_port (
688- context ,
689- loadbalancer .vip_port_id ,
690- {'port' : port_data }
691- )
648+ self .update_vipport_attrs (context , agent , device , loadbalancer )
692649
693650 # NOTE(qzhao): Vlan id might be assigned after updating vip
694651 # port. Need to build service payload after updating port.
695652 service = self ._create_service (context , loadbalancer , agent )
696653 service ["device" ] = device
697654
655+ agent_host = agent ['host' ]
698656 driver .agent_rpc .create_loadbalancer (
699657 context , loadbalancer .to_api_dict (), service , agent_host )
700658 except Exception as e :
@@ -758,7 +716,71 @@ def delete(self, context, loadbalancer):
758716 self ._handle_entity_error (context , loadbalancer .id )
759717 raise e
760718
761- # Temporarily utilize this interface to implement loadbalancer rebuild
719+ def update_vipport_attrs (self , context , agent , device , loadbalancer ):
720+
721+ driver = self .driver
722+
723+ agent_host = agent ["host" ]
724+ # Update the port for the VIP to show ownership by this driver
725+ port_data = {
726+ 'admin_state_up' : True ,
727+ 'device_owner' : 'network:f5lbaasv2' ,
728+ 'status' : n_const .PORT_STATUS_ACTIVE
729+ }
730+ port_data [portbindings .HOST_ID ] = agent_host
731+ port_data [portbindings .VNIC_TYPE ] = "baremetal"
732+ port_data [portbindings .PROFILE ] = {}
733+
734+ device_info = device .get ('device_info' )
735+
736+ vip_masq_mac = device_info .get ('masquerade_mac' )
737+ if not vip_masq_mac :
738+ LOG .error (
739+ "Can not find masquerade_mac in device %s, when"
740+ " migrating loadbalancer %s." % (
741+ device , loadbalancer
742+ )
743+ )
744+
745+ # llinfo is a list of dict type
746+ llinfo = device_info .get ('local_link_information' )
747+
748+ if llinfo :
749+ link_info = llinfo [0 ]
750+ else :
751+ link_info = dict ()
752+ llinfo = [link_info ]
753+
754+ link_info .update ({"lb_mac" : vip_masq_mac })
755+
756+ port_data [portbindings .PROFILE ] = {
757+ "local_link_information" : llinfo
758+ }
759+
760+ # pzhang migrate
761+ driver .plugin .db ._core_plugin .update_port (
762+ context ,
763+ loadbalancer .vip_port_id ,
764+ {'port' : port_data }
765+ )
766+
767+ def migrate_vipport (self , context , agent , device , loadbalancer ):
768+
769+ driver = self .driver
770+
771+ LOG .info ("erase device_owner of vip port %s" %
772+ loadbalancer .vip_port_id )
773+
774+ driver .plugin .db ._core_plugin .update_port (
775+ context ,
776+ loadbalancer .vip_port_id ,
777+ {"port" : {"device_owner" : "" }}
778+ )
779+
780+ LOG .info ("reassign attributes of vip port %s" %
781+ loadbalancer .vip_port_id )
782+ self .update_vipport_attrs (context , agent , device , loadbalancer )
783+
762784 @log_helpers .log_method_call
763785 def refresh (self , context , body ):
764786 """Refresh a loadbalancer."""
@@ -780,6 +802,9 @@ def refresh(self, context, body):
780802 service ["device" ] = device
781803 agent_host = agent ['host' ]
782804
805+ if device_id :
806+ self .migrate_vipport (context , agent , device , loadbalancer )
807+
783808 if rebuild_all :
784809 self ._allocate_acl_groups (context , service )
785810 driver .agent_rpc .rebuild_loadbalancer (
0 commit comments