summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/client_config.py28
-rw-r--r--openstackclient/common/clientmanager.py20
-rw-r--r--openstackclient/common/command.py5
-rw-r--r--openstackclient/common/exceptions.py5
-rw-r--r--openstackclient/common/logs.py5
-rw-r--r--openstackclient/common/parseractions.py5
-rw-r--r--openstackclient/common/quota.py21
-rw-r--r--openstackclient/common/timing.py5
-rw-r--r--openstackclient/common/utils.py5
9 files changed, 90 insertions, 9 deletions
diff --git a/openstackclient/common/client_config.py b/openstackclient/common/client_config.py
index 895909e9..30286df8 100644
--- a/openstackclient/common/client_config.py
+++ b/openstackclient/common/client_config.py
@@ -16,6 +16,7 @@
import logging
from os_client_config import config
+from os_client_config import exceptions as occ_exceptions
LOG = logging.getLogger(__name__)
@@ -182,6 +183,14 @@ class OSC_Config(config.OpenStackConfig):
LOG.debug("auth_config_hook(): %s" % config)
return config
+ def load_auth_plugin(self, config):
+ """Get auth plugin and validate args"""
+
+ loader = self._get_auth_loader(config)
+ config = self._validate_auth(config, loader)
+ auth_plugin = loader.load_from_options(**config['auth'])
+ return auth_plugin
+
def _validate_auth_ksc(self, config, cloud, fixed_argparse=None):
"""Old compatibility hack for OSC, no longer needed/wanted"""
return config
@@ -192,6 +201,8 @@ class OSC_Config(config.OpenStackConfig):
plugin_options = loader.get_options()
+ msgs = []
+ prompt_options = []
for p_opt in plugin_options:
# if it's in config, win, move it and kill it from config dict
# if it's in config.auth but not in config we're good
@@ -202,6 +213,16 @@ class OSC_Config(config.OpenStackConfig):
winning_value = self._find_winning_auth_value(
p_opt, config['auth'])
+ # if the plugin tells us that this value is required
+ # then error if it's doesn't exist now
+ if not winning_value and p_opt.required:
+ msgs.append(
+ 'Missing value {auth_key}'
+ ' required for auth plugin {plugin}'.format(
+ auth_key=p_opt.name, plugin=config.get('auth_type'),
+ )
+ )
+
# Clean up after ourselves
for opt in [p_opt.name] + [o.name for o in p_opt.deprecated]:
opt = opt.replace('-', '_')
@@ -224,6 +245,13 @@ class OSC_Config(config.OpenStackConfig):
p_opt.dest not in config['auth'] and
self._pw_callback is not None
):
+ # Defer these until we know all required opts are present
+ prompt_options.append(p_opt)
+
+ if msgs:
+ raise occ_exceptions.OpenStackConfigException('\n'.join(msgs))
+ else:
+ for p_opt in prompt_options:
config['auth'][p_opt.dest] = self._pw_callback(p_opt.prompt)
return config
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py
index 57423aed..23c35a3b 100644
--- a/openstackclient/common/clientmanager.py
+++ b/openstackclient/common/clientmanager.py
@@ -60,6 +60,26 @@ class ClientManager(clientmanager.ClientManager):
self._cacert = self.cacert
self._insecure = not self.verify
+ def setup_auth(self):
+ """Set up authentication"""
+
+ if self._auth_setup_completed:
+ return
+
+ # NOTE(dtroyer): Validate the auth args; this is protected with 'if'
+ # because openstack_config is an optional argument to
+ # CloudConfig.__init__() and we'll die if it was not
+ # passed.
+ if self._cli_options._openstack_config is not None:
+ self._cli_options._openstack_config._pw_callback = \
+ shell.prompt_for_password
+ self._cli_options._auth = \
+ self._cli_options._openstack_config.load_auth_plugin(
+ self._cli_options.config,
+ )
+
+ return super(ClientManager, self).setup_auth()
+
def is_network_endpoint_enabled(self):
"""Check if the network endpoint is enabled"""
diff --git a/openstackclient/common/command.py b/openstackclient/common/command.py
index 29c1534d..44954da3 100644
--- a/openstackclient/common/command.py
+++ b/openstackclient/common/command.py
@@ -15,12 +15,15 @@
# NOTE(dtroyer): This file is deprecated in Jun 2016, remove after 4.x release
# or Jun 2017.
+import inspect
import sys
from osc_lib.command.command import * # noqa
+parent_import = inspect.getouterframes(inspect.currentframe())[1][1]
sys.stderr.write(
"WARNING: %s is deprecated and will be removed after Jun 2017. "
- "Please use osc_lib.command.command\n" % __name__
+ "Please use osc_lib.command.command. This warning is caused by an "
+ "out-of-date import in %s\n" % (__name__, parent_import)
)
diff --git a/openstackclient/common/exceptions.py b/openstackclient/common/exceptions.py
index 7124074c..ed497e7b 100644
--- a/openstackclient/common/exceptions.py
+++ b/openstackclient/common/exceptions.py
@@ -14,12 +14,15 @@
# NOTE(dtroyer): This file is deprecated in Jun 2016, remove after 4.x release
# or Jun 2017.
+import inspect
import sys
from osc_lib.exceptions import * # noqa
+parent_import = inspect.getouterframes(inspect.currentframe())[1][1]
sys.stderr.write(
"WARNING: %s is deprecated and will be removed after Jun 2017. "
- "Please use osc_lib.exceptions\n" % __name__
+ "Please use osc_lib.exceptions. This warning is caused by an "
+ "out-of-date import in %s\n" % (__name__, parent_import)
)
diff --git a/openstackclient/common/logs.py b/openstackclient/common/logs.py
index 8aa97d5b..24bf07eb 100644
--- a/openstackclient/common/logs.py
+++ b/openstackclient/common/logs.py
@@ -14,13 +14,16 @@
# NOTE(dtroyer): This file is deprecated in Jun 2016, remove after 4.x release
# or Jun 2017.
+import inspect
import sys
from osc_lib.logs import * # noqa
from osc_lib.logs import _FileFormatter # noqa
+parent_import = inspect.getouterframes(inspect.currentframe())[1][1]
sys.stderr.write(
"WARNING: %s is deprecated and will be removed after Jun 2017. "
- "Please use osc_lib.logs\n" % __name__
+ "Please use osc_lib.logs. This warning is caused by an "
+ "out-of-date import in %s\n" % (__name__, parent_import)
)
diff --git a/openstackclient/common/parseractions.py b/openstackclient/common/parseractions.py
index fa5148ec..3af3a017 100644
--- a/openstackclient/common/parseractions.py
+++ b/openstackclient/common/parseractions.py
@@ -14,12 +14,15 @@
# NOTE(dtroyer): This file is deprecated in Jun 2016, remove after 4.x release
# or Jun 2017.
+import inspect
import sys
from osc_lib.cli.parseractions import * # noqa
+parent_import = inspect.getouterframes(inspect.currentframe())[1][1]
sys.stderr.write(
"WARNING: %s is deprecated and will be removed after Jun 2017. "
- "Please use osc_lib.cli.parseractions\n" % __name__
+ "Please use osc_lib.cli.parseractions. This warning is caused by an "
+ "out-of-date import in %s\n" % (__name__, parent_import)
)
diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py
index 5d53171c..aabfa5d5 100644
--- a/openstackclient/common/quota.py
+++ b/openstackclient/common/quota.py
@@ -43,11 +43,20 @@ COMPUTE_QUOTAS = {
}
VOLUME_QUOTAS = {
+ 'backups': 'backups',
+ 'backup_gigabytes': 'backup-gigabytes',
'gigabytes': 'gigabytes',
+ 'per_volume_gigabytes': 'per-volume-gigabytes',
'snapshots': 'snapshots',
'volumes': 'volumes',
}
+IMPACT_VOLUME_TYPE_QUOTAS = [
+ 'gigabytes',
+ 'snapshots',
+ 'volumes',
+]
+
NOVA_NETWORK_QUOTAS = {
'floating_ips': 'floating-ips',
'security_group_rules': 'secgroup-rules',
@@ -128,7 +137,8 @@ class SetQuota(command.Command):
for k, v in VOLUME_QUOTAS.items():
value = getattr(parsed_args, k, None)
if value is not None:
- if parsed_args.volume_type:
+ if (parsed_args.volume_type and
+ k in IMPACT_VOLUME_TYPE_QUOTAS):
k = k + '_%s' % parsed_args.volume_type
volume_kwargs[k] = value
@@ -237,11 +247,16 @@ class ShowQuota(command.ShowOne):
return quota._info
def get_network_quota(self, parsed_args):
- if parsed_args.quota_class or parsed_args.default:
+ if parsed_args.quota_class:
return {}
if self.app.client_manager.is_network_endpoint_enabled():
project = self._get_project(parsed_args)
- return self.app.client_manager.network.get_quota(project)
+ client = self.app.client_manager.network
+ if parsed_args.default:
+ network_quota = client.get_quota_default(project)
+ else:
+ network_quota = client.get_quota(project)
+ return network_quota
else:
return {}
diff --git a/openstackclient/common/timing.py b/openstackclient/common/timing.py
index facbec35..444f0cb2 100644
--- a/openstackclient/common/timing.py
+++ b/openstackclient/common/timing.py
@@ -14,12 +14,15 @@
# NOTE(dtroyer): This file is deprecated in Jun 2016, remove after 4.x release
# or Jun 2017.
+import inspect
import sys
from osc_lib.command.timing import * # noqa
+parent_import = inspect.getouterframes(inspect.currentframe())[1][1]
sys.stderr.write(
"WARNING: %s is deprecated and will be removed after Jun 2017. "
- "Please use osc_lib.command.timing\n" % __name__
+ "Please use osc_lib.command.timing. This warning is caused by an "
+ "out-of-date import in %s\n" % (__name__, parent_import)
)
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 73cd3dc9..aeb3aea7 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -14,12 +14,15 @@
# NOTE(dtroyer): This file is deprecated in Jun 2016, remove after 4.x release
# or Jun 2017.
+import inspect
import sys
from osc_lib.utils import * # noqa
+parent_import = inspect.getouterframes(inspect.currentframe())[1][1]
sys.stderr.write(
"WARNING: %s is deprecated and will be removed after Jun 2017. "
- "Please use osc_lib.utils\n" % __name__
+ "Please use osc_lib.utils. This warning is caused by an "
+ "out-of-date import in %s\n" % (__name__, parent_import)
)