diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index f72bb50..91a2089 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -115,6 +115,30 @@ def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): return tuple(row) +def get_dict_properties(item, fields, mixed_case_fields=[], formatters={}): + """Return a tuple containing the item properties. + + :param item: a single dict resource + :param fields: tuple of strings with the desired field names + :param mixed_case_fields: tuple of field names to preserve case + :param formatters: dictionary mapping field names to callables + to format the values + """ + row = [] + + for field in fields: + if field in mixed_case_fields: + field_name = field.replace(' ', '_') + else: + field_name = field.lower().replace(' ', '_') + data = item[field_name] if field_name in item else '' + if field in formatters: + row.append(formatters[field](data)) + else: + row.append(data) + return tuple(row) + + def string_to_bool(arg): return arg.strip().lower() in ('t', 'true', 'yes', '1') diff --git a/openstackclient/shell.py b/openstackclient/shell.py index b66611b..91b02a2 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -29,6 +29,7 @@ from openstackclient.common import clientmanager from openstackclient.common import commandmanager from openstackclient.common import exceptions as exc from openstackclient.common import openstackkeyring +from openstackclient.common import restapi from openstackclient.common import utils @@ -368,6 +369,9 @@ class OpenStackShell(app.App): if self.options.deferred_help: self.DeferredHelpAction(self.parser, self.parser, None, None) + # Set up common client session + self.restapi = restapi.RESTApi() + # If the user is not asking for help, make sure they # have given us auth. cmd_name = None @@ -376,6 +380,7 @@ class OpenStackShell(app.App): cmd_factory, cmd_name, sub_argv = cmd_info if self.interactive_mode or cmd_name != 'help': self.authenticate_user() + self.restapi.set_auth(self.client_manager.identity.auth_token) def prepare_to_run_command(self, cmd): """Set up auth and API versions""" diff --git a/openstackclient/tests/common/__init__.py b/openstackclient/tests/common/__init__.py new file mode 100644 index 0000000..c534c01 --- /dev/null +++ b/openstackclient/tests/common/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2013 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# diff --git a/tox.ini b/tox.ini index 61bdc9d..e2c61af 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,6 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' downloadcache = ~/cache/pip [flake8] -ignore = E126,E202,W602,H402 +ignore = E126,E202,W602,H302,H402 show-source = True exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools