1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
16 from toscaparser.common.exception import ExceptionCollector
17 from toscaparser.common.exception import UnknownFieldError
18 from toscaparser.entity_template import EntityTemplate
20 SECTIONS = (DESCRIPTION, EVENT, SCHEDULE, TARGET_FILTER, CONDITION, ACTION) = \
21 ('description', 'event_type', 'schedule',
22 'target_filter', 'condition', 'action')
23 CONDITION_KEYNAMES = (CONTRAINT, PERIOD, EVALUATIONS, METHOD) = \
24 ('constraint', 'period', 'evaluations', 'method')
25 log = logging.getLogger('tosca')
28 class Triggers(EntityTemplate):
30 '''Triggers defined in policies of topology template'''
32 def __init__(self, name, trigger_tpl):
34 self.trigger_tpl = trigger_tpl
36 self._validate_condition()
38 def get_description(self):
39 return self.trigger_tpl['description']
42 return self.trigger_tpl['event_type']
44 def get_schedule(self):
45 return self.trigger_tpl['schedule']
47 def get_target_filter(self):
48 return self.trigger_tpl['target_filter']
50 def get_condition(self):
51 return self.trigger_tpl['condition']
54 return self.trigger_tpl['action']
56 def _validate_keys(self):
57 for key in self.trigger_tpl.keys():
58 if key not in SECTIONS:
59 ExceptionCollector.appendException(
60 UnknownFieldError(what='Triggers "%s"' % self.name,
63 def _validate_condition(self):
64 for key in self.get_condition():
65 if key not in CONDITION_KEYNAMES:
66 ExceptionCollector.appendException(
67 UnknownFieldError(what='Triggers "%s"' % self.name,