Project
The Project class represents an OpenStack project (tenant) and provides access to project resources including servers, users, floating IPs, and quotas.
Constructor
Project(project_id=None, name=None, cloud=Cloud())
The unique identifier for the project. Use either project_id or name to identify the project.
The name of the project. Use either project_id or name to identify the project.
The Cloud instance to use for API calls. Defaults to a new Cloud() instance.
Properties
Returns the name associated to this Projectproject = Project(project_id="abc123")
print(project.name)
Returns the ID associated to this Projectproject = Project(name="lsst-drp")
print(project.id)
Returns the parent Project associated to this Project. Returns None if this project has no parent.project = Project(name="child-project")
if project.parent:
print(f"Parent project: {project.parent.name}")
Returns the tags associated to this Project. Output is a list of strings.project = Project(name="lsst-drp")
tags = project.tags
for tag in tags:
print(f"Tag: {tag}")
Get the list of Servers currently running on this Projectproject = Project(name="ncas-force-U")
servers = project.servers
for server in servers:
print(f"Server: {server.name} - {server.status}")
Returns the list of Users with access to this Projectproject = Project(name="Condor")
users = project.users
for user in users:
print(f"User: {user.name}")
Returns the list of Floating IPs in this Projectproject = Project(name="lsst-drp")
fips = project.fips
for fip in fips:
print(f"Floating IP: {fip.ip}")
Returns the quota information for this Projectproject = Project(name="lsst-drp")
quotas = project.quotas
print(f"Cores: {quotas.cores}")
print(f"RAM: {quotas.ram}")
Methods
Adds an entity (e.g., User) to this Projectfrom myos.user import User
project = Project(name="my-project")
user = User(name="new-user", domain_name="stfc")
project.add(user)
Removes an entity (e.g., User) from this Project. Currently not implemented.from myos.user import User
project = Project(name="my-project")
user = User(name="old-user", domain_name="stfc")
project.remove(user)
Usage Example
from myos.project import Project
from myos.cloud import Cloud
# Initialize project by name
project = Project(name="lsst-drp")
print(f"Project ID: {project.id}")
# Get project resources
servers = project.servers
print(f"Total servers: {len(servers)}")
for server in servers:
print(f" - {server.name}: {server.status}")
# Get project users
users = project.users
print(f"Total users: {len(users)}")
for user in users:
print(f" - {user.name}")
# Get floating IPs
fips = project.fips
for fip in fips:
print(f"Floating IP: {fip.ip}")
# Check quotas
quotas = project.quotas
print(f"Available cores: {quotas.cores}")
print(f"Available RAM: {quotas.ram}")
# Check parent project
if project.parent:
print(f"Parent project: {project.parent.name}")
# Add user to project
from myos.user import User
new_user = User(user_id="xyz789")
project.add(new_user)
# Use custom cloud configuration
custom_cloud = Cloud("staging")
project = Project(name="test-project", cloud=custom_cloud)