3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from cmframework.utils.cmalarmhandler import AlarmHandler
20 class CMAlarm(object):
21 NODE_REBOOT_REQUEST_ALARM = '45001'
22 ACTIVATION_FAILED_ALARM = '45002'
24 def _get_alarm_id(self):
25 raise NotImplementedError('Not implemented alarm')
27 def raise_alarm_for_node(self, node_name, supplementary_info=None):
28 logging.debug('raise_alarm_for_node called with %s %s', node_name, supplementary_info)
30 self._raise_alarm_with_dn('NODE-{}'.format(node_name), supplementary_info)
32 def raise_alarm_for_sg(self, sg_name, supplementary_info=None):
33 logging.debug('raise_alarm_for_sg called with %s %s', sg_name, supplementary_info)
35 self._raise_alarm_with_dn('SG-{}'.format(sg_name), supplementary_info)
37 def _raise_alarm_with_dn(self, dn, supplementary_info=None):
38 logging.debug('raise_alarm called for %s with %s %s',
43 if not supplementary_info:
44 supplementary_info = {}
47 alarm_handler = AlarmHandler()
49 alarm_handler.raise_alarm_with_dn(self._get_alarm_id(),
52 except Exception as ex: # pylint: disable=broad-except
53 logging.warning('Alarm raising failed: %s', str(ex))
55 def cancel_alarm_for_node(self, node_name, supplementary_info=None):
56 logging.debug('cancel_alarm called with %s %s', node_name, supplementary_info)
58 self._cancel_alarm_with_dn('NODE-{}'.format(node_name), supplementary_info)
60 def cancel_alarm_for_sg(self, sg_name, supplementary_info=None):
61 logging.debug('cancel_alarm called with %s %s', sg_name, supplementary_info)
63 self._cancel_alarm_with_dn('SG-{}'.format(sg_name), supplementary_info)
65 def _cancel_alarm_with_dn(self, dn, supplementary_info=None):
66 logging.debug('cancel_alarm called for %s with %s %s',
71 if not supplementary_info:
72 supplementary_info = {}
75 alarm_handler = AlarmHandler()
77 alarm_handler.cancel_alarm_with_dn(self._get_alarm_id(),
80 except Exception as ex: # pylint: disable=broad-except
81 logging.warning('Alarm canceling failed: %s', str(ex))
84 class CMRebootRequestAlarm(CMAlarm):
85 def _get_alarm_id(self):
86 return CMAlarm.NODE_REBOOT_REQUEST_ALARM
89 class CMActivationFailedAlarm(CMAlarm):
90 def _get_alarm_id(self):
91 return CMAlarm.ACTIVATION_FAILED_ALARM