@@ -327,6 +327,7 @@ def _translate_pool(self, p_res):
327
327
)
328
328
329
329
def create_health_monitor (hm_obj ):
330
+ print (" Creating health monitor res for {}" .format (p_res .name ))
330
331
hm_res_values = dict ()
331
332
attr_name_lst = [
332
333
'created_at' , 'updated_at' , 'action' , 'status' ,
@@ -350,12 +351,15 @@ def create_health_monitor(hm_obj):
350
351
hm_res_values ['properties_data_encrypted' ] = 0
351
352
352
353
hm_res_pd = dict ()
353
- # TODO: session persistance
354
354
hm_res_pd ["delay" ] = hm_obj .delay
355
355
hm_res_pd ["type" ] = hm_obj .type
356
356
hm_res_pd ["max_retries" ] = hm_obj .max_retries
357
357
hm_res_pd ["timeout" ] = hm_obj .timeout
358
- hm_res_pd ["pool" ] = hm_obj .pool
358
+ hm_res_pd ["pool" ] = p_res .nova_instance
359
+ if hm_obj .type == 'HTTP' or hm_obj .type == 'HTTPS' :
360
+ hm_res_pd ['http_method' ] = hm_obj .http_method
361
+ hm_res_pd ['expected_codes' ] = hm_obj .expected_codes
362
+ hm_res_pd ['url_path' ] = hm_obj .url_path
359
363
hm_res_values ['properties_data' ] = hm_res_pd
360
364
361
365
hm_res = Resource .create (hctxt (), hm_res_values )
@@ -369,20 +373,16 @@ def delete_health_monitor(hm_res_name, hm_res):
369
373
370
374
if 'monitors' in p_properties :
371
375
p_obj = self .lbaasv2_data .get_pool (p_res .nova_instance )
376
+
372
377
# this is the only used hm after the data migration
373
378
active_hm_id = p_obj .healthmonitor_id
379
+ if not active_hm_id :
380
+ return
374
381
375
- for mon in p_properties ['monitors' ]:
376
- if isinstance (mon , str ):
377
- hm_obj = self .lbaasv2_data .get_health_monitor (
378
- p_obj .healthmonitor_id )
379
- if hm_obj .id == active_hm_id :
380
- create_health_monitor (hm_obj )
381
- elif isinstance (mon , dict ) and 'get_resource' in mon :
382
- hm_res_name = mon ['get_resource' ]
383
- hm_res = self .res_dict ['HealthMonitor' ][hm_res_name ]
384
- if hm_res .nova_instance != active_hm_id :
385
- delete_health_monitor (hm_res_name , hm_res )
382
+ hm_res_name = self .get_resource_name ('HealthMonitor' , active_hm_id )
383
+ if not hm_res_name :
384
+ hm_obj = self .lbaasv2_data .get_health_monitor (active_hm_id )
385
+ create_health_monitor (hm_obj )
386
386
387
387
def _handle_no_lb_case (self , p_res ):
388
388
def respective_lb_res_exists ():
@@ -563,20 +563,27 @@ def _finalize_and_save(self):
563
563
res .update_and_save (
564
564
{'properties_data' : res .properties_data })
565
565
566
- if res_type == 'LoadBalancer' :
566
+ if res_type == 'Pool' :
567
+ res .update_and_save (
568
+ {'rsrc_metadata' : {}})
569
+ elif res_type == 'LoadBalancer' :
567
570
res .update_and_save (
568
571
{'nova_instance' : self ._lb_id [res_name ]})
569
572
elif res_type == 'HealthMonitor' and not res .nova_instance :
570
573
res .update_and_save (
571
574
{'nova_instance' : None })
572
575
573
576
def get_resource_prop_name (self , res_type , nova_instance ):
577
+ if res_type not in self .res_dict :
578
+ return None
574
579
for res_name , res in self .res_dict [res_type ].items ():
575
580
if res .nova_instance == nova_instance :
576
581
return res .name
577
582
return None
578
583
579
584
def get_resource_name (self , res_type , nova_instance ):
585
+ if res_type not in self .res_dict :
586
+ return None
580
587
for res_name , res in self .res_dict [res_type ].items ():
581
588
if res .nova_instance == nova_instance :
582
589
return res_name
@@ -628,14 +635,17 @@ def create_health_monitor(hm_res_name):
628
635
t_hm_res_p ['type' ] = hm_res_p ['type' ]
629
636
t_hm_res_p ['max_retries' ] = hm_res_p ['max_retries' ]
630
637
t_hm_res_p ['timeout' ] = hm_res_p ['timeout' ]
631
- #TODO: test again!
632
638
t_hm_res_p ['pool' ] = {
633
639
'get_resource' :
634
640
self .res_handler .get_resource_name (
635
641
'Pool' ,
636
642
hm_res_p ['pool' ]
637
643
)
638
644
}
645
+ if hm_res_p ['type' ] == 'HTTP' or hm_res_p ['type' ] == 'HTTPS' :
646
+ t_hm_res_p ['http_method' ] = hm_res_p ['http_method' ]
647
+ t_hm_res_p ['expected_codes' ] = hm_res_p ['expected_codes' ]
648
+ t_hm_res_p ['url_path' ] = hm_res_p ['url_path' ]
639
649
self .resources [hm_res_name ] = dict ()
640
650
self .resources [hm_res_name ]['properties' ] = t_hm_res_p
641
651
self .resources [hm_res_name ]['type' ] = (
0 commit comments