Skip to content

Commit fc776c7

Browse files
authored
Skip adding memory and disk for baremetal flavors (#6)
* Skip adding memory and disk for baremetal flavors * fix up syntax * Add some debug info
1 parent 32a541c commit fc776c7

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

os_capacity/prometheus.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ def get_capacity_per_flavor(placement_client, flavors):
1818

1919

2020
def get_placement_request(flavor):
21-
resources = {"MEMORY_MB": flavor.ram, "DISK_GB": (flavor.disk + flavor.ephemeral)}
21+
resources = {}
2222
required_traits = []
23+
24+
def add_defaults(resources, flavor, skip_vcpu=False):
25+
resources["MEMORY_MB"] = flavor.ram
26+
resources["DISK_GB"] = flavor.disk + flavor.ephemeral
27+
if not skip_vcpu:
28+
resources["VCPU"] = flavor.vcpus
29+
2330
for key, value in flavor.extra_specs.items():
2431
if "trait:" == key[:6]:
2532
if value == "required":
@@ -29,8 +36,13 @@ def get_placement_request(flavor):
2936
resources[key[10:]] = count
3037
if "hw:cpu_policy" == key and value == "dedicated":
3138
resources["PCPU"] = flavor.vcpus
32-
if "PCPU" not in resources.keys() and "VCPU" not in resources.keys():
33-
resources["VCPU"] = flavor.vcpus
39+
add_defaults(resources, flavor, skip_vcpu=True)
40+
41+
# if not baremetal and not PCPU
42+
# we should add the default vcpu ones
43+
if not resources:
44+
add_defaults(resources, flavor)
45+
3446
return resources, required_traits
3547

3648

@@ -61,7 +73,10 @@ def get_max_per_host(placement_client, resources, required_traits):
6173
# available count is the min of the max counts
6274
if max_counts:
6375
count_per_rp[rp_uuid] = min(max_counts)
64-
76+
if not count_per_rp:
77+
print(
78+
f"# WARNING - no candidates for resources:{resource_str} traits:{required_str}"
79+
)
6580
return count_per_rp
6681

6782

@@ -136,6 +151,7 @@ def print_details(compute_client, placement_client):
136151
for hostname in hostnames:
137152
rp = resource_providers[hostname]
138153
rp_id = rp["uuid"]
154+
free_space_found = False
139155
for flavor_name in flavor_names:
140156
all_counts = capacity_per_flavor.get(flavor_name, {})
141157
our_count = all_counts.get(rp_id, 0)
@@ -151,6 +167,9 @@ def print_details(compute_client, placement_client):
151167
print(
152168
f'openstack_capacity_by_hostname{{{host_str},flavor="{flavor_name}"}} {our_count}'
153169
)
170+
free_space_found = True
171+
if not free_space_found:
172+
print(f"# WARNING - no free spaces found for {hostname}")
154173

155174
for project, names in project_to_aggregate.items():
156175
for name in names:

0 commit comments

Comments
 (0)