Skip to content

Commit

Permalink
Refactor querying hypervisor server count
Browse files Browse the repository at this point in the history
Add new server query to find number of servers on a hypervisor
  • Loading branch information
gmatthews20 committed Dec 13, 2024
1 parent 5363a77 commit 1243bb0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/openstack_query_api/hypervisor_queries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from openstackquery.api.query_objects import HypervisorQuery
from openstackquery.api.query_objects import HypervisorQuery, ServerQuery


def query_hypervisor_state(cloud_account: str):
Expand All @@ -17,9 +17,19 @@ def query_hypervisor_state(cloud_account: str):
"hypervisor_state",
"hypervisor_status",
"hypervisor_uptime_days",
"hypervisor_server_count",
)

state_query.run(cloud_account=cloud_account)
state_query.run(cloud_account=cloud_account, all_projects=True, as_admin=True)
hypervisor_info = state_query.to_props()
server_query = ServerQuery()
server_query.group_by("hypervisor_name")
server_query.run(cloud_account=cloud_account, all_projects=True, as_admin=True)

return state_query.to_props()
servers_on_hypervisor = server_query.to_props()

for hv in hypervisor_info:
hv["hypervisor_server_count"] = len(
servers_on_hypervisor.get(hv["hypervisor_name"], [])
)

return hypervisor_info

0 comments on commit 1243bb0

Please sign in to comment.