Jude Cross | 638c4ef | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import json |
| 16 | |
| 17 | from oslo_serialization import jsonutils |
| 18 | from tempest.lib.common import rest_client |
| 19 | |
| 20 | |
| 21 | class 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) |