blob: f7a894bf285f697bb21315e26e12902f006c8ff4 [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')
35 body = json.loads(body)
36 return resp, body['endpoints']
37
38 def create_endpoint(self, service_id, interface, url, **kwargs):
Brant Knudson3a9bdf92014-02-27 17:09:50 -060039 """Create endpoint.
40
41 Normally this function wouldn't allow setting values that are not
42 allowed for 'enabled'. Use `force_enabled` to set a non-boolean.
43
44 """
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053045 region = kwargs.get('region', None)
Brant Knudson3a9bdf92014-02-27 17:09:50 -060046 if 'force_enabled' in kwargs:
47 enabled = kwargs.get('force_enabled', None)
48 else:
49 enabled = kwargs.get('enabled', None)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053050 post_body = {
51 'service_id': service_id,
52 'interface': interface,
53 'url': url,
54 'region': region,
55 'enabled': enabled
56 }
57 post_body = json.dumps({'endpoint': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020058 resp, body = self.post('endpoints', post_body)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053059 body = json.loads(body)
60 return resp, body['endpoint']
61
62 def update_endpoint(self, endpoint_id, service_id=None, interface=None,
Brant Knudson3a9bdf92014-02-27 17:09:50 -060063 url=None, region=None, enabled=None, **kwargs):
64 """Updates an endpoint with given parameters.
65
66 Normally this function wouldn't allow setting values that are not
67 allowed for 'enabled'. Use `force_enabled` to set a non-boolean.
68
69 """
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053070 post_body = {}
71 if service_id is not None:
72 post_body['service_id'] = service_id
73 if interface is not None:
74 post_body['interface'] = interface
75 if url is not None:
76 post_body['url'] = url
77 if region is not None:
78 post_body['region'] = region
Brant Knudson3a9bdf92014-02-27 17:09:50 -060079 if 'force_enabled' in kwargs:
80 post_body['enabled'] = kwargs['force_enabled']
81 elif enabled is not None:
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053082 post_body['enabled'] = enabled
83 post_body = json.dumps({'endpoint': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020084 resp, body = self.patch('endpoints/%s' % endpoint_id, post_body)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053085 body = json.loads(body)
86 return resp, body['endpoint']
87
88 def delete_endpoint(self, endpoint_id):
89 """Delete endpoint."""
90 resp_header, resp_body = self.delete('endpoints/%s' % endpoint_id)
91 return resp_header, resp_body