The Hypervisor class provides an interface for working with OpenStack compute hosts (hypervisors). Hypervisors are the physical or virtual machines that run your cloud instances. This guide shows you how to query hypervisor information and monitor the servers running on them.
from myos.hypervisor import Hypervisorhypervisor = Hypervisor(name="hv300.nubes.rl.ac.uk")# Get hypervisor detailsprint(hypervisor.hostname) # Hypervisor hostnameprint(hypervisor.name) # Same as hostnameprint(hypervisor.id) # Hypervisor ID
The name and hostname properties are equivalent for the Hypervisor class.
Retrieve all servers running on a specific hypervisor:
from myos.hypervisor import Hypervisorhypervisor = Hypervisor(name="hv-a100x8-8.nubes.rl.ac.uk")# Get all servers on this hypervisorservers = hypervisor.serversprint(f"Hypervisor {hypervisor.hostname} hosts {len(servers)} servers\n")for server in servers: print(f"Server: {server.name}") print(f" ID: {server.id}") print(f" Status: {server.status}") print(f" Flavor: {server.flavor.name}") print()
Example Output
Hypervisor hv-a100x8-8.nubes.rl.ac.uk hosts 3 serversServer: vwn-gpu-2025-12-05-21-03-17-0 ID: 79b3b46d-c7d8-47d2-a59d-ce5ded79b63b Status: ACTIVE Flavor: g-a100-80gb-2022.x1Server: vwn-gpu-2025-12-17-13-17-19-0 ID: 4027da2e-c42b-411b-88f7-cc41f431959a Status: ACTIVE Flavor: g-a100-80gb-2022.x1
The servers property searches across all projects, making it useful for monitoring hypervisor workload.
Traverse relationships to understand who is using resources on a hypervisor:
from myos.hypervisor import Hypervisorhypervisor = Hypervisor(name="hv-a100x8-8.nubes.rl.ac.uk")print(f"Analyzing hypervisor: {hypervisor.hostname}\n")print(f"Status: {hypervisor.status}, State: {hypervisor.state}\n")# Get all servers and their creatorsservers = hypervisor.serversprint(f"Total servers: {len(servers)}\n")user_server_count = {}for server in servers: print(f"Server: {server.name}") print(f" Status: {server.status}") print(f" Image: {server.image.name}") # Get the user who created this server user = server.user print(f" Created by: {user.name}") print(f" User domain: {user.domain.name}") # Track servers per user if user.name not in user_server_count: user_server_count[user.name] = 0 user_server_count[user.name] += 1 print()# Summaryprint("User Summary:")for username, count in user_server_count.items(): print(f" {username}: {count} server(s)")
Find which hypervisor is running a specific server:
from myos.server import Serverserver = Server(server_id="79b3b46d-c7d8-47d2-a59d-ce5ded79b63b")# Get the hypervisor running this serverhypervisor = server.hypervisorprint(f"Server {server.name} is running on:")print(f" Hypervisor: {hypervisor.hostname}")print(f" HV Status: {hypervisor.status}")print(f" HV State: {hypervisor.state}")# Get other servers on the same hypervisorsibling_servers = hypervisor.serversprint(f"\nOther servers on this hypervisor ({len(sibling_servers) - 1}):")for srv in sibling_servers: if srv.id != server.id: print(f" - {srv.name} ({srv.status})")
This pattern is useful for understanding resource colocation and planning migrations.
Monitor hypervisor utilization for capacity planning:
from myos.hypervisor import Hypervisorhypervisor = Hypervisor(name="hv-a100x8-8.nubes.rl.ac.uk")print("=" * 60)print(f"Hypervisor Capacity Report: {hypervisor.hostname}")print("=" * 60)# Health checkprint(f"\nHealth Status:")print(f" Status: {hypervisor.status}")print(f" State: {hypervisor.state}")# Get all serversservers = hypervisor.serversprint(f"\nWorkload Summary:")print(f" Total Servers: {len(servers)}")# Count servers by statusstatus_counts = {}for server in servers: status = server.status if status not in status_counts: status_counts[status] = 0 status_counts[status] += 1for status, count in sorted(status_counts.items()): print(f" {status}: {count}")# Analyze flavors in useprint(f"\nFlavor Distribution:")flavor_counts = {}for server in servers: flavor_name = server.flavor.name if flavor_name not in flavor_counts: flavor_counts[flavor_name] = 0 flavor_counts[flavor_name] += 1for flavor, count in sorted(flavor_counts.items(), key=lambda x: x[1], reverse=True): print(f" {flavor}: {count} server(s)")# List active serversactive_servers = [s for s in servers if s.status == "ACTIVE"]print(f"\nActive Servers ({len(active_servers)}):")for server in active_servers[:10]: # Show first 10 user = server.user print(f" - {server.name}") print(f" Owner: {user.name} ({user.domain.name})") print(f" Flavor: {server.flavor.name}")print("\n" + "=" * 60)