当前位置: 首页>>代码示例>>Python>>正文


Python DataEntity.validate_datatype方法代码示例

本文整理汇总了Python中toscaparser.dataentity.DataEntity.validate_datatype方法的典型用法代码示例。如果您正苦于以下问题:Python DataEntity.validate_datatype方法的具体用法?Python DataEntity.validate_datatype怎么用?Python DataEntity.validate_datatype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在toscaparser.dataentity.DataEntity的用法示例。


在下文中一共展示了DataEntity.validate_datatype方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _validate_occurrences

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
 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))
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:nodetemplate.py

示例2: _validate_occurrences

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
 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)))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:10,代码来源:nodetemplate.py

示例3: _validate_value

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
    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)
开发者ID:openstack,项目名称:tosca-parser,代码行数:11,代码来源:parameters.py

示例4: _translate_inputs

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
    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
开发者ID:OnStack,项目名称:heat-translator,代码行数:59,代码来源:translate_inputs.py

示例5: result

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
    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
开发者ID:openstack,项目名称:tosca-parser,代码行数:10,代码来源:functions.py

示例6: validate

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
 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()
开发者ID:mouloudi,项目名称:tosca-parser,代码行数:11,代码来源:properties.py

示例7: _groups

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
 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
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:22,代码来源:topology_template.py

示例8: _translate_inputs

# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate_datatype [as 别名]
    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
开发者ID:MatMaul,项目名称:heat-translator,代码行数:65,代码来源:translate_inputs.py


注:本文中的toscaparser.dataentity.DataEntity.validate_datatype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。