fix client to work

add default conversion for exceptions
move the default headers
change the VersionInfo name

Change-Id: Icd74efdc32cd90e89f2321b0ec8da29d3555629a
Implements: blueprint vitrage-cli
This commit is contained in:
Eyal 2015-12-01 16:20:09 +02:00
parent 2128549d7b
commit 680457faa5
4 changed files with 5 additions and 15 deletions

View File

@ -14,4 +14,4 @@ import pbr.version
__version__ = pbr.version.VersionInfo(
'vitrageclient').version_string()
'python-vitrageclient').version_string()

View File

@ -25,6 +25,8 @@ def Client(version, *args, **kwargs):
class VitrageClient(adapter.Adapter):
def request(self, url, method, **kwargs):
headers = kwargs.setdefault('headers', {})
headers.setdefault('Accept', 'application/json')
raise_exc = kwargs.pop('raise_exc', True)
resp = super(VitrageClient, self).request(url,
method,

View File

@ -33,4 +33,4 @@ class ClientException(Exception):
def from_response(resp, url, method):
return None
return ClientException(resp.status_code, url=url, method=method)

View File

@ -10,25 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from v1 import topology
from vitrageclient import client
from vitrageclient.v1 import topology
class Client(object):
DEFAULT_HEADERS = {
"Accept": "application/json",
}
def __init__(self, session=None, service_type='rca', **kwargs):
self._set_default_headers(kwargs)
self._api = client.VitrageClient(session, service_type=service_type,
**kwargs)
self.topology = topology.Topology(self._api)
def _set_default_headers(self, kwargs):
headers = kwargs.get('headers', {})
for k, v in self.DEFAULT_HEADERS.items():
if k not in headers:
headers[k] = v
kwargs['headers'] = headers
return kwargs