20
20
from octavia_lib .api .drivers import provider_base as driver_base
21
21
from octavia_lib .common import constants
22
22
from oslo_log import log as logging
23
+ from ovsdbapp .backend .ovs_idl import idlutils
23
24
24
25
from ovn_octavia_provider .common import clients
25
26
from ovn_octavia_provider .common import config as ovn_conf
@@ -89,7 +90,7 @@ def _check_for_allowed_cidrs(self, allowed_cidrs):
89
90
user_fault_string = msg ,
90
91
operator_fault_string = msg )
91
92
92
- def loadbalancer_create (self , loadbalancer ):
93
+ def _get_loadbalancer_request_info (self , loadbalancer ):
93
94
admin_state_up = loadbalancer .admin_state_up
94
95
if isinstance (admin_state_up , o_datamodels .UnsetType ):
95
96
admin_state_up = True
@@ -102,9 +103,12 @@ def loadbalancer_create(self, loadbalancer):
102
103
o_datamodels .UnsetType ):
103
104
request_info [constants .ADDITIONAL_VIPS ] = \
104
105
loadbalancer .additional_vips
106
+ return request_info
105
107
108
+ def loadbalancer_create (self , loadbalancer ):
106
109
request = {'type' : ovn_const .REQ_TYPE_LB_CREATE ,
107
- 'info' : request_info }
110
+ 'info' : self ._get_loadbalancer_request_info (
111
+ loadbalancer )}
108
112
self ._ovn_helper .add_request (request )
109
113
110
114
if not isinstance (loadbalancer .listeners , o_datamodels .UnsetType ):
@@ -587,10 +591,38 @@ def health_monitor_delete(self, healthmonitor):
587
591
'info' : request_info }
588
592
self ._ovn_helper .add_request (request )
589
593
594
+ def _ensure_loadbalancer (self , loadbalancer ):
595
+ try :
596
+ ovn_lbs = self ._ovn_helper ._find_ovn_lbs_with_retry (
597
+ loadbalancer .loadbalancer_id )
598
+ except idlutils .RowNotFound :
599
+ LOG .debug (f"OVN loadbalancer { loadbalancer .loadbalancer_id } "
600
+ "not found. Start create process." )
601
+ # TODO(froyo): By now just syncing LB only
602
+ status = self ._ovn_helper .lb_create (
603
+ self ._get_loadbalancer_request_info (loadbalancer ))
604
+ self ._ovn_helper ._update_status_to_octavia (status )
605
+ else :
606
+ # Load Balancer found, check LB and listener/pool/member/hms
607
+ # related
608
+ for ovn_lb in ovn_lbs :
609
+ LOG .debug (
610
+ f"Sync - Loadbalancer { loadbalancer .loadbalancer_id } "
611
+ "found checking other entities related" )
612
+ self ._ovn_helper .lb_sync (
613
+ self ._get_loadbalancer_request_info (loadbalancer ), ovn_lb )
614
+ status = self ._ovn_helper ._get_current_operating_statuses (
615
+ ovn_lb )
616
+ self ._ovn_helper ._update_status_to_octavia (status )
617
+
590
618
def do_sync (self , ** lb_filters ):
591
619
LOG .info (f"Starting sync OVN DB with Loadbalancer filter { lb_filters } " )
592
620
octavia_client = clients .get_octavia_client ()
593
621
# We can add project_id to lb_filters for lbs to limit the scope.
594
622
lbs = self ._ovn_helper .get_octavia_lbs (octavia_client , ** lb_filters )
595
623
for lb in lbs :
596
- LOG .info (f"Starting sync OVN DB with Loadbalancer { lb .id } " )
624
+ LOG .info (f"Starting sync OVN DB with Loadbalancer { lb .name } " )
625
+ provider_lb = (
626
+ self ._ovn_helper ._octavia_driver_lib .get_loadbalancer (lb .id )
627
+ )
628
+ self ._ensure_loadbalancer (provider_lb )
0 commit comments