blob: f93fb74a111a7dbcd32703e79e865dc5e781143d [file] [log] [blame]
rajalakshmi-ganesanab426722013-02-08 15:49:15 +05301# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Matthew Treinish21905512015-07-13 10:33:35 -040016from oslo_serialization import jsonutils as json
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053017
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000018from tempest.common import service_client
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053019
20
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000021class EndPointClient(service_client.ServiceClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090022 api_version = "v3"
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053023
24 def list_endpoints(self):
25 """GET endpoints."""
26 resp, body = self.get('endpoints')
David Kranz2aaf5312014-08-29 09:22:10 -040027 self.expected_success(200, resp.status)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053028 body = json.loads(body)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000029 return service_client.ResponseBodyList(resp, body['endpoints'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053030
31 def create_endpoint(self, service_id, interface, url, **kwargs):
Brant Knudson3a9bdf92014-02-27 17:09:50 -060032 """Create endpoint.
33
34 Normally this function wouldn't allow setting values that are not
35 allowed for 'enabled'. Use `force_enabled` to set a non-boolean.
36
37 """
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053038 region = kwargs.get('region', None)
Brant Knudson3a9bdf92014-02-27 17:09:50 -060039 if 'force_enabled' in kwargs:
40 enabled = kwargs.get('force_enabled', None)
41 else:
42 enabled = kwargs.get('enabled', None)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053043 post_body = {
44 'service_id': service_id,
45 'interface': interface,
46 'url': url,
47 'region': region,
48 'enabled': enabled
49 }
50 post_body = json.dumps({'endpoint': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020051 resp, body = self.post('endpoints', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040052 self.expected_success(201, resp.status)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053053 body = json.loads(body)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000054 return service_client.ResponseBody(resp, body['endpoint'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053055
56 def update_endpoint(self, endpoint_id, service_id=None, interface=None,
Brant Knudson3a9bdf92014-02-27 17:09:50 -060057 url=None, region=None, enabled=None, **kwargs):
58 """Updates an endpoint with given parameters.
59
60 Normally this function wouldn't allow setting values that are not
61 allowed for 'enabled'. Use `force_enabled` to set a non-boolean.
62
63 """
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053064 post_body = {}
65 if service_id is not None:
66 post_body['service_id'] = service_id
67 if interface is not None:
68 post_body['interface'] = interface
69 if url is not None:
70 post_body['url'] = url
71 if region is not None:
72 post_body['region'] = region
Brant Knudson3a9bdf92014-02-27 17:09:50 -060073 if 'force_enabled' in kwargs:
74 post_body['enabled'] = kwargs['force_enabled']
75 elif enabled is not None:
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053076 post_body['enabled'] = enabled
77 post_body = json.dumps({'endpoint': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020078 resp, body = self.patch('endpoints/%s' % endpoint_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040079 self.expected_success(200, resp.status)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053080 body = json.loads(body)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000081 return service_client.ResponseBody(resp, body['endpoint'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053082
83 def delete_endpoint(self, endpoint_id):
84 """Delete endpoint."""
85 resp_header, resp_body = self.delete('endpoints/%s' % endpoint_id)
David Kranz2aaf5312014-08-29 09:22:10 -040086 self.expected_success(204, resp_header.status)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000087 return service_client.ResponseBody(resp_header, resp_body)