Cloud class is the main entry point for interacting with your OpenStack infrastructure using myos. It provides a unified interface to access all OpenStack resources including hypervisors, flavors, images, projects, and floating IPs.
Overview
TheCloud class acts as a gateway to your OpenStack cloud, wrapping OpenStack CLI commands and returning resource objects that you can work with programmatically.
Key Features
- Unified Access: Single interface to access all OpenStack resources
- Lazy Loading: Resources are loaded on-demand when you access properties
- EntityList Support: All resource collections return
EntityListobjects with built-in filtering, sorting, and mapping - Cloud Context: Automatically passes cloud authentication to all resource objects
Basic Usage
Creating a Cloud Instance
The cloud parameter corresponds to the cloud name in your OpenStack CLI configuration (see Authentication).
Accessing Resources
TheCloud class provides property-based access to different resource types. Each property returns an EntityList containing resource objects.
Available Resources
Hypervisors
Access all hypervisors in your cloud:Flavors
Retrieve all available instance flavors:The
flavors property fetches all flavors including private ones using the --all flag.Images
Get all images available in the cloud:Projects
Access all projects (tenants):Floating IPs
Retrieve all floating IP addresses:How It Works
TheCloud class uses the OpenStack CLI under the hood. When you access a resource property, myos:
- Constructs an OpenStack CLI command with the appropriate
--os-cloudparameter - Executes the command and captures JSON output
- Parses the JSON and creates resource objects
- Returns an
EntityListcontaining all resources
Example Internal Flow
When you callcloud.hypervisors, myos executes:
Hypervisor objects are created for each entry.
Working with EntityLists
All resource properties returnEntityList objects, which support functional programming patterns:
Complete Example
Here’s a complete example that demonstrates accessing multiple resource types:Source Reference
TheCloud class implementation can be found in cloud.py:5-83. Each resource property follows a consistent pattern:
- Execute OpenStack CLI command with
--os-cloudparameter - Parse JSON response
- Create resource objects
- Return
EntityList
Next Steps
- Learn about Authentication to configure cloud access
- Explore individual resource classes like
Hypervisor,Project, andServer - Understand
EntityListmethods for filtering and transforming data