rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | # |
| 3 | # Copyright 2013 OpenStack Foundation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | import json |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 19 | import urlparse |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 20 | |
| 21 | from tempest.common.rest_client import RestClient |
| 22 | |
| 23 | |
| 24 | class EndPointClientJSON(RestClient): |
| 25 | |
| 26 | def __init__(self, config, username, password, auth_url, tenant_name=None): |
| 27 | super(EndPointClientJSON, self).__init__(config, |
| 28 | username, password, |
| 29 | auth_url, tenant_name) |
| 30 | self.service = self.config.identity.catalog_type |
| 31 | self.endpoint_url = 'adminURL' |
| 32 | |
| 33 | def request(self, method, url, headers=None, body=None, wait=None): |
| 34 | """Overriding the existing HTTP request in super class rest_client.""" |
| 35 | self._set_auth() |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 36 | self.base_url = self.base_url.replace( |
| 37 | urlparse.urlparse(self.base_url).path, "/v3") |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 38 | return super(EndPointClientJSON, self).request(method, url, |
| 39 | headers=headers, |
| 40 | body=body) |
| 41 | |
| 42 | def list_endpoints(self): |
| 43 | """GET endpoints.""" |
| 44 | resp, body = self.get('endpoints') |
| 45 | body = json.loads(body) |
| 46 | return resp, body['endpoints'] |
| 47 | |
| 48 | def create_endpoint(self, service_id, interface, url, **kwargs): |
| 49 | """Create endpoint.""" |
| 50 | region = kwargs.get('region', None) |
| 51 | enabled = kwargs.get('enabled', None) |
| 52 | post_body = { |
| 53 | 'service_id': service_id, |
| 54 | 'interface': interface, |
| 55 | 'url': url, |
| 56 | 'region': region, |
| 57 | 'enabled': enabled |
| 58 | } |
| 59 | post_body = json.dumps({'endpoint': post_body}) |
| 60 | resp, body = self.post('endpoints', post_body, self.headers) |
| 61 | body = json.loads(body) |
| 62 | return resp, body['endpoint'] |
| 63 | |
| 64 | def update_endpoint(self, endpoint_id, service_id=None, interface=None, |
| 65 | url=None, region=None, enabled=None): |
| 66 | """Updates an endpoint with given parameters.""" |
| 67 | post_body = {} |
| 68 | if service_id is not None: |
| 69 | post_body['service_id'] = service_id |
| 70 | if interface is not None: |
| 71 | post_body['interface'] = interface |
| 72 | if url is not None: |
| 73 | post_body['url'] = url |
| 74 | if region is not None: |
| 75 | post_body['region'] = region |
| 76 | if enabled is not None: |
| 77 | post_body['enabled'] = enabled |
| 78 | post_body = json.dumps({'endpoint': post_body}) |
| 79 | resp, body = self.patch('endpoints/%s' % endpoint_id, post_body, |
| 80 | self.headers) |
| 81 | body = json.loads(body) |
| 82 | return resp, body['endpoint'] |
| 83 | |
| 84 | def delete_endpoint(self, endpoint_id): |
| 85 | """Delete endpoint.""" |
| 86 | resp_header, resp_body = self.delete('endpoints/%s' % endpoint_id) |
| 87 | return resp_header, resp_body |