def _validate_occurrences(self, occurrences): DataEntity.validate_datatype('list', occurrences) for value in occurrences: DataEntity.validate_datatype('integer', value) if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \ or occurrences[1] == 0: raise InvalidPropertyValueError(what=(occurrences))
def _validate_occurrences(self, occurrences): DataEntity.validate_datatype('list', occurrences) for value in occurrences: DataEntity.validate_datatype('integer', value) if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \ or occurrences[1] == 0: ExceptionCollector.appendException( InvalidPropertyValueError(what=(occurrences)))
def _translate_inputs(self): hot_inputs = [] log.info(_('Translating TOSCA input type to HOT input type.')) for input in self.inputs: hot_default = None hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type] if input.name in self.parsed_params: hot_default = DataEntity.validate_datatype( input.type, self.parsed_params[input.name]) elif input.default is not None: hot_default = DataEntity.validate_datatype( input.type, input.default) else: if self.deploy: msg = _("Need to specify a value " "for input {0}.").format(input.name) log.error(msg) raise Exception(msg) if input.type == "scalar-unit.size": # Assumption here is to use this scalar-unit.size for size of # cinder volume in heat templates and will be in GB. # should add logic to support other types if needed. input_value = hot_default hot_default = (ScalarUnit_Size( hot_default).get_num_from_scalar_unit('GiB')) if hot_default == 0: msg = _('Unit value should be > 0.') log.error(msg) raise Exception(msg) elif int(hot_default) < hot_default: hot_default = int(hot_default) + 1 log.warning( _("Cinder unit value should be in multiples" " of GBs. So corrected %(input_value)s " "to %(hot_default)s GB.") % { 'input_value': input_value, 'hot_default': hot_default }) if input.type == 'version': hot_default = TOSCAVersionProperty(hot_default).get_version() hot_constraints = [] if input.constraints: for constraint in input.constraints: if hot_default: constraint.validate(hot_default) hc, hvalue = self._translate_constraints( constraint.constraint_key, constraint.constraint_value) hot_constraints.append({hc: hvalue}) hot_inputs.append( HotParameter(name=input.name, type=hot_input_type, description=input.description, default=hot_default, constraints=hot_constraints)) return hot_inputs
def _translate_inputs(self): hot_inputs = [] hot_default = None for input in self.inputs: hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type] if input.name in self.parsed_params: input_type = hot_input_type if input.type == "scalar-unit.size": input_type = input.type DataEntity.validate_datatype(input_type, self.parsed_params[input.name]) hot_default = self.parsed_params[input.name] elif input.default is not None: hot_default = input.default else: log.warning(_("Need to specify a value " "for input {0}").format(input.name)) raise Exception(_("Need to specify a value " "for input {0}").format(input.name)) if input.type == "scalar-unit.size": # Assumption here is to use this scalar-unit.size for size of # cinder volume in heat templates and will be in GB. # should add logic to support other types if needed. input_value = hot_default hot_default = (ScalarUnit_Size(hot_default). get_num_from_scalar_unit('GiB')) if hot_default == 0: log.warning(_('Unit value should be > 0.')) raise Exception(_( 'Unit value should be > 0.')) elif int(hot_default) < hot_default: hot_default = int(hot_default) + 1 log.warning(_("Cinder unit value should be in multiples" " of GBs. So corrected %(input_value)s " "to %(hot_default)s GB.") % {'input_value': input_value, 'hot_default': hot_default}) if input.type == 'version': hot_default = TOSCAVersionProperty(hot_default).get_version() hot_constraints = [] if input.constraints: for constraint in input.constraints: constraint.validate( int(hot_default) if hot_input_type == "number" else hot_default) hc, hvalue = self._translate_constraints( constraint.constraint_key, constraint.constraint_value) hot_constraints.append({hc: hvalue}) hot_inputs.append(HotParameter(name=input.name, type=hot_input_type, description=input.description, default=hot_default, constraints=hot_constraints)) return hot_inputs
def _validate_value(self, value): tosca = EntityType.TOSCA_DEF datatype = None if self.type in tosca: datatype = tosca[self.type] elif EntityType.DATATYPE_NETWORK_PREFIX + self.type in tosca: datatype = tosca[EntityType.DATATYPE_NETWORK_PREFIX + self.type] DataEntity.validate_datatype(self.type, value, None, datatype)
def result(self): if self.tosca_tpl.parsed_params and self.input_name in self.tosca_tpl.parsed_params: return DataEntity.validate_datatype( self.tosca_tpl.tpl["inputs"][self.input_name]["type"], self.tosca_tpl.parsed_params[self.input_name] ) input = [input_def for input_def in self.tosca_tpl.inputs if self.input_name == input_def.name][0] return input.default
def validate(self): '''Validate if not a reference property.''' if not is_function(self.value): if self.type == Schema.STRING: self.value = str(self.value) self.value = DataEntity.validate_datatype(self.type, self.value, self.entry_schema, self.custom_def) self._validate_constraints()
def _groups(self): groups = [] member_nodes = None for group_name, group_tpl in self._tpl_groups().items(): member_names = group_tpl.get('members') if member_names is not None: DataEntity.validate_datatype('list', member_names) if len(member_names) < 1 or \ len(member_names) != len(set(member_names)): exception.ExceptionCollector.appendException( exception.InvalidGroupTargetException( message=_('Member nodes "%s" should be >= 1 ' 'and not repeated') % member_names)) else: member_nodes = self._get_group_members(member_names) group = Group(group_name, group_tpl, member_nodes, self.custom_defs) groups.append(group) return groups
def result(self): if self.tosca_tpl.parsed_params and \ self.input_name in self.tosca_tpl.parsed_params: return DataEntity.validate_datatype( self.tosca_tpl.tpl['inputs'][self.input_name]['type'], self.tosca_tpl.parsed_params[self.input_name]) input = [input_def for input_def in self.tosca_tpl.inputs if self.input_name == input_def.name][0] return input.default
def result(self): input = [input_def for input_def in self.tosca_tpl.inputs if self.input_name == input_def.name][0] if self.tosca_tpl.parsed_params and \ self.input_name in self.tosca_tpl.parsed_params: if input and input.type == Schema.ENUM: return DataEntity.validate_datatype(input.type, self.tosca_tpl.parsed_params[self.input_name], input.schema) value = self.tosca_tpl.parsed_params[self.input_name] if value is not None: return DataEntity.validate_datatype( self.tosca_tpl.tpl['inputs'][self.input_name]['type'], value) if input and input.type == Schema.ENUM: return DataEntity.validate_datatype(input.type, input.default, input.schema) return input.default
def _validate_value(self, value): tosca = EntityType.TOSCA_DEF datatype = None if self.type in tosca: datatype = tosca[self.type] elif EntityType.DATATYPE_NETWORK_PREFIX + self.type in tosca: datatype = tosca[EntityType.DATATYPE_NETWORK_PREFIX + self.type] schema = self.schema if self.type in (Schema.JSON, Schema.ENUM) else None return DataEntity.validate_datatype(self.type, value, schema, datatype)
def validate_datatype(type, value, entry_schema=None, custom_def=None): if value: if (type == Schema.STRING): return str(value) elif type == Schema.FLOAT: try: return float(value) except Exception: ExceptionCollector.appendException( ValueError(('"%s" is not an float.') % value)) return DataEntity.validate_datatype(type, value, entry_schema, custom_def) return value
def validate(self): '''Validate if not a reference property.''' if is_function(self.value) is False: try: if self.type == Schema.STRING: self.value = str(self.value) self.value = DataEntity.validate_datatype( self.type, self.value, self.entry_schema, self.custom_def, self.name) self._validate_constraints() except Exception as e: log.error("Property error {}: {}".format(self.name, e)) if exception.ExceptionCollector.collecting is False: raise e
def _translate_inputs(self): mano_inputs = [] if 'key_name' in self.parsed_params and 'key_name' not in self.inputs: name = 'key_name' type = 'string' default = self.parsed_params[name] schema_dict = {'type': type, 'default': default} input = Input(name, schema_dict) self.inputs.append(input) self.log.info(_('Translating TOSCA input type to MANO input type.')) for input in self.inputs: mano_default = None mano_input_type = TOSCA_TO_MANO_INPUT_TYPES[input.type] if input.name in self.parsed_params: mano_default = DataEntity.validate_datatype( input.type, self.parsed_params[input.name]) elif input.default is not None: mano_default = DataEntity.validate_datatype( input.type, input.default) else: if self.deploy: msg = _("Need to specify a value " "for input {0}.").format(input.name) self.log.error(msg) raise Exception(msg) if input.type == "scalar-unit.size": # Assumption here is to use this scalar-unit.size for size of # cinder volume in heat templates and will be in GB. # should add logic to support other types if needed. input_value = mano_default mano_default = (ScalarUnit_Size( mano_default).get_num_from_scalar_unit('GiB')) if mano_default == 0: msg = _('Unit value should be > 0.') self.log.error(msg) raise Exception(msg) elif int(mano_default) < mano_default: mano_default = int(mano_default) + 1 self.log.warning( _("Cinder unit value should be in" " multiples of GBs. So corrected" " %(input_value)s to %(mano_default)s" " GB.") % { 'input_value': input_value, 'mano_default': mano_default }) if input.type == 'version': mano_default = TOSCAVersionProperty(mano_default).get_version() mano_constraints = [] if input.constraints: for constraint in input.constraints: if mano_default: constraint.validate(mano_default) hc, hvalue = self._translate_constraints( constraint.constraint_key, constraint.constraint_value) mano_constraints.append({hc: hvalue}) mano_inputs.append( ManoParameter(self.log, name=input.name, type=mano_input_type, description=input.description, default=mano_default, constraints=mano_constraints)) return mano_inputs
def _translate_inputs(self): hot_inputs = [] if 'key_name' in self.parsed_params and 'key_name' not in self.inputs: name = 'key_name' type = 'string' default = self.parsed_params[name] schema_dict = {'type': type, 'default': default} input = Input(name, schema_dict) self.inputs.append(input) log.info(_('Translating TOSCA input type to HOT input type.')) for input in self.inputs: hot_default = None hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type] if input.name in self.parsed_params: hot_default = DataEntity.validate_datatype( input.type, self.parsed_params[input.name]) elif input.default is not None: hot_default = DataEntity.validate_datatype(input.type, input.default) else: if self.deploy: msg = _("Need to specify a value " "for input {0}.").format(input.name) log.error(msg) raise Exception(msg) if input.type == "scalar-unit.size": # Assumption here is to use this scalar-unit.size for size of # cinder volume in heat templates and will be in GB. # should add logic to support other types if needed. input_value = hot_default hot_default = (ScalarUnit_Size(hot_default). get_num_from_scalar_unit('GiB')) if hot_default == 0: msg = _('Unit value should be > 0.') log.error(msg) raise Exception(msg) elif int(hot_default) < hot_default: hot_default = int(hot_default) + 1 log.warning(_("Cinder unit value should be in multiples" " of GBs. So corrected %(input_value)s " "to %(hot_default)s GB.") % {'input_value': input_value, 'hot_default': hot_default}) if input.type == 'version': hot_default = TOSCAVersionProperty(hot_default).get_version() hot_constraints = [] if input.constraints: for constraint in input.constraints: if hot_default: constraint.validate(hot_default) hc, hvalue = self._translate_constraints( constraint.constraint_key, constraint.constraint_value) hot_constraints.append({hc: hvalue}) hot_inputs.append(HotParameter(name=input.name, type=hot_input_type, description=input.description, default=hot_default, constraints=hot_constraints)) return hot_inputs