blob: a1112da73597369d34df10d5327b0d7ff4713c67 [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
Matthew Treinish684d8992014-01-30 16:27:40 +000023 def get_rest_client(self, username,
Nikolay Pliashechnikovb053aab2013-11-05 06:06:44 -080024 password, auth_url, tenant_name=None):
Matthew Treinish684d8992014-01-30 16:27:40 +000025 return RestClient(username, password, auth_url, tenant_name)
Nikolay Pliashechnikovb053aab2013-11-05 06:06:44 -080026
27 def deserialize(self, body):
28 return json.loads(body.replace("\n", ""))
29
30 def serialize(self, body):
31 return json.dumps(body)
32
33 def create_alarm(self, **kwargs):
34 uri = "%s/alarms" % self.uri_prefix
35 return self.post(uri, kwargs)
36
37 def add_sample(self, sample_list, meter_name, meter_unit, volume,
38 sample_type, resource_id, **kwargs):
39 sample = {"counter_name": meter_name, "counter_unit": meter_unit,
40 "counter_volume": volume, "counter_type": sample_type,
41 "resource_id": resource_id}
42 for key in kwargs:
43 sample[key] = kwargs[key]
44
45 sample_list.append(self.serialize(sample))
46 return sample_list
47
48 def create_sample(self, meter_name, sample_list):
49 uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
50 return self.post(uri, str(sample_list))