blob: 22ed5f2c273d63790a71c79c974827e2709d941d [file] [log] [blame]
Jude Cross638c4ef2017-07-24 14:57:20 -07001# Copyright 2017 Catalyst IT Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import json
16
17from oslo_serialization import jsonutils
18from tempest.lib.common import rest_client
19
20
21class LoadbalancerClientBase(rest_client.RestClient):
22 def get_list_objs(self, obj):
23 resp, body = self.get('/v2.0/lbaas/%s' % obj)
24
25 return resp, jsonutils.loads(body)
26
27 def delete_obj(self, obj, id, cascade=False):
28 url = '/v2.0/lbaas/{obj}/{id}'.format(obj=obj, id=id)
29 if cascade:
30 url += '?cascade=True'
31 return self.delete(url)
32
33 def get_obj(self, obj, id):
34 resp, body = self.get('/v2.0/lbaas/{obj}/{id}'.format(obj=obj, id=id))
35
36 return resp, jsonutils.loads(body)
37
38 def post_json(self, obj, req_body, extra_headers={}):
39 headers = {"Content-Type": "application/json"}
40 headers = dict(headers, **extra_headers)
41 url_path = '/v2.0/lbaas/%s' % obj
42
43 resp, body = self.post(url_path, json.dumps(req_body), headers=headers)
44
45 return resp, jsonutils.loads(body)
46
47 def put_json(self, obj, id, req_body, extra_headers={}):
48 headers = {"Content-Type": "application/json"}
49 headers = dict(headers, **extra_headers)
50 url_path = '/v2.0/lbaas/%s/%s' % (obj, id)
51
52 resp, body = self.put(url_path, json.dumps(req_body), headers=headers)
53
54 return resp, jsonutils.loads(body)