summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/common.py8
-rwxr-xr-xexamples/object_api.py17
-rwxr-xr-xexamples/osc-lib.py14
3 files changed, 35 insertions, 4 deletions
diff --git a/examples/common.py b/examples/common.py
index 2e798529..3b31f582 100755
--- a/examples/common.py
+++ b/examples/common.py
@@ -85,8 +85,16 @@ def base_parser(parser):
# Global arguments
parser.add_argument(
+ '--os-cloud',
+ metavar='<cloud-config-name>',
+ dest='cloud',
+ default=env('OS_CLOUD'),
+ help='Cloud name in clouds.yaml (Env: OS_CLOUD)',
+ )
+ parser.add_argument(
'--os-region-name',
metavar='<auth-region-name>',
+ dest='region_name',
default=env('OS_REGION_NAME'),
help='Authentication region name (Env: OS_REGION_NAME)',
)
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',
diff --git a/examples/osc-lib.py b/examples/osc-lib.py
index 2960a2f7..84501903 100755
--- a/examples/osc-lib.py
+++ b/examples/osc-lib.py
@@ -29,6 +29,8 @@ import common
from openstackclient.common import clientmanager
+from os_client_config import config as cloud_config
+
LOG = logging.getLogger('')
@@ -36,6 +38,16 @@ LOG = logging.getLogger('')
def run(opts):
"""Run the examples"""
+ # Do configuration file handling
+ cc = cloud_config.OpenStackConfig()
+ LOG.debug("defaults: %s", cc.defaults)
+
+ cloud = cc.get_one_cloud(
+ cloud=opts.cloud,
+ argparse=opts,
+ )
+ LOG.debug("cloud cfg: %s", cloud.config)
+
# Loop through extensions to get API versions
# Currently API versions are statically selected. Once discovery
# is working this can go away...
@@ -59,7 +71,7 @@ def run(opts):
# Collect the auth and config options together and give them to
# ClientManager and it will wrangle all of the goons into place.
client_manager = clientmanager.ClientManager(
- cli_options=opts,
+ cli_options=cloud,
verify=verify,
api_version=api_version,
)