Using openstack.config in an Application

Using openstack.config in an Application


The simplest and least useful thing you can do is:

python -m openstack.config.loader

Which will print out whatever if finds for your config. If you want to use it from python, which is much more likely what you want to do, things like:

Get a named cloud.

import openstack.config

cloud_region = openstack.config.OpenStackConfig().get_one(
    'internap', region_name='ams01')
print(, cloud_region.region, cloud_region.config)

Or, get all of the clouds.

import openstack.config

cloud_regions = openstack.config.OpenStackConfig().get_all()
for cloud_region in cloud_regions:
    print(, cloud_region.region, cloud_region.config)


If you’re using openstack.config from a program that wants to process command line options, there is a registration function to register the arguments that both openstack.config and keystoneauth know how to deal with - as well as a consumption argument.

import argparse
import sys

import openstack.config

config = openstack.config.OpenStackConfig()
parser = argparse.ArgumentParser()
config.register_argparse_arguments(parser, sys.argv)

options = parser.parse_args()

cloud_region = config.get_one(argparse=options)
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.