~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/engine/properties.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-10-03 09:43:04 UTC
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20131003094304-zhhr2brapzlpvjmm
Tags: upstream-2013.2~rc1
ImportĀ upstreamĀ versionĀ 2013.2~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from heat.common import exception
20
20
from heat.engine import parameters
 
21
from heat.engine import hot
21
22
 
22
23
SCHEMA_KEYS = (
23
24
    REQUIRED, IMPLEMENTED, DEFAULT, TYPE, SCHEMA,
191
192
            parameters.JSON: MAP
192
193
        }
193
194
 
 
195
        def get_num(key, context=param):
 
196
            val = context.get(key)
 
197
            if val is not None:
 
198
                val = Property.str_to_num(val)
 
199
            return val
 
200
 
194
201
        def constraints():
195
 
            def get_num(key):
196
 
                val = param.get(key)
197
 
                if val is not None:
198
 
                    val = Property.str_to_num(val)
199
 
                return val
200
 
 
201
202
            desc = param.get(parameters.CONSTRAINT_DESCRIPTION)
202
203
 
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)
214
215
 
 
216
        def constraints_hot():
 
217
            constraints = param.get(hot.CONSTRAINTS)
 
218
            if constraints is None:
 
219
                return
 
220
 
 
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)
 
237
 
 
238
        if isinstance(param, hot.HOTParamSchema):
 
239
            constraint_list = list(constraints_hot())
 
240
        else:
 
241
            constraint_list = list(constraints())
 
242
 
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)
219
247
 
220
248
    def validate_constraints(self, value):
221
249
        for constraint in self.constraints:
683
711
        prop = self.props[key]
684
712
 
685
713
        if key in self.data:
686
 
            value = self.resolve(self.data[key])
687
714
            try:
 
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()