Simple OpenStack access with os-client-config

Easy consumption of OpenStack Clouds

Simple things should be simple, and nowhere is that more true than in constructing objects to interface with clouds. What you wnat to do is just interact with the cloud - what you often are required to do is generate sequences of object constructions because there are a bunch of things you might have wanted to do.

In the spirit of making the simple things simple, we recently added a couple of simple helper factory functions to os-client-config: One to create Client objects, and one to create mounted Session objects. Both functions fully support the breadth of config options afforded by os-client-config, including environment variables, config files and command line options. (Speaking of - if you haven't fallen in love with clouds.yaml yet, now's the time)

Examples are probably best

Client Library Client Objects

Make a nova client object that uses env vars for auth info:


client = os_client_config.make_client('compute')
    

Make a glance client object for the cloud named 'mtvexx' in my clouds.yaml file:


client = os_client_config.make_client('image', cloud='mtvxx')
    

Make a neutron client by passing in all of the values directly:


client = os_client_config.make_client(
    'network',
    auth_url='https://example.com', username='my-user',
    password='awesome-password', project_name='my-project',
    region_name='the-best-region')
    

Make a barbican client from env vars with all the standard arguments passed on the comand line:


import argparse
client = os_client_config.make_client(
    'key-manager', options=argparse.ArgumentParser())
    

That likely covers most of the common end-user use cases with using OpenStack Client Libraries. If you need more flexibility, you can always create an os-client-config CloudConfig object and call get_legacy_client, but I'm a big believer in one step instead of three if you can get away with it:


config = os_client_config.OpenStackConfig()
cloud_config = config.get_one_cloud(cloud='vexxhost')
client = cloud_config.get_legacy_client('compute')
    

Mounted Keystone Session

What if what you want to do is make some direct REST calls to an OpenStack service, but you want to be able to do env vars or argparse or clouds.yaml files to configure your authentication?

Well - you're in luck!

Make a Session object for nova that uses env vars for auth info:


session = os_client_config.session_client('compute')
    

That will get you a keystoneauth Session object that has been "mounted" on the compute service. So you can do this:


response = session.get('/servers')
server_list = response.json()['servers']
    

The same argument sequence used for make_client works for session_client.

Make a glance Session object for the cloud named 'mtvexx' in my clouds.yaml file:


session = os_client_config.session_client('image', cloud='mtvxx')
    

Make a neutron Session object by passing in all of the values directly:


session = os_client_config.session_client(
    'network',
    auth_url='https://example.com', username='my-user',
    password='awesome-password', project_name='my-project',
    region_name='the-best-region')
    

Make a barbican Session object from env vars with all the standard arguments passed on the comand line:


import argparse
session = os_client_config.session_client(
    'key-manager', options=argparse.ArgumentParser())
    

Do it all without syntactic help:


config = os_client_config.OpenStackConfig()
cloud_config = config.get_one_cloud(cloud='vexxhost')
session = cloud_config.get_session_client('compute')