Debian Codegraph @

monascaclient/v2_0/alarm_definitions.py

raw
1 # (C) Copyright 2014-2015 Hewlett Packard Enterprise Development Company LP
2 # Copyright 2017 FUJITSU LIMITED
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain 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,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 from monascaclient.common import monasca_manager
18
19
20 class AlarmDefinitionsManager(monasca_manager.MonascaManager):
21 base_url = '/alarm-definitions'
22
23 def create(self, **kwargs):
24 """Create an alarm definition."""
25 resp = self.client.create(url=self.base_url,
26 json=kwargs)
27 return resp
28
29 def get(self, **kwargs):
30 """Get the details for a specific alarm definition."""
31
32 # NOTE(trebskit) should actually be find_one, but
33 # monasca does not support expected response format
34
35 url = '%s/%s' % (self.base_url, kwargs['alarm_id'])
36 resp = self.client.list(path=url)
37 return resp
38
39 def list(self, **kwargs):
40 """Get a list of alarm definitions."""
41 return self._list('', 'dimensions', **kwargs)
42
43 def delete(self, **kwargs):
44 """Delete a specific alarm definition."""
45 url_str = self.base_url + '/%s' % kwargs['alarm_id']
46 resp = self.client.delete(url_str)
47 return resp
48
49 def update(self, **kwargs):
50 """Update a specific alarm definition."""
51 url_str = self.base_url + '/%s' % kwargs['alarm_id']
52 del kwargs['alarm_id']
53
54 resp = self.client.create(url=url_str,
55 method='PUT',
56 json=kwargs)
57
58 return resp
59
60 def patch(self, **kwargs):
61 """Patch a specific alarm definition."""
62 url_str = self.base_url + '/%s' % kwargs['alarm_id']
63 del kwargs['alarm_id']
64
65 resp = self.client.create(url=url_str,
66 method='PATCH',
67 json=kwargs)
68
69 return resp