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