Create a new base REST API interface
* restapi module provides basic REST API support * uses dicts rather than Resource classes * JSON serialization/deserialization * log requests in 'curl' format * basic API boilerplate for create/delete/list/set/show verbs * ignore H302 due to urllib import Change-Id: I3cb91e44e631ee19e9f5dea19b6bac5d599d19ce
This commit is contained in:
@@ -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')
|
||||
|
||||
|
||||
@@ -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"""
|
||||
|
||||
14
openstackclient/tests/common/__init__.py
Normal file
14
openstackclient/tests/common/__init__.py
Normal file
@@ -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.
|
||||
#
|
||||
2
tox.ini
2
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
|
||||
|
||||
Reference in New Issue
Block a user