21 lines
636 B
Python
21 lines
636 B
Python
from openstack.connection import Connection
|
|
|
|
from collections import Counter
|
|
|
|
def get_flavor_list(connection: Connection) -> dict:
|
|
servers = list(connection.compute.servers(all_projects=True))
|
|
flavor_ids = [s.flavor['id'] for s in servers if 'id' in s.flavor]
|
|
flavor_count = Counter(flavor_ids).most_common()
|
|
|
|
flavors = list(flavor_count)
|
|
|
|
result = {}
|
|
for idx, prefix in [(0, "first"), (1, "second"), (2, "third")]:
|
|
if len(flavors) > idx:
|
|
result[f"{prefix}_common_flavor"] = {
|
|
"name": flavors[idx][0],
|
|
"count": flavors[idx][1]
|
|
}
|
|
|
|
return result
|