• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python dataentity.DataEntity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_port_spec_addl_reqs

    def test_port_spec_addl_reqs(self):
        value_snippet = '''
        test_port:
          protocol: tcp
          target: 65535
          target_range: [ 1, 65535 ]
          source: 1
          source_range: [ 1, 65535 ]

        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.datatypes.network.PortSpec',
                          value.get('test_port'))
        self.assertIsNotNone(data.validate())
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:14,代码来源:test_datatypes.py


示例17: test_custom_datatype_with_parent

 def test_custom_datatype_with_parent(self):
     value_snippet = '''
     name: Mike
     gender: male
     contacts:
       - {contact_name: Tom,
         contact_email: [email protected],
         contact_phone: '123456789'}
       - {contact_name: Jerry,
         contact_email: [email protected],
         contact_phone: '321654987'}
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.People', value,
                       DataTypeTest.custom_type_def)
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:16,代码来源:test_datatypes.py


示例18: result

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


示例19: validate

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


示例20: test_valid_ranges_against_constraints

    def test_valid_ranges_against_constraints(self):

        # The TestLab range type has max=UNBOUNDED
        value_snippet = '''
        temperature1: [-255, 999999]
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.my.datatypes.TestLab', value,
                          DataTypeTest.custom_type_def)
        self.assertIsNotNone(data.validate())

        # The TestLab range type has min=UNBOUNDED
        value_snippet = '''
        temperature2: [-999999, 255]
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.my.datatypes.TestLab', value,
                          DataTypeTest.custom_type_def)
        self.assertIsNotNone(data.validate())
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:19,代码来源:test_datatypes.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
下一篇:
Python exception.ExceptionCollector类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap