Nikolay Pliashechnikov | b053aab | 2013-11-05 06:06:44 -0800 | [diff] [blame] | 1 | # Copyright 2014 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 | |
| 16 | from lxml import etree |
| 17 | |
vponomaryov | 960eeb4 | 2014-02-22 18:25:25 +0200 | [diff] [blame] | 18 | from tempest.common import rest_client |
Eiichi Aikawa | ca3d9bd | 2014-03-06 15:06:21 +0900 | [diff] [blame] | 19 | from tempest.services.compute.xml import common |
Nikolay Pliashechnikov | b053aab | 2013-11-05 06:06:44 -0800 | [diff] [blame] | 20 | import tempest.services.telemetry.telemetry_client_base as client |
| 21 | |
| 22 | |
| 23 | class TelemetryClientXML(client.TelemetryClientBase): |
vponomaryov | 960eeb4 | 2014-02-22 18:25:25 +0200 | [diff] [blame] | 24 | TYPE = "xml" |
Nikolay Pliashechnikov | b053aab | 2013-11-05 06:06:44 -0800 | [diff] [blame] | 25 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 26 | def get_rest_client(self, auth_provider): |
vponomaryov | 960eeb4 | 2014-02-22 18:25:25 +0200 | [diff] [blame] | 27 | rc = rest_client.RestClient(auth_provider) |
| 28 | rc.TYPE = self.TYPE |
| 29 | return rc |
Nikolay Pliashechnikov | b053aab | 2013-11-05 06:06:44 -0800 | [diff] [blame] | 30 | |
| 31 | def _parse_array(self, body): |
| 32 | array = [] |
| 33 | for child in body.getchildren(): |
Eiichi Aikawa | ca3d9bd | 2014-03-06 15:06:21 +0900 | [diff] [blame] | 34 | array.append(common.xml_to_json(child)) |
Nikolay Pliashechnikov | b053aab | 2013-11-05 06:06:44 -0800 | [diff] [blame] | 35 | return array |
| 36 | |
| 37 | def serialize(self, body): |
Eiichi Aikawa | ca3d9bd | 2014-03-06 15:06:21 +0900 | [diff] [blame] | 38 | return str(common.Document(body)) |
Nikolay Pliashechnikov | b053aab | 2013-11-05 06:06:44 -0800 | [diff] [blame] | 39 | |
| 40 | def deserialize(self, body): |
| 41 | return self._parse_array(etree.fromstring(body)) |