2020
2121
2222configuration = {}
23- nb_device_query_list = None
2423
2524
26- @worker_process_init .connect
27- def celery_init_worker (** kwargs ):
28- global configuration
29-
30- with open ("/etc/conductor.yml" ) as fp :
31- configuration = yaml .load (fp , Loader = yaml .SafeLoader )
32-
33- if not configuration :
34- logger .warning (
35- "The conductor configuration is empty. That's probably wrong"
36- )
37- configuration = {}
38- return
39-
40- # Resolve all IDs in the conductor.yml
41- if Config .enable_ironic .lower () in ["true" , "yes" ]:
42- if "ironic_parameters" not in configuration :
43- logger .error (
44- "ironic_parameters not found in the conductor configuration"
45- )
46- return
47-
48- if "driver_info" in configuration ["ironic_parameters" ]:
49- if "deploy_kernel" in configuration ["ironic_parameters" ]["driver_info" ]:
50- result = openstack .image_get (
51- configuration ["ironic_parameters" ]["driver_info" ][
52- "deploy_kernel"
53- ]
54- )
55- configuration ["ironic_parameters" ]["driver_info" ][
56- "deploy_kernel"
57- ] = result .id
58-
59- if (
60- "deploy_ramdisk"
61- in configuration ["ironic_parameters" ]["driver_info" ]
62- ):
63- result = openstack .image_get (
64- configuration ["ironic_parameters" ]["driver_info" ][
65- "deploy_ramdisk"
66- ]
67- )
68- configuration ["ironic_parameters" ]["driver_info" ][
69- "deploy_ramdisk"
70- ] = result .id
71-
72- if (
73- "cleaning_network"
74- in configuration ["ironic_parameters" ]["driver_info" ]
75- ):
76- result = openstack .network_get (
77- configuration ["ironic_parameters" ]["driver_info" ][
78- "cleaning_network"
79- ]
80- )
81- configuration ["ironic_parameters" ]["driver_info" ][
82- "cleaning_network"
83- ] = result .id
84-
85- if (
86- "provisioning_network"
87- in configuration ["ironic_parameters" ]["driver_info" ]
88- ):
89- result = openstack .network_get (
90- configuration ["ironic_parameters" ]["driver_info" ][
91- "provisioning_network"
92- ]
93- )
94- configuration ["ironic_parameters" ]["driver_info" ][
95- "provisioning_network"
96- ] = result .id
97-
98- global nb_device_query_list
99-
25+ def get_nb_device_query_list ():
10026 try :
10127 supported_nb_device_filters = [
10228 "site" ,
@@ -136,6 +62,74 @@ def celery_init_worker(**kwargs):
13662 logger .error (f"Unknown value in NETBOX_FILTER_LIST: { exc } " )
13763 nb_device_query_list = []
13864
65+ return nb_device_query_list
66+
67+
68+ def get_configuration ():
69+ with open ("/etc/conductor.yml" ) as fp :
70+ configuration = yaml .load (fp , Loader = yaml .SafeLoader )
71+
72+ if not configuration :
73+ logger .warning (
74+ "The conductor configuration is empty. That's probably wrong"
75+ )
76+ return {}
77+
78+ if Config .enable_ironic .lower () not in ["true" , "yes" ]:
79+ return configuration
80+
81+ if "ironic_parameters" not in configuration :
82+ logger .error ("ironic_parameters not found in the conductor configuration" )
83+ return configuration
84+
85+ if "driver_info" in configuration ["ironic_parameters" ]:
86+ if "deploy_kernel" in configuration ["ironic_parameters" ]["driver_info" ]:
87+ result = openstack .image_get (
88+ configuration ["ironic_parameters" ]["driver_info" ]["deploy_kernel" ]
89+ )
90+ configuration ["ironic_parameters" ]["driver_info" ][
91+ "deploy_kernel"
92+ ] = result .id
93+
94+ if "deploy_ramdisk" in configuration ["ironic_parameters" ]["driver_info" ]:
95+ result = openstack .image_get (
96+ configuration ["ironic_parameters" ]["driver_info" ]["deploy_ramdisk" ]
97+ )
98+ configuration ["ironic_parameters" ]["driver_info" ][
99+ "deploy_ramdisk"
100+ ] = result .id
101+
102+ if "cleaning_network" in configuration ["ironic_parameters" ]["driver_info" ]:
103+ result = openstack .network_get (
104+ configuration ["ironic_parameters" ]["driver_info" ][
105+ "cleaning_network"
106+ ]
107+ )
108+ configuration ["ironic_parameters" ]["driver_info" ][
109+ "cleaning_network"
110+ ] = result .id
111+
112+ if (
113+ "provisioning_network"
114+ in configuration ["ironic_parameters" ]["driver_info" ]
115+ ):
116+ result = openstack .network_get (
117+ configuration ["ironic_parameters" ]["driver_info" ][
118+ "provisioning_network"
119+ ]
120+ )
121+ configuration ["ironic_parameters" ]["driver_info" ][
122+ "provisioning_network"
123+ ] = result .id
124+
125+ return configuration
126+
127+
128+ @worker_process_init .connect
129+ def celery_init_worker (** kwargs ):
130+ global configuration
131+ configuration = get_configuration ()
132+
139133
140134@app .on_after_configure .connect
141135def setup_periodic_tasks (sender , ** kwargs ):
@@ -206,6 +200,7 @@ def deep_decrypt(a, vault):
206200 }
207201
208202 devices = set ()
203+ nb_device_query_list = get_nb_device_query_list ()
209204 for nb_device_query in nb_device_query_list :
210205 devices |= set (netbox .get_devices (** nb_device_query ))
211206
@@ -236,6 +231,7 @@ def deep_decrypt(a, vault):
236231 # NOTE: Find nodes in netbox which are not present in Ironic and add them
237232 for device in devices :
238233 logger .info (f"Looking for { device .name } in ironic" )
234+ logger .info (device )
239235
240236 node_interfaces = list (netbox .get_interfaces_by_device (device .name ))
241237
@@ -279,7 +275,7 @@ def deep_decrypt(a, vault):
279275 # NOTE: Render driver address field
280276 address_key = driver_params [node_attributes ["driver" ]]["address" ]
281277 if address_key in node_attributes ["driver_info" ]:
282- if "address" in device .oob_ip :
278+ if device . oob_ip and "address" in device .oob_ip :
283279 node_mgmt_address = device .oob_ip ["address" ]
284280 else :
285281 node_mgmt_addresses = [
@@ -303,9 +299,6 @@ def deep_decrypt(a, vault):
303299 )
304300 )
305301 )
306- else :
307- logger .error (f"Could not find out-of-band address for { device } " )
308- node_attributes ["driver_info" ].pop (address_key , None )
309302 node_attributes .update ({"resource_class" : device .name })
310303 ports_attributes = [
311304 dict (address = interface .mac_address )
@@ -316,9 +309,9 @@ def deep_decrypt(a, vault):
316309 lock = Redlock (
317310 key = f"lock_osism_tasks_conductor_sync_netbox_with_ironic-{ device .name } " ,
318311 masters = {utils .redis },
319- auto_release_time = 60 ,
312+ auto_release_time = 600 ,
320313 )
321- if lock .acquire (timeout = 20 ):
314+ if lock .acquire (timeout = 120 ):
322315 try :
323316 logger .info (f"Processing device { device .name } " )
324317 node = openstack .baremetal_node_show (device .name , ignore_missing = True )
0 commit comments