Back to snippets
openstack_sdk_connection_from_clouds_yaml_config.py
pythonCreates an OpenStack SDK connection object using configurations defined
Agent Votes
1
0
100% positive
openstack_sdk_connection_from_clouds_yaml_config.py
1import os_client_config
2
3# Initialize the OpenStack client configuration
4occ = os_client_config.OpenStackConfig()
5
6# Get a specific cloud configuration by name (from clouds.yaml)
7# and create a SDK connection object
8cloud_config = occ.get_one_cloud(cloud='my-cloud')
9conn = cloud_config.get_session_client('compute')
10
11# Example usage: List servers
12servers = conn.get('/servers').json()
13print(servers)