blob: 996aceb4ccebfb7c5d8da25baf5ff77fa4949ea7 [file] [log] [blame]
Nikolay Pliashechnikovb053aab2013-11-05 06:06:44 -08001# 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
Eiichi Aikawaca3d9bd2014-03-06 15:06:21 +090016from tempest.common import rest_client
Nikolay Pliashechnikovb053aab2013-11-05 06:06:44 -080017from tempest.openstack.common import jsonutils as json
18import tempest.services.telemetry.telemetry_client_base as client
19
20
21class TelemetryClientJSON(client.TelemetryClientBase):
22
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000023 def get_rest_client(self, auth_provider):
Eiichi Aikawaca3d9bd2014-03-06 15:06:21 +090024 return rest_client.RestClient(auth_provider)
Nikolay Pliashechnikovb053aab2013-11-05 06:06:44 -080025
26 def deserialize(self, body):
27 return json.loads(body.replace("\n", ""))
28
29 def serialize(self, body):
30 return json.dumps(body)
31
Nikolay Pliashechnikovb053aab2013-11-05 06:06:44 -080032 def add_sample(self, sample_list, meter_name, meter_unit, volume,
33 sample_type, resource_id, **kwargs):
34 sample = {"counter_name": meter_name, "counter_unit": meter_unit,
35 "counter_volume": volume, "counter_type": sample_type,
36 "resource_id": resource_id}
37 for key in kwargs:
38 sample[key] = kwargs[key]
39
40 sample_list.append(self.serialize(sample))
41 return sample_list
42
43 def create_sample(self, meter_name, sample_list):
44 uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
45 return self.post(uri, str(sample_list))