summaryrefslogtreecommitdiff
path: root/openstackclient/shell.py
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2015-03-02 17:05:35 -0600
committerDean Troyer <dtroyer@gmail.com>2015-04-18 23:04:51 -0500
commit5649695c658505b0217fb6d03cf199797b90ca4c (patch)
tree277dc72a93e7fa4c557a1dbe0d4d021d69e94c5d /openstackclient/shell.py
parenta5e79d58ae508e218a113bfa3976fae369980688 (diff)
downloadpython-openstackclient-5649695c658505b0217fb6d03cf199797b90ca4c.tar.gz
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 <mordred@inaugust.com> Change-Id: I4939acf8067e44ffe06a2e26fc28f1adf8985b7d Depends-On: I45e2550af58aee616ca168d20a557077beeab007
Diffstat (limited to 'openstackclient/shell.py')
-rw-r--r--openstackclient/shell.py58
1 files changed, 47 insertions, 11 deletions
diff --git a/openstackclient/shell.py b/openstackclient/shell.py
index f4e3b7e5..00f4a3c9 100644
--- a/openstackclient/shell.py
+++ b/openstackclient/shell.py
@@ -33,6 +33,8 @@ from openstackclient.common import exceptions as exc
from openstackclient.common import timing
from openstackclient.common import utils
+from os_client_config import config as cloud_config
+
DEFAULT_DOMAIN = 'default'
@@ -86,10 +88,6 @@ class OpenStackShell(app.App):
# Until we have command line arguments parsed, dump any stack traces
self.dump_stack_trace = True
- # This is instantiated in initialize_app() only when using
- # password flow auth
- self.auth_client = None
-
# Assume TLS host certificate verification is enabled
self.verify = True
@@ -165,10 +163,19 @@ class OpenStackShell(app.App):
description,
version)
+ # service token auth argument
+ parser.add_argument(
+ '--os-cloud',
+ metavar='<cloud-config-name>',
+ dest='cloud',
+ default=utils.env('OS_CLOUD'),
+ help='Cloud name in clouds.yaml (Env: OS_CLOUD)',
+ )
# Global arguments
parser.add_argument(
'--os-region-name',
metavar='<auth-region-name>',
+ dest='region_name',
default=utils.env('OS_REGION_NAME'),
help='Authentication region name (Env: OS_REGION_NAME)')
parser.add_argument(
@@ -213,8 +220,43 @@ class OpenStackShell(app.App):
* authenticate against Identity if requested
"""
+ # Parent __init__ parses argv into self.options
super(OpenStackShell, self).initialize_app(argv)
+ # Resolve the verify/insecure exclusive pair here as cloud_config
+ # doesn't know about verify
+ self.options.insecure = (
+ self.options.insecure and not self.options.verify
+ )
+
+ # Set the default plugin to token_endpoint if rl and token are given
+ if (self.options.url and self.options.token):
+ # Use service token authentication
+ cloud_config.set_default('auth_type', 'token_endpoint')
+ else:
+ cloud_config.set_default('auth_type', 'osc_password')
+ self.log.debug("options: %s", self.options)
+
+ # Do configuration file handling
+ cc = cloud_config.OpenStackConfig()
+ self.log.debug("defaults: %s", cc.defaults)
+
+ self.cloud = cc.get_one_cloud(
+ cloud=self.options.cloud,
+ argparse=self.options,
+ )
+ self.log.debug("cloud cfg: %s", self.cloud.config)
+
+ # Set up client TLS
+ cacert = self.cloud.cacert
+ if cacert:
+ self.verify = cacert
+ else:
+ self.verify = not getattr(self.cloud.config, 'insecure', False)
+
+ # Neutralize verify option
+ self.options.verify = None
+
# Save default domain
self.default_domain = self.options.os_default_domain
@@ -260,14 +302,8 @@ class OpenStackShell(app.App):
# Handle deferred help and exit
self.print_help_if_requested()
- # Set up common client session
- if self.options.os_cacert:
- self.verify = self.options.os_cacert
- else:
- self.verify = not self.options.insecure
-
self.client_manager = clientmanager.ClientManager(
- cli_options=self.options,
+ cli_options=self.cloud,
verify=self.verify,
api_version=self.api_version,
pw_func=prompt_for_password,