Skip to main content

Introduction

This quickstart guide will help you get up and running with myos in minutes. You’ll learn how to query users, projects, and servers from your OpenStack cloud using the myos SDK.
Make sure you’ve completed the installation steps before continuing.

Your First Query

Let’s start with a simple example - querying information about a user.

Query a User

Open a Python interpreter and try the following:
from myos.user import User

# Query user by name and domain
user = User(name='wup22514', domain_name='stfc')

# Access user properties
print(f"User ID: {user.id}")
print(f"Email: {user.email}")
print(f"Description: {user.description}")
Lazy Loading: myos uses lazy loading - data is only fetched from OpenStack when you access a property. This makes the SDK efficient and fast.

List User’s Projects

Once you have a user object, you can easily access related resources:
from myos.user import User

user = User(name='wup22514', domain_name='stfc')

# Get all projects the user has access to
projects = user.projects

for project in projects:
    print(f"{project.id} - {project.name}")

Query a Project

Projects are a central concept in OpenStack. Here’s how to work with them:
from myos.project import Project

# Query project by name
project = Project(name='Condor')

print(f"Project ID: {project.id}")
print(f"Project Name: {project.name}")

List Project Resources

Once you have a project, you can query its users, servers, and other resources:
from myos.project import Project

project = Project(name='Condor')

# List all users with access to this project
users = project.users
print(f"Users with access: {len(users)}")
for user in users:
    print(f"  - {user.name}: {user.email}")

# List all servers in this project
servers = project.servers
print(f"\nTotal servers: {len(servers)}")
for server in servers:
    print(f"  - {server.name} ({server.id})")

# List floating IPs
fips = project.fips
print(f"\nFloating IPs: {len(fips)}")
for fip in fips:
    print(f"  - {fip.ip}")

Check Project Quotas

You can easily check quota information for a project:
from myos.project import Project

project = Project(name='Condor')
quotas = project.quotas

print(f"CPU cores quota: {quotas.cores}")
print(f"RAM quota: {quotas.ram} MB")

Query a Server

Servers (virtual machines) can be queried by ID or name:
from myos.server import Server

# Query server by ID
server = Server(server_id='79b3b46d-c7d8-47d2-a59d-ce5ded79b63b')

print(f"Server Name: {server.name}")
print(f"Status: {server.status}")

Get Server Details

Access detailed information about a server and its related resources:
from myos.server import Server

server = Server(server_id='79b3b46d-c7d8-47d2-a59d-ce5ded79b63b')

# Basic information
print(f"Name: {server.name}")
print(f"Status: {server.status}")

# Owner information
print(f"\nOwner: {server.user.name}")
print(f"Owner Email: {server.user.email}")

# Resource details
print(f"\nImage: {server.image.name}")
print(f"Flavor: {server.flavor.name}")
print(f"  - CPUs: {server.flavor.cpu}")
print(f"  - RAM: {server.flavor.ram} MB")
print(f"  - Disk: {server.flavor.disk} GB")

# Hypervisor location
print(f"\nHypervisor: {server.hypervisor.hostname}")
Some properties like flavor.cpu, flavor.ram, etc., require accessing additional data from OpenStack and may take longer to retrieve.

Working with Cloud Resources

The Cloud class provides access to cloud-wide resources:
from myos.cloud import Cloud

# Initialize cloud connection (uses 'admin' from clouds.yaml)
cloud = Cloud("admin")

# Get all hypervisors
hypervisors = cloud.hypervisors
print(f"Total hypervisors: {len(hypervisors)}")
print(f"First hypervisor: {hypervisors[0].hostname}")

# Get all projects
projects = cloud.projects
print(f"\nTotal projects: {len(projects)}")

# Get all flavors
flavors = cloud.flavors
print(f"\nTotal flavors: {len(flavors)}")

# Get all images
images = cloud.images
print(f"\nTotal images: {len(images)}")

# Get all floating IPs
fips = cloud.fips
print(f"\nTotal floating IPs: {len(fips)}")

Complete Example

Here’s a complete example that ties everything together:
example.py
from myos.cloud import Cloud
from myos.project import Project
from myos.user import User

# Initialize cloud connection
cloud = Cloud("admin")

# Get a specific project
project = Project(name='Condor')
print(f"Project: {project.name} ({project.id})")

# Show project quotas
quotas = project.quotas
print(f"\nQuotas:")
print(f"  Cores: {quotas.cores}")
print(f"  RAM: {quotas.ram} MB")

# List all servers in the project
servers = project.servers
print(f"\nServers ({len(servers)} total):")
for server in servers[:5]:  # Show first 5
    print(f"  - {server.name}")
    print(f"    Status: {server.status}")
    print(f"    Owner: {server.user.email}")
    print(f"    Flavor: {server.flavor.name}")
    print()

# List users with access
users = project.users
print(f"Users with access ({len(users)} total):")
for user in users[:10]:  # Show first 10
    print(f"  - {user.name}")

Using Different Cloud Profiles

If you have multiple cloud configurations in your clouds.yaml, you can specify which one to use:
from myos.cloud import Cloud
from myos.hypervisor import Hypervisor

# Use development cloud
dev_cloud = Cloud("admin-dev")

# Query resources in dev cloud
hv = Hypervisor(name="hv400.matrix.net", cloud=dev_cloud)
servers = hv.servers

print(f"Servers on {hv.hostname} in dev cloud: {len(servers)}")
Pass the cloud parameter to any resource class (User, Project, Server, etc.) to use a specific cloud profile.

Next Steps

Now that you understand the basics, explore these resources:

Common Patterns

Find all servers owned by a user

from myos.user import User

user = User(name='wup22514', domain_name='stfc')
servers = user.servers

for server in servers:
    print(f"{server.name} - {server.status}")

Find all servers on a hypervisor

from myos.hypervisor import Hypervisor

hv = Hypervisor(name='hv1.matrix.net')
servers = hv.servers

for server in servers:
    print(f"{server.name} owned by {server.user.email}")

Check resource usage across all projects

from myos.cloud import Cloud

cloud = Cloud("admin")
projects = cloud.projects

total_servers = 0
for project in projects:
    server_count = len(project.servers)
    total_servers += server_count
    if server_count > 0:
        print(f"{project.name}: {server_count} servers")

print(f"\nTotal servers across all projects: {total_servers}")

Build docs developers (and LLMs) love