summaryrefslogtreecommitdiffstats
path: root/nfvparser/toscaparser/triggers.py
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2017-09-26 20:40:39 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2017-09-26 20:47:53 +0800
commit000ea52b78b072435f01d67dd799023117e67a2e (patch)
tree1f14cdb4485e2184904b553b82afd9e7139a18e5 /nfvparser/toscaparser/triggers.py
parent53065490134870ead778bff590cfd9e43ddd9f77 (diff)
Sync code from nfv-toscaprser
Currently nfv-toscaparser has published the regular version of 0.5.1 the patch will synchronize the code. JIRA: MODELING-23 Change-Id: If95579fc366b69b2b14b2e441ff9a3e6807e3820 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'nfvparser/toscaparser/triggers.py')
-rw-r--r--nfvparser/toscaparser/triggers.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/nfvparser/toscaparser/triggers.py b/nfvparser/toscaparser/triggers.py
index 9edeef4..8e47eee 100644
--- a/nfvparser/toscaparser/triggers.py
+++ b/nfvparser/toscaparser/triggers.py
@@ -16,12 +16,16 @@ import logging
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import UnknownFieldError
from toscaparser.entity_template import EntityTemplate
-
-SECTIONS = (DESCRIPTION, EVENT, SCHEDULE, TARGET_FILTER, CONDITION, ACTION) = \
- ('description', 'event_type', 'schedule',
- 'target_filter', 'condition', 'action')
-CONDITION_KEYNAMES = (CONTRAINT, PERIOD, EVALUATIONS, METHOD) = \
- ('constraint', 'period', 'evaluations', 'method')
+from toscaparser.utils import validateutils
+
+SECTIONS = (DESCRIPTION, EVENT, SCHEDULE, METER_NAME, METADATA,
+ TARGET_FILTER, CONDITION, ACTION) = \
+ ('description', 'event_type', 'schedule', 'meter_name',
+ 'metadata', 'target_filter', 'condition', 'action')
+CONDITION_KEYNAMES = (CONSTRAINT, PERIOD, EVALUATIONS, METHOD,
+ THRESHOLD, COMPARISON_OPERATOR) = \
+ ('constraint', 'period', 'evaluations',
+ 'method', 'threshold', 'comparison_operator')
log = logging.getLogger('tosca')
@@ -34,6 +38,7 @@ class Triggers(EntityTemplate):
self.trigger_tpl = trigger_tpl
self._validate_keys()
self._validate_condition()
+ self._validate_input()
def get_description(self):
return self.trigger_tpl['description']
@@ -66,3 +71,12 @@ class Triggers(EntityTemplate):
ExceptionCollector.appendException(
UnknownFieldError(what='Triggers "%s"' % self.name,
field=key))
+
+ def _validate_input(self):
+ for key, value in self.get_condition().items():
+ if key in [PERIOD, EVALUATIONS]:
+ validateutils.validate_integer(value)
+ elif key == THRESHOLD:
+ validateutils.validate_numeric(value)
+ elif key in [METER_NAME, METHOD]:
+ validateutils.validate_string(value)