Update common apiclient from Oslo

Updated openstack.common.apiclient code from oslo-incubator to commit
8630a44d64c92a0d479e4652bf5ba2cd22416eae

List of changes:

9f1e7eb Correct docstring in load_plugin_from_args
0c4d2c7 Removed set_loaded() method from Resource class
3b248dd Add to_dict() method to apiclient Resource
be81d6b Cleanup unused log related code
8575d87 Removed copyright from empty files
bbaf317 Use encode() instead of strutils.safe_encode() in fake_client
41dc2b4 Encode response from FakeHTTPClient

Removed Resource class from client's code - we should use Resource from
common code.

Change-Id: I0b90999e7832f3796201e40f7df4de7148b832fa
This commit is contained in:
Victor Sergeyev 2014-02-10 10:26:01 +02:00
parent 55d9fda3d3
commit 32641b4f27
8 changed files with 24 additions and 48 deletions

View File

@ -17,11 +17,6 @@
Base utilities to build API operation managers and objects on top of.
"""
import copy
from tuskarclient.openstack.common.apiclient import base
# Python 2.4 compat
try:
all
@ -117,16 +112,3 @@ class Manager(object):
def _delete(self, url):
self.api.raw_request('DELETE', url)
class Resource(base.Resource):
"""A resource represents a particular instance of an object (tenant, user,
etc). This is pretty much just a bag for attributes.
:param manager: Manager object
:param info: dictionary representing resource attributes
:param loaded: prevent lazy-loading if set to True
"""
def to_dict(self):
return copy.deepcopy(self._info)

View File

@ -1,14 +0,0 @@
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
# 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.

View File

@ -19,7 +19,6 @@
import abc
import argparse
import logging
import os
import six
@ -28,9 +27,6 @@ from stevedore import extension
from tuskarclient.openstack.common.apiclient import exceptions
logger = logging.getLogger(__name__)
_discovered_plugins = {}
@ -80,7 +76,7 @@ def load_plugin_from_args(args):
alphabetical order.
:type args: argparse.Namespace
:raises: AuthorizationFailure
:raises: AuthPluginOptionsMissing
"""
auth_system = args.os_auth_system
if auth_system:

View File

@ -24,6 +24,7 @@ Base utilities to build API operation managers and objects on top of.
# pylint: disable=E1102
import abc
import copy
import six
@ -84,8 +85,8 @@ class HookableMixin(object):
class BaseManager(HookableMixin):
"""Basic manager type providing common operations.
Managers interact with a particular type of API (servers, images, etc.) and
provide CRUD operations for them.
Managers interact with a particular type of API (servers, flavors, images,
etc.) and provide CRUD operations for them.
"""
resource_class = None
@ -456,17 +457,17 @@ class Resource(object):
def __getattr__(self, k):
if k not in self.__dict__:
#NOTE(bcwaldon): disallow lazy-loading if already loaded once
if not self.is_loaded():
self.get()
if not self.is_loaded:
self._get()
return self.__getattr__(k)
raise AttributeError(k)
else:
return self.__dict__[k]
def get(self):
# set_loaded() first ... so if we have to bail, we know we tried.
self.set_loaded(True)
def _get(self):
# set _loaded first ... so if we have to bail, we know we tried.
self._loaded = True
if not hasattr(self.manager, 'get'):
return
@ -484,8 +485,9 @@ class Resource(object):
return self.id == other.id
return self._info == other._info
@property
def is_loaded(self):
return self._loaded
def set_loaded(self, val):
self._loaded = val
def to_dict(self):
return copy.deepcopy(self._info)

View File

@ -60,6 +60,11 @@ class AuthorizationFailure(ClientException):
pass
class ConnectionRefused(ClientException):
"""Cannot connect to API service."""
pass
class AuthPluginOptionsMissing(AuthorizationFailure):
"""Auth plugin misses some options."""
def __init__(self, opt_names):

View File

@ -27,6 +27,7 @@ places where actual behavior differs from the spec.
import json
import requests
import six
from tuskarclient.openstack.common.apiclient import client
from tuskarclient.openstack.common.py3kcompat import urlutils
@ -61,6 +62,8 @@ class TestResponse(requests.Response):
else:
self._content = text
default_headers = {}
if six.PY3 and isinstance(self._content, six.string_types):
self._content = self._content.encode('utf-8', 'strict')
self.headers = data.get('headers') or default_headers
else:
self.status_code = data

View File

@ -11,9 +11,10 @@
# under the License.
from tuskarclient.common import base
from tuskarclient.openstack.common.apiclient import base as common_base
class OvercloudRole(base.Resource):
class OvercloudRole(common_base.Resource):
"""Represents an instance of an Overcloud Role in the Tuskar API.
:param manager: Manager object

View File

@ -11,9 +11,10 @@
# under the License.
from tuskarclient.common import base
from tuskarclient.openstack.common.apiclient import base as common_base
class Overcloud(base.Resource):
class Overcloud(common_base.Resource):
"""Represents an instance of a Overcloud in the Tuskar API.
:param manager: Manager object