@@ -110,11 +110,18 @@ def get_resource_provider_info(compute_client, placement_client):
110110
111111 raw_rps = list (placement_client .resource_providers ())
112112
113+ skip_aggregate_lookup = (
114+ int (os .environ .get ("OS_CAPACITY_SKIP_AGGREGATE_LOOKUP" , "0" )) == 1
115+ )
113116 resource_providers = {}
114117 for raw_rp in raw_rps :
115118 rp = {"uuid" : raw_rp .id }
116119 resource_providers [raw_rp .name ] = rp
117- # TODO - get aggregates
120+
121+ if skip_aggregate_lookup :
122+ # skip checking every resource provider for their aggregates
123+ continue
124+
118125 response = placement_client .get (
119126 f"/resource_providers/{ raw_rp .id } /aggregates" ,
120127 headers = {"OpenStack-API-Version" : "placement 1.19" },
@@ -311,8 +318,10 @@ def collect(self):
311318 print (f"Collect started { collect_id } " )
312319 guages = []
313320
314- skip_project_usage = int (os .environ .get ('OS_CAPACITY_SKIP_PROJECT_USAGE' , "0" ))
315- skip_host_usage = int (os .environ .get ('OS_CAPACITY_SKIP_HOST_USAGE' , "0" ))
321+ skip_project_usage = (
322+ int (os .environ .get ("OS_CAPACITY_SKIP_PROJECT_USAGE" , "0" )) == 1
323+ )
324+ skip_host_usage = int (os .environ .get ("OS_CAPACITY_SKIP_HOST_USAGE" , "0" )) == 1
316325
317326 conn = openstack .connect ()
318327 openstack .enable_logging (debug = False )
@@ -324,21 +333,27 @@ def collect(self):
324333
325334 host_time = time .perf_counter ()
326335 host_duration = host_time - start_time
327- print (f"1 of 3: host flavor capacity complete for { collect_id } it took { host_duration } seconds" )
336+ print (
337+ f"1 of 3: host flavor capacity complete for { collect_id } it took { host_duration } seconds"
338+ )
328339
329340 if not skip_project_usage :
330341 guages += get_project_usage (conn .identity , conn .placement , conn .compute )
331342 project_time = time .perf_counter ()
332343 project_duration = project_time - host_time
333- print (f"2 of 3: project usage complete for { collect_id } it took { project_duration } seconds" )
344+ print (
345+ f"2 of 3: project usage complete for { collect_id } it took { project_duration } seconds"
346+ )
334347 else :
335348 print ("2 of 3: skipping project usage" )
336349
337350 if not skip_project_usage :
338351 guages += get_host_usage (resource_providers , conn .placement )
339352 host_usage_time = time .perf_counter ()
340353 host_usage_duration = host_usage_time - project_time
341- print (f"3 of 3: host usage complete for { collect_id } it took { host_usage_duration } seconds" )
354+ print (
355+ f"3 of 3: host usage complete for { collect_id } it took { host_usage_duration } seconds"
356+ )
342357 else :
343358 print ("3 of 3: skipping host usage" )
344359 except Exception as e :
@@ -352,8 +367,8 @@ def collect(self):
352367
353368if __name__ == "__main__" :
354369 kwargs = {
355- "port" : int (os .environ .get (' OS_CAPACITY_EXPORTER_PORT' , 9000 )),
356- "addr" : os .environ .get (' OS_CAPACITY_EXPORTER_LISTEN_ADDRESS' , ' 0.0.0.0' ),
370+ "port" : int (os .environ .get (" OS_CAPACITY_EXPORTER_PORT" , 9000 )),
371+ "addr" : os .environ .get (" OS_CAPACITY_EXPORTER_LISTEN_ADDRESS" , " 0.0.0.0" ),
357372 }
358373 prom_client .start_http_server (** kwargs )
359374
0 commit comments