@@ -110,11 +110,18 @@ def get_resource_provider_info(compute_client, placement_client):
110
110
111
111
raw_rps = list (placement_client .resource_providers ())
112
112
113
+ skip_aggregate_lookup = (
114
+ int (os .environ .get ("OS_CAPACITY_SKIP_AGGREGATE_LOOKUP" , "0" )) == 1
115
+ )
113
116
resource_providers = {}
114
117
for raw_rp in raw_rps :
115
118
rp = {"uuid" : raw_rp .id }
116
119
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
+
118
125
response = placement_client .get (
119
126
f"/resource_providers/{ raw_rp .id } /aggregates" ,
120
127
headers = {"OpenStack-API-Version" : "placement 1.19" },
@@ -311,8 +318,10 @@ def collect(self):
311
318
print (f"Collect started { collect_id } " )
312
319
guages = []
313
320
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
316
325
317
326
conn = openstack .connect ()
318
327
openstack .enable_logging (debug = False )
@@ -324,21 +333,27 @@ def collect(self):
324
333
325
334
host_time = time .perf_counter ()
326
335
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
+ )
328
339
329
340
if not skip_project_usage :
330
341
guages += get_project_usage (conn .identity , conn .placement , conn .compute )
331
342
project_time = time .perf_counter ()
332
343
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
+ )
334
347
else :
335
348
print ("2 of 3: skipping project usage" )
336
349
337
350
if not skip_project_usage :
338
351
guages += get_host_usage (resource_providers , conn .placement )
339
352
host_usage_time = time .perf_counter ()
340
353
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
+ )
342
357
else :
343
358
print ("3 of 3: skipping host usage" )
344
359
except Exception as e :
@@ -352,8 +367,8 @@ def collect(self):
352
367
353
368
if __name__ == "__main__" :
354
369
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" ),
357
372
}
358
373
prom_client .start_http_server (** kwargs )
359
374
0 commit comments