blob: 747d7c17a9ca09c9dabb3611ca27d415adde4669 [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
16from tempest.common.rest_client import RestClient
17from 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):
24 return 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
32 def create_alarm(self, **kwargs):
33 uri = "%s/alarms" % self.uri_prefix
34 return self.post(uri, kwargs)
35
36 def add_sample(self, sample_list, meter_name, meter_unit, volume,
37 sample_type, resource_id, **kwargs):
38 sample = {"counter_name": meter_name, "counter_unit": meter_unit,
39 "counter_volume": volume, "counter_type": sample_type,
40 "resource_id": resource_id}
41 for key in kwargs:
42 sample[key] = kwargs[key]
43
44 sample_list.append(self.serialize(sample))
45 return sample_list
46
47 def create_sample(self, meter_name, sample_list):
48 uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
49 return self.post(uri, str(sample_list))