當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。