blob: 14a3bd631b63e03d7c9f184f2ce02b7e6302cd5b [file] [log] [blame]
Ken'ichi Ohmichi0e836652015-01-08 04:38:56 +00001# Copyright 2015 NEC Corporation. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050015from tempest.lib.common import rest_client
Ken'ichi Ohmichi79aede12015-01-17 08:19:47 +000016
Ken'ichi Ohmichi0e836652015-01-08 04:38:56 +000017
18class ServiceClient(rest_client.RestClient):
19
20 def __init__(self, auth_provider, service, region,
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000021 endpoint_type=None, build_interval=None, build_timeout=None,
22 disable_ssl_certificate_validation=None, ca_certs=None,
23 trace_requests=None):
24
David Kranz1e33e372015-03-20 09:42:56 -040025 dscv = disable_ssl_certificate_validation
Ken'ichi Ohmichi0e836652015-01-08 04:38:56 +000026 params = {
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000027 'disable_ssl_certificate_validation': dscv,
David Kranz1e33e372015-03-20 09:42:56 -040028 'ca_certs': ca_certs,
29 'trace_requests': trace_requests
Ken'ichi Ohmichi0e836652015-01-08 04:38:56 +000030 }
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000031
Ken'ichi Ohmichi0e836652015-01-08 04:38:56 +000032 if endpoint_type is not None:
33 params.update({'endpoint_type': endpoint_type})
34 if build_interval is not None:
35 params.update({'build_interval': build_interval})
36 if build_timeout is not None:
37 params.update({'build_timeout': build_timeout})
38 super(ServiceClient, self).__init__(auth_provider, service, region,
39 **params)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000040
41
42class ResponseBody(dict):
43 """Class that wraps an http response and dict body into a single value.
44
45 Callers that receive this object will normally use it as a dict but
46 can extract the response if needed.
47 """
48
49 def __init__(self, response, body=None):
50 body_data = body or {}
51 self.update(body_data)
52 self.response = response
53
54 def __str__(self):
David Kranz01fa7e42015-02-10 15:51:51 -050055 body = super(ResponseBody, self).__str__()
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000056 return "response: %s\nBody: %s" % (self.response, body)
57
58
David Kranze4e3b412015-02-10 10:50:42 -050059class ResponseBodyData(object):
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000060 """Class that wraps an http response and string data into a single value"""
David Kranze4e3b412015-02-10 10:50:42 -050061
62 def __init__(self, response, data):
63 self.response = response
64 self.data = data
65
66 def __str__(self):
67 return "response: %s\nBody: %s" % (self.response, self.data)
68
69
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000070class ResponseBodyList(list):
71 """Class that wraps an http response and list body into a single value.
72
73 Callers that receive this object will normally use it as a list but
74 can extract the response if needed.
75 """
76
77 def __init__(self, response, body=None):
78 body_data = body or []
79 self.extend(body_data)
80 self.response = response
81
82 def __str__(self):
David Kranz01fa7e42015-02-10 15:51:51 -050083 body = super(ResponseBodyList, self).__str__()
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000084 return "response: %s\nBody: %s" % (self.response, body)