**** CubicPower OpenStack Study ****
def validate(filter, value):
return FILTER_FUNCTIONS.get(filter, lambda v: True)(value)
**** CubicPower OpenStack Study ****
def validate_int_in_range(min=0, max=None):
def _validator(v):
try:
if max is None:
return min <= int(v)
return min <= int(v) <= max
except ValueError:
return False
return _validator
**** CubicPower OpenStack Study ****
def validate_boolean(v):
return v.lower() in ('none', 'true', 'false', '1', '0')
FILTER_FUNCTIONS = {'size_max': validate_int_in_range(), # build validator
'size_min': validate_int_in_range(), # build validator
'min_ram': validate_int_in_range(), # build validator
'protected': validate_boolean,
'is_public': validate_boolean, }