19
19
from heat.common import exception
20
20
from heat.engine import parameters
21
from heat.engine import hot
23
24
REQUIRED, IMPLEMENTED, DEFAULT, TYPE, SCHEMA,
191
192
parameters.JSON: MAP
195
def get_num(key, context=param):
196
val = context.get(key)
198
val = Property.str_to_num(val)
194
201
def constraints():
198
val = Property.str_to_num(val)
201
202
desc = param.get(parameters.CONSTRAINT_DESCRIPTION)
203
204
if parameters.MIN_VALUE in param or parameters.MAX_VALUE in param:
212
213
if parameters.ALLOWED_PATTERN in param:
213
214
yield AllowedPattern(param[parameters.ALLOWED_PATTERN], desc)
216
def constraints_hot():
217
constraints = param.get(hot.CONSTRAINTS)
218
if constraints is None:
221
for constraint in constraints:
222
desc = constraint.get(hot.DESCRIPTION)
223
if hot.RANGE in constraint:
224
const_def = constraint.get(hot.RANGE)
225
yield Range(get_num(hot.MIN, const_def),
226
get_num(hot.MAX, const_def), desc)
227
if hot.LENGTH in constraint:
228
const_def = constraint.get(hot.LENGTH)
229
yield Length(get_num(hot.MIN, const_def),
230
get_num(hot.MAX, const_def), desc)
231
if hot.ALLOWED_VALUES in constraint:
232
const_def = constraint.get(hot.ALLOWED_VALUES)
233
yield AllowedValues(const_def, desc)
234
if hot.ALLOWED_PATTERN in constraint:
235
const_def = constraint.get(hot.ALLOWED_PATTERN)
236
yield AllowedPattern(const_def, desc)
238
if isinstance(param, hot.HOTParamSchema):
239
constraint_list = list(constraints_hot())
241
constraint_list = list(constraints())
215
243
return cls(param_type_map.get(param[parameters.TYPE], MAP),
216
244
description=param.get(parameters.DESCRIPTION),
217
245
required=parameters.DEFAULT not in param,
218
constraints=list(constraints()))
246
constraints=constraint_list)
220
248
def validate_constraints(self, value):
221
249
for constraint in self.constraints:
683
711
prop = self.props[key]
685
713
if key in self.data:
686
value = self.resolve(self.data[key])
715
value = self.resolve(self.data[key])
688
716
return prop.validate_data(value)
689
except ValueError as e:
717
# the resolver function could raise any number of exceptions,
718
# so handle this generically
719
except Exception as e:
690
720
raise ValueError(self.error_prefix + '%s %s' % (key, str(e)))
691
721
elif prop.has_default():
692
722
return prop.default()