
os-client-config provided helper functions for constructing legacy python-*client objects, as well as Connection and OpenStackCloud objects. openstacksdk isn't in the business of constructing python-*client objects for people, so let's remove these. We also dont' need helper functions in the openstack.config space for constructing Connection since we already have openstack.connect for that (and we'll fold OpenStackCloud in soon enough) Change-Id: I09e4fe258ff58a8e8aec5919369ff856a5102b76
1.4 KiB
1.4 KiB
Using openstack.config in an Application
Usage
The simplest and least useful thing you can do is:
-m openstack.config.loader python
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
= openstack.config.OpenStackConfig().get_one(
cloud_region 'internap', region_name='ams01')
print(cloud_region.name, cloud_region.region, cloud_region.config)
Or, get all of the clouds.
import openstack.config
= openstack.config.OpenStackConfig().get_all()
cloud_regions for cloud_region in cloud_regions:
print(cloud_region.name, cloud_region.region, cloud_region.config)
argparse
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
= openstack.config.OpenStackConfig()
config = argparse.ArgumentParser()
parser
config.register_argparse_arguments(parser, sys.argv)
= parser.parse_args()
options
= config.get_one(argparse=options) cloud_region