@@ -18,8 +18,15 @@ def get_capacity_per_flavor(placement_client, flavors):
18
18
19
19
20
20
def get_placement_request (flavor ):
21
- resources = {"MEMORY_MB" : flavor . ram , "DISK_GB" : ( flavor . disk + flavor . ephemeral ) }
21
+ resources = {}
22
22
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
+
23
30
for key , value in flavor .extra_specs .items ():
24
31
if "trait:" == key [:6 ]:
25
32
if value == "required" :
@@ -29,8 +36,13 @@ def get_placement_request(flavor):
29
36
resources [key [10 :]] = count
30
37
if "hw:cpu_policy" == key and value == "dedicated" :
31
38
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
+
34
46
return resources , required_traits
35
47
36
48
@@ -61,7 +73,10 @@ def get_max_per_host(placement_client, resources, required_traits):
61
73
# available count is the min of the max counts
62
74
if max_counts :
63
75
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
+ )
65
80
return count_per_rp
66
81
67
82
@@ -136,6 +151,7 @@ def print_details(compute_client, placement_client):
136
151
for hostname in hostnames :
137
152
rp = resource_providers [hostname ]
138
153
rp_id = rp ["uuid" ]
154
+ free_space_found = False
139
155
for flavor_name in flavor_names :
140
156
all_counts = capacity_per_flavor .get (flavor_name , {})
141
157
our_count = all_counts .get (rp_id , 0 )
@@ -151,6 +167,9 @@ def print_details(compute_client, placement_client):
151
167
print (
152
168
f'openstack_capacity_by_hostname{{{ host_str } ,flavor="{ flavor_name } "}} { our_count } '
153
169
)
170
+ free_space_found = True
171
+ if not free_space_found :
172
+ print (f"# WARNING - no free spaces found for { hostname } " )
154
173
155
174
for project , names in project_to_aggregate .items ():
156
175
for name in names :
0 commit comments