blob: c3fedb28f5c8c2ed6de073d8b55ada4c3666130d [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
16import json
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053017
Haiwei Xuaad85db2014-03-05 05:17:39 +090018from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053022
23
Haiwei Xuaad85db2014-03-05 05:17:39 +090024class EndPointClientJSON(rest_client.RestClient):
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053025
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000026 def __init__(self, auth_provider):
27 super(EndPointClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.identity.catalog_type
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053029 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000030 self.api_version = "v3"
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053031
32 def list_endpoints(self):
33 """GET endpoints."""
34 resp, body = self.get('endpoints')
David Kranz2aaf5312014-08-29 09:22:10 -040035 self.expected_success(200, resp.status)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053036 body = json.loads(body)
37 return resp, body['endpoints']
38
39 def create_endpoint(self, service_id, interface, url, **kwargs):
Brant Knudson3a9bdf92014-02-27 17:09:50 -060040 """Create endpoint.
41
42 Normally this function wouldn't allow setting values that are not
43 allowed for 'enabled'. Use `force_enabled` to set a non-boolean.
44
45 """
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053046 region = kwargs.get('region', None)
Brant Knudson3a9bdf92014-02-27 17:09:50 -060047 if 'force_enabled' in kwargs:
48 enabled = kwargs.get('force_enabled', None)
49 else:
50 enabled = kwargs.get('enabled', None)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053051 post_body = {
52 'service_id': service_id,
53 'interface': interface,
54 'url': url,
55 'region': region,
56 'enabled': enabled
57 }
58 post_body = json.dumps({'endpoint': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020059 resp, body = self.post('endpoints', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040060 self.expected_success(201, resp.status)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053061 body = json.loads(body)
62 return resp, body['endpoint']
63
64 def update_endpoint(self, endpoint_id, service_id=None, interface=None,
Brant Knudson3a9bdf92014-02-27 17:09:50 -060065 url=None, region=None, enabled=None, **kwargs):
66 """Updates an endpoint with given parameters.
67
68 Normally this function wouldn't allow setting values that are not
69 allowed for 'enabled'. Use `force_enabled` to set a non-boolean.
70
71 """
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053072 post_body = {}
73 if service_id is not None:
74 post_body['service_id'] = service_id
75 if interface is not None:
76 post_body['interface'] = interface
77 if url is not None:
78 post_body['url'] = url
79 if region is not None:
80 post_body['region'] = region
Brant Knudson3a9bdf92014-02-27 17:09:50 -060081 if 'force_enabled' in kwargs:
82 post_body['enabled'] = kwargs['force_enabled']
83 elif enabled is not None:
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053084 post_body['enabled'] = enabled
85 post_body = json.dumps({'endpoint': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020086 resp, body = self.patch('endpoints/%s' % endpoint_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040087 self.expected_success(200, resp.status)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053088 body = json.loads(body)
89 return resp, body['endpoint']
90
91 def delete_endpoint(self, endpoint_id):
92 """Delete endpoint."""
93 resp_header, resp_body = self.delete('endpoints/%s' % endpoint_id)
David Kranz2aaf5312014-08-29 09:22:10 -040094 self.expected_success(204, resp_header.status)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053095 return resp_header, resp_body