From 5649695c658505b0217fb6d03cf199797b90ca4c Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 2 Mar 2015 17:05:35 -0600 Subject: Add --os-cloud support This adds a new option --os-cloud that allows the configuration values for multiple clouds to be stored in a local file and selected with a single option. Internal option names have had 'os_' removed to be comptible with the options returned from OpenStackConfig().get_one_cloud(). The config file is ~/.config/openstack/clouds.yaml: Sample ------ clouds: devstack: auth: auth_url: http://192.168.122.10:35357/ project_name: demo username: demo password: 0penstack region_name: RegionOne devstack: auth: auth_url: http://192.168.122.10:35357/ project_name: demo username: demo password: 0penstack region_name: RegionOne Co-Authored-By: Monty Taylor Change-Id: I4939acf8067e44ffe06a2e26fc28f1adf8985b7d Depends-On: I45e2550af58aee616ca168d20a557077beeab007 --- examples/object_api.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'examples/object_api.py') diff --git a/examples/object_api.py b/examples/object_api.py index 5c6bd9f0..441013ca 100755 --- a/examples/object_api.py +++ b/examples/object_api.py @@ -30,6 +30,8 @@ import common from openstackclient.api import object_store_v1 as object_store from openstackclient.identity import client as identity_client +from os_client_config import config as cloud_config + LOG = logging.getLogger('') @@ -37,6 +39,15 @@ LOG = logging.getLogger('') def run(opts): """Run the examples""" + # Look for configuration file + # To support token-flow we have no required values + # print "options: %s" % self.options + cloud = cloud_config.OpenStackConfig().get_one_cloud( + cloud=opts.cloud, + argparse=opts, + ) + LOG.debug("cloud cfg: %s", cloud.config) + # Set up certificate verification and CA bundle # NOTE(dtroyer): This converts from the usual OpenStack way to the single # requests argument and is an app-specific thing because @@ -52,13 +63,13 @@ def run(opts): # The returned session will have a configured auth object # based on the selected plugin's available options. # So to do...oh, just go to api.auth.py and look at what it does. - session = common.make_session(opts, verify=verify) + session = common.make_session(cloud, verify=verify) # Extract an endpoint auth_ref = session.auth.get_auth_ref(session) - if opts.os_url: - endpoint = opts.os_url + if opts.url: + endpoint = opts.url else: endpoint = auth_ref.service_catalog.url_for( service_type='object-store', -- cgit v1.2.1