Nikolay Pliashechnikov | b053aab | 2013-11-05 06:06:44 -0800 | [diff] [blame^] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2014 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 | from tempest.common.rest_client import RestClient |
| 19 | from tempest.openstack.common import jsonutils as json |
| 20 | import tempest.services.telemetry.telemetry_client_base as client |
| 21 | |
| 22 | |
| 23 | class TelemetryClientJSON(client.TelemetryClientBase): |
| 24 | |
| 25 | def get_rest_client(self, config, username, |
| 26 | password, auth_url, tenant_name=None): |
| 27 | return RestClient(config, username, password, auth_url, tenant_name) |
| 28 | |
| 29 | def deserialize(self, body): |
| 30 | return json.loads(body.replace("\n", "")) |
| 31 | |
| 32 | def serialize(self, body): |
| 33 | return json.dumps(body) |
| 34 | |
| 35 | def create_alarm(self, **kwargs): |
| 36 | uri = "%s/alarms" % self.uri_prefix |
| 37 | return self.post(uri, kwargs) |
| 38 | |
| 39 | def add_sample(self, sample_list, meter_name, meter_unit, volume, |
| 40 | sample_type, resource_id, **kwargs): |
| 41 | sample = {"counter_name": meter_name, "counter_unit": meter_unit, |
| 42 | "counter_volume": volume, "counter_type": sample_type, |
| 43 | "resource_id": resource_id} |
| 44 | for key in kwargs: |
| 45 | sample[key] = kwargs[key] |
| 46 | |
| 47 | sample_list.append(self.serialize(sample)) |
| 48 | return sample_list |
| 49 | |
| 50 | def create_sample(self, meter_name, sample_list): |
| 51 | uri = "%s/meters/%s" % (self.uri_prefix, meter_name) |
| 52 | return self.post(uri, str(sample_list)) |