Debian Codegraph @

monascaclient/v2_0/notifications.py

raw
1 # (C) Copyright 2014-2016 Hewlett Packard Enterprise Development 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 NotificationsManager(monasca_manager.MonascaManager):
21 base_url = '/notification-methods'
22
23 def create(self, **kwargs):
24 """Create a notification."""
25 body = self.client.create(url=self.base_url,
26 json=kwargs)
27 return body
28
29 def get(self, **kwargs):
30 """Get the details for a specific notification."""
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['notification_id'])
36 resp = self.client.list(path=url)
37 return resp
38
39 def list(self, **kwargs):
40 """Get a list of notifications."""
41 return self._list('', **kwargs)
42
43 def delete(self, **kwargs):
44 """Delete a notification."""
45 url = self.base_url + '/%s' % kwargs['notification_id']
46 resp = self.client.delete(url=url)
47 return resp
48
49 def update(self, **kwargs):
50 """Update a notification."""
51 url_str = self.base_url + '/%s' % kwargs['notification_id']
52 del kwargs['notification_id']
53
54 resp = self.client.create(url=url_str,
55 method='PUT',
56 json=kwargs)
57 return resp
58
59 def patch(self, **kwargs):
60 """Patch a notification."""
61 url_str = self.base_url + '/%s' % kwargs['notification_id']
62 del kwargs['notification_id']
63
64 resp = self.client.create(url=url_str,
65 method='PATCH',
66 json=kwargs)
67
68 return resp