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


Python dataentity.DataEntity类代码示例

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


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

示例1: _validate_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:
         raise InvalidPropertyValueError(what=(occurrences))
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:7,代码来源:nodetemplate.py

示例2: test_built_in_datatype

    def test_built_in_datatype(self):
        value_snippet = '''
        private_network:
          network_name: private
          network_id: 3e54214f-5c09-1bc9-9999-44100326da1b
          addresses: [ 10.111.128.10 ]
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.datatypes.network.NetworkInfo',
                          value.get('private_network'))
        self.assertIsNotNone(data.validate())

        value_snippet = '''
        portspec_valid:
          protocol: tcp
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.datatypes.network.PortSpec',
                          value.get('portspec_valid'))
        self.assertIsNotNone(data.validate())

        value_snippet = '''
        portspec_invalid:
          protocol: xyz
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.datatypes.network.PortSpec',
                          value.get('portspec_invalid'))
        err = self.assertRaises(exception.ValidationError, data.validate)
        self.assertEqual(_('The value "xyz" of property "protocol" is not '
                           'valid. Expected a value from "[udp, tcp, igmp]".'
                           ),
                         err.__str__())
开发者ID:neogoku,项目名称:nfv_api,代码行数:33,代码来源:test_datatypes.py

示例3: test_range_unbounded

 def test_range_unbounded(self):
     value_snippet = '''
     temperature: [-100, 999999]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.TestLab', value,
                       DataTypeTest.custom_type_def)
     self.assertIsNotNone(data.validate())
开发者ID:rickyhai11,项目名称:tosca-parser,代码行数:8,代码来源:test_datatypes.py

示例4: _validate_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)))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:8,代码来源:nodetemplate.py

示例5: _translate_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
开发者ID:OnStack,项目名称:heat-translator,代码行数:57,代码来源:translate_inputs.py

示例6: test_custom_datatype

 def test_custom_datatype(self):
     value_snippet = '''
     name: Mike
     gender: male
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.PeopleBase', value,
                       DataTypeTest.custom_type_def)
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:test_datatypes.py

示例7: _validate_value

    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,代码行数:9,代码来源:parameters.py

示例8: test_built_in_datatype_without_properties

 def test_built_in_datatype_without_properties(self):
     value_snippet = '''
     2
     '''
     value = yamlparser.simple_parse(value_snippet)
     datatype = DataType('PortDef')
     self.assertEqual('integer', datatype.value_type)
     data = DataEntity('PortDef', value)
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:test_datatypes.py

示例9: test_default_field_in_dataentity

 def test_default_field_in_dataentity(self):
     value_snippet = '''
     name: Mike
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.PeopleBase', value,
                       DataTypeTest.custom_type_def)
     data = data.validate()
     self.assertEqual('unknown', data.get('gender'))
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:test_datatypes.py

示例10: test_built_in_nested_datatype

 def test_built_in_nested_datatype(self):
     value_snippet = '''
     user_port:
       protocol: tcp
       target: [50000]
       source: [9000]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('PortSpec', value.get('user_port'))
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py

示例11: test_valid_range_type

 def test_valid_range_type(self):
     value_snippet = '''
     user_port:
       protocol: tcp
       target_range:  [20000, 60000]
       source_range:  [1000, 3000]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('PortSpec', value.get('user_port'))
     self.assertIsNotNone(data.validate())
开发者ID:rickyhai11,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py

示例12: test_functions_datatype

 def test_functions_datatype(self):
     value_snippet = '''
     admin_credential:
       user: username
       token: { get_input: password }
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.datatypes.Credential',
                       value.get('admin_credential'))
     self.assertIsNotNone(data.validate())
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py

示例13: test_built_in_datatype

 def test_built_in_datatype(self):
     value_snippet = '''
     private_network:
       network_name: private
       network_id: 3e54214f-5c09-1bc9-9999-44100326da1b
       addresses: [ 10.111.128.10 ]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.datatypes.network.NetworkInfo',
                       value.get('private_network'))
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:11,代码来源:test_datatypes.py

示例14: test_built_in_datatype_with_short_name

 def test_built_in_datatype_with_short_name(self):
     value_snippet = '''
     ethernet_port:
       port_name: port1
       port_id: 2c0c7a37-691a-23a6-7709-2d10ad041467
       network_id: 3e54214f-5c09-1bc9-9999-44100326da1b
       mac_address: f1:18:3b:41:92:1e
       addresses: [ 172.24.9.102 ]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('PortInfo', value.get('ethernet_port'))
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:12,代码来源:test_datatypes.py

示例15: test_range_unbounded

 def test_range_unbounded(self):
     value_snippet = '''
     humidity: [-100, 100]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.TestLab',
                       value, DataTypeTest.custom_type_def)
     err = self.assertRaises(exception.InvalidSchemaError,
                             lambda: data.validate())
     self.assertEqual(_('The property "in_range" expects comparable values.'
                        ),
                      err.__str__())
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:12,代码来源:test_datatypes.py


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