blob: f81fccf2971b3e5de5a8b18470f901167da848c4 [file] [log] [blame]
rajalakshmi-ganesanab426722013-02-08 15:49:15 +05301# 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.
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070017import urlparse
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053018
19import httplib2
20from lxml import etree
21
22from tempest.common.rest_client import RestClientXML
23from tempest.services.compute.xml.common import Document
24from tempest.services.compute.xml.common import Element
25from tempest.services.compute.xml.common import xml_to_json
26
27XMLNS = "http://docs.openstack.org/identity/api/v3"
28
29
30class EndPointClientXML(RestClientXML):
31
32 def __init__(self, config, username, password, auth_url, tenant_name=None):
33 super(EndPointClientXML, self).__init__(config, username, password,
34 auth_url, tenant_name)
35 self.service = self.config.identity.catalog_type
36 self.endpoint_url = 'adminURL'
37
38 def _parse_array(self, node):
39 array = []
40 for child in node.getchildren():
41 tag_list = child.tag.split('}', 1)
42 if tag_list[1] == "endpoint":
43 array.append(xml_to_json(child))
44 return array
45
46 def _parse_body(self, body):
47 json = xml_to_json(body)
48 return json
49
50 def request(self, method, url, headers=None, body=None, wait=None):
51 """Overriding the existing HTTP request in super class RestClient."""
52 dscv = self.config.identity.disable_ssl_certificate_validation
53 self.http_obj = httplib2.Http(disable_ssl_certificate_validation=dscv)
54 self._set_auth()
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070055 self.base_url = self.base_url.replace(
56 urlparse.urlparse(self.base_url).path, "/v3")
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053057 return super(EndPointClientXML, self).request(method, url,
58 headers=headers,
59 body=body)
60
61 def list_endpoints(self):
62 """Get the list of endpoints."""
63 resp, body = self.get("endpoints", self.headers)
64 body = self._parse_array(etree.fromstring(body))
65 return resp, body
66
67 def create_endpoint(self, service_id, interface, url, **kwargs):
68 """Create endpoint."""
69 region = kwargs.get('region', None)
70 enabled = kwargs.get('enabled', None)
71 create_endpoint = Element("endpoint",
72 xmlns=XMLNS,
73 service_id=service_id,
74 interface=interface,
75 url=url, region=region,
76 enabled=enabled)
77 resp, body = self.post('endpoints', str(Document(create_endpoint)),
78 self.headers)
79 body = self._parse_body(etree.fromstring(body))
80 return resp, body
81
82 def update_endpoint(self, endpoint_id, service_id=None, interface=None,
83 url=None, region=None, enabled=None):
84 """Updates an endpoint with given parameters."""
85 doc = Document()
86 endpoint = Element("endpoint")
87 doc.append(endpoint)
88
89 if service_id:
90 endpoint.add_attr("service_id", service_id)
91 if interface:
92 endpoint.add_attr("interface", interface)
93 if url:
94 endpoint.add_attr("url", url)
95 if region:
96 endpoint.add_attr("region", region)
97 if enabled is not None:
98 endpoint.add_attr("enabled", enabled)
99 resp, body = self.patch('endpoints/%s' % str(endpoint_id),
100 str(doc), self.headers)
101 body = self._parse_body(etree.fromstring(body))
102 return resp, body
103
104 def delete_endpoint(self, endpoint_id):
105 """Delete endpoint."""
106 resp_header, resp_body = self.delete('endpoints/%s' % endpoint_id)
107 return resp_header, resp_body