From caf12fd025755df745bc18b46fb9ef655dfb2dab Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 26 Jan 2023 16:06:02 +0000 Subject: [PATCH 1/3] Skip adding memory and disk for baremetal flavors --- os_capacity/prometheus.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/os_capacity/prometheus.py b/os_capacity/prometheus.py index 6b8c407..2242b33 100755 --- a/os_capacity/prometheus.py +++ b/os_capacity/prometheus.py @@ -18,8 +18,15 @@ def get_capacity_per_flavor(placement_client, flavors): def get_placement_request(flavor): - resources = {"MEMORY_MB": flavor.ram, "DISK_GB": (flavor.disk + flavor.ephemeral)} + resources = {} required_traits = [] + + def add_defaults(resources, flavor, skip_vcpu=False): + resources["MEMORY_MB"] = flavor.ram + resources["DISK_GB"] = (flavor.disk + flavor.ephemeral)} + if not skip_vcpu: + resources["VCPU"] = flavor.vcpus + for key, value in flavor.extra_specs.items(): if "trait:" == key[:6]: if value == "required": @@ -29,8 +36,13 @@ def get_placement_request(flavor): resources[key[10:]] = count if "hw:cpu_policy" == key and value == "dedicated": resources["PCPU"] = flavor.vcpus - if "PCPU" not in resources.keys() and "VCPU" not in resources.keys(): - resources["VCPU"] = flavor.vcpus + add_defaults(resources, flavor, skip_vcpu=True) + + # if not baremetal and not PCPU + # we should add the default vcpu ones + if not resources: + add_defaults(resources, flavor) + return resources, required_traits From 5f6aa82128c308298909acfbab33b31a218f86ae Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 26 Jan 2023 18:17:05 +0000 Subject: [PATCH 2/3] fix up syntax --- os_capacity/prometheus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os_capacity/prometheus.py b/os_capacity/prometheus.py index 2242b33..7f60400 100755 --- a/os_capacity/prometheus.py +++ b/os_capacity/prometheus.py @@ -23,7 +23,7 @@ def get_placement_request(flavor): def add_defaults(resources, flavor, skip_vcpu=False): resources["MEMORY_MB"] = flavor.ram - resources["DISK_GB"] = (flavor.disk + flavor.ephemeral)} + resources["DISK_GB"] = flavor.disk + flavor.ephemeral if not skip_vcpu: resources["VCPU"] = flavor.vcpus From 0ddb34d725e50440e5b086739e803eec0f7ae590 Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 26 Jan 2023 18:31:27 +0000 Subject: [PATCH 3/3] Add some debug info --- os_capacity/prometheus.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/os_capacity/prometheus.py b/os_capacity/prometheus.py index 7f60400..d607fd8 100755 --- a/os_capacity/prometheus.py +++ b/os_capacity/prometheus.py @@ -73,7 +73,10 @@ def get_max_per_host(placement_client, resources, required_traits): # available count is the min of the max counts if max_counts: count_per_rp[rp_uuid] = min(max_counts) - + if not count_per_rp: + print( + f"# WARNING - no candidates for resources:{resource_str} traits:{required_str}" + ) return count_per_rp @@ -148,6 +151,7 @@ def print_details(compute_client, placement_client): for hostname in hostnames: rp = resource_providers[hostname] rp_id = rp["uuid"] + free_space_found = False for flavor_name in flavor_names: all_counts = capacity_per_flavor.get(flavor_name, {}) our_count = all_counts.get(rp_id, 0) @@ -163,6 +167,9 @@ def print_details(compute_client, placement_client): print( f'openstack_capacity_by_hostname{{{host_str},flavor="{flavor_name}"}} {our_count}' ) + free_space_found = True + if not free_space_found: + print(f"# WARNING - no free spaces found for {hostname}") for project, names in project_to_aggregate.items(): for name in names: