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


Python ExceptionCollector.appendException方法代码示例

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


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

示例1: validate

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def validate(self):
     if len(self.args) < 2:
         ExceptionCollector.appendException(
             ValueError(_('Expected arguments: "node-template-name", "req-or-cap" ' '(optional), "property name".'))
         )
         return
     if len(self.args) == 2:
         found_prop = self._find_property(self.args[1])
         if not found_prop:
             return
         prop = found_prop.value
         if not isinstance(prop, Function):
             get_function(self.tosca_tpl, self.context, prop)
     elif len(self.args) >= 3:
         # do not use _find_property to avoid raise KeyError
         # if the prop is not found
         # First check if there is property with this name
         node_tpl = self._find_node_template(self.args[0])
         props = node_tpl.get_properties() if node_tpl else []
         index = 2
         found = [props[self.args[1]]] if self.args[1] in props else []
         if found:
             property_value = found[0].value
         else:
             index = 3
             # then check the req or caps
             property_value = self._find_req_or_cap_property(self.args[1], self.args[2])
         if len(self.args) > index:
             for elem in self.args[index:]:
                 if isinstance(property_value, list):
                     int_elem = int(elem)
                     property_value = self._get_index_value(property_value, int_elem)
                 else:
                     property_value = self._get_attribute_value(property_value, elem)
开发者ID:openstack,项目名称:tosca-parser,代码行数:36,代码来源:functions.py

示例2: _common_validate_properties

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _common_validate_properties(self, entitytype, properties):
     allowed_props = []
     required_props = []
     for p in entitytype.get_properties_def_objects():
         allowed_props.append(p.name)
         if p.required:
             required_props.append(p.name)
     if properties:
         self._common_validate_field(properties, allowed_props,
                                     'properties')
         # make sure it's not missing any property required by a tosca type
         missingprop = []
         for r in required_props:
             if r not in properties.keys():
                 missingprop.append(r)
         if missingprop:
             ExceptionCollector.appendException(
                 MissingRequiredFieldError(
                     what='"properties" of template "%s"' % self.name,
                     required=missingprop))
     else:
         if required_props:
             ExceptionCollector.appendException(
                 MissingRequiredFieldError(
                     what='"properties" of template "%s"' % self.name,
                     required=missingprop))
开发者ID:semk,项目名称:tosca-parser,代码行数:28,代码来源:entity_template.py

示例3: __init__

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
    def __init__(self, name, value=None, schema=None):
        self.name = name
        self.value = value
        self.schema = schema

        try:
            self.schema['type']
        except KeyError:
            msg = (_('Schema definition of "%(pname)s" must have a "type" '
                     'attribute.') % dict(pname=self.name))
            ExceptionCollector.appendException(
                InvalidSchemaError(message=msg))

        if 'required' in self.schema:
            required = self.schema['required']
            if not isinstance(required, bool):
                if required.lower() not in self.VALID_REQUIRED_VALUES:
                    valid_values = ', '.join(self.VALID_REQUIRED_VALUES)
                    msg = (_('Schema definition of "%(propname)s" has '
                             '"required" attribute with invalid value '
                             '"%(value1)s". The value must be one of '
                             '"%(value2)s".') % {"propname": self.name,
                                                 "value1": required,
                                                 "value2": valid_values})
                    ExceptionCollector.appendException(
                        InvalidSchemaError(message=msg))
开发者ID:semk,项目名称:tosca-parser,代码行数:28,代码来源:property_definition.py

示例4: validate_range

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
def validate_range(range):
    # list class check
    validate_list(range)
    # validate range list has a min and max
    if len(range) != 2:
        ExceptionCollector.appendException(
            ValueError(_('"%s" is not a valid range.') % range))
    # validate min and max are numerics or the keyword UNBOUNDED
    min_test = max_test = False
    if not range[0] == RANGE_UNBOUNDED:
        min = validate_numeric(range[0])
    else:
        min_test = True
    if not range[1] == RANGE_UNBOUNDED:
        max = validate_numeric(range[1])
    else:
        max_test = True
    # validate the max > min (account for UNBOUNDED)
    if not min_test and not max_test:
        # Note: min == max is allowed
        if min > max:
            ExceptionCollector.appendException(
                ValueError(_('"%s" is not a valid range.') % range))

    return range
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:27,代码来源:validateutils.py

示例5: _validate_and_load_imports

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
    def _validate_and_load_imports(self):
        imports_names = set()

        if not self.importslist:
            msg = _('"imports" keyname is defined without including '
                    'templates.')
            log.error(msg)
            ExceptionCollector.appendException(ValidationError(message=msg))
            return

        for import_def in self.importslist:
            if isinstance(import_def, dict):
                for import_name, import_uri in import_def.items():
                    if import_name in imports_names:
                        msg = (_('Duplicate import name "%s" was found.') %
                               import_name)
                        log.error(msg)
                        ExceptionCollector.appendException(
                            ValidationError(message=msg))
                    imports_names.add(import_name)

                    custom_type = self._load_import_template(import_name,
                                                             import_uri)
                    namespace_prefix = None
                    if isinstance(import_uri, dict):
                        namespace_prefix = import_uri.get(
                            self.NAMESPACE_PREFIX)

                    self._update_custom_def(custom_type, namespace_prefix)
            else:  # old style of imports
                custom_type = self._load_import_template(None,
                                                         import_def)
                if custom_type:
                    self._update_custom_def(custom_type, None)
开发者ID:semk,项目名称:tosca-parser,代码行数:36,代码来源:imports.py

示例6: _validate_fields

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _validate_fields(self):
     if self.defs:
         for name in self.defs.keys():
             if name not in self.SECTIONS:
                 ExceptionCollector.appendException(
                     UnknownFieldError(what='Group Type %s'
                                       % self.grouptype, field=name))
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:9,代码来源:grouptype.py

示例7: __init__

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def __init__(self, property_name, property_type, constraint):
     super(Pattern, self).__init__(property_name, property_type, constraint)
     if not isinstance(self.constraint_value, self.valid_types):
         ExceptionCollector.appendException(
             InvalidSchemaError(message=_('The property "pattern" '
                                          'expects a string.')))
     self.match = re.compile(self.constraint_value).match
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:9,代码来源:constraints.py

示例8: validate

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def validate(self):
     if len(self.args) != 2:
         ExceptionCollector.appendException(
             ValueError(_('Illegal arguments for function "{0}". Expected '
                          'arguments: "node-template-name", '
                          '"attribute-name"').format(GET_ATTRIBUTE)))
     self._find_node_template_containing_attribute()
开发者ID:semk,项目名称:tosca-parser,代码行数:9,代码来源:functions.py

示例9: _validate_requirements_keys

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _validate_requirements_keys(self, requirement):
     for key in requirement.keys():
         if key not in self.REQUIREMENTS_SECTION:
             ExceptionCollector.appendException(
                 UnknownFieldError(
                     what='"requirements" of template "%s"' % self.name,
                     field=key))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:9,代码来源:nodetemplate.py

示例10: _validate_keys

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _validate_keys(self):
     if self.defs:
         for key in self.defs.keys():
             if key not in self.SECTIONS:
                 ExceptionCollector.appendException(
                     UnknownFieldError(what='Nodetype"%s"' % self.ntype,
                                       field=key))
开发者ID:santhoshkmr64,项目名称:santhosh,代码行数:9,代码来源:nodetype.py

示例11: _validate_requirements

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
    def _validate_requirements(self):
        type_requires = self.type_definition.get_all_requirements()
        allowed_reqs = ["template"]
        if type_requires:
            for treq in type_requires:
                for key, value in treq.items():
                    allowed_reqs.append(key)
                    if isinstance(value, dict):
                        for key in value:
                            allowed_reqs.append(key)

        requires = self.type_definition.get_value(self.REQUIREMENTS,
                                                  self.entity_tpl)
        if requires:
            if not isinstance(requires, list):
                ExceptionCollector.appendException(
                    TypeMismatchError(
                        what='"requirements" of template "%s"' % self.name,
                        type='list'))
            for req in requires:
                for r1, value in req.items():
                    if isinstance(value, dict):
                        self._validate_requirements_keys(value)
                        self._validate_requirements_properties(value)
                        allowed_reqs.append(r1)
                self._common_validate_field(req, allowed_reqs, 'requirements')
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:28,代码来源:nodetemplate.py

示例12: _validate_type_version

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _validate_type_version(self, version):
     if version not in self.VALID_TEMPLATE_VERSIONS:
         ExceptionCollector.appendException(
             InvalidTemplateVersion(
                 what=version + " in " + self.import_def, valid_versions=", ".join(self.VALID_TEMPLATE_VERSIONS)
             )
         )
开发者ID:neogoku,项目名称:nfv_api,代码行数:9,代码来源:tosca_type_validation.py

示例13: _validate_interfaces

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _validate_interfaces(self):
     ifaces = self.type_definition.get_value(self.INTERFACES,
                                             self.entity_tpl)
     if ifaces:
         for name, value in ifaces.items():
             if name in (LIFECYCLE, LIFECYCLE_SHORTNAME):
                 self._common_validate_field(
                     value, InterfacesDef.
                     interfaces_node_lifecycle_operations,
                     'interfaces')
             elif name in (CONFIGURE, CONFIGURE_SHORTNAME):
                 self._common_validate_field(
                     value, InterfacesDef.
                     interfaces_relationship_configure_operations,
                     'interfaces')
             elif name in self.type_definition.interfaces.keys():
                 self._common_validate_field(
                     value,
                     self._collect_custom_iface_operations(name),
                     'interfaces')
             else:
                 ExceptionCollector.appendException(
                     UnknownFieldError(
                         what='"interfaces" of template "%s"' %
                         self.name, field=name))
开发者ID:openstack,项目名称:tosca-parser,代码行数:27,代码来源:nodetemplate.py

示例14: _get_capability_property

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _get_capability_property(self,
                              node_template,
                              capability_name,
                              property_name):
     """Gets a node template capability property."""
     caps = node_template.get_capabilities()
     if caps and capability_name in caps.keys():
         cap = caps[capability_name]
         property = None
         props = cap.get_properties()
         if props and property_name in props.keys():
             property = props[property_name].value
         if not property:
             ExceptionCollector.appendException(
                 KeyError(_('Property "%(prop)s" was not found in '
                            'capability "%(cap)s" of node template '
                            '"%(ntpl1)s" referenced from node template '
                            '"%(ntpl2)s".') % {'prop': property_name,
                                               'cap': capability_name,
                                               'ntpl1': node_template.name,
                                               'ntpl2': self.context.name}))
         return property
     msg = _('Requirement/Capability "{0}" referenced from node template '
             '"{1}" was not found in node template "{2}".').format(
                 capability_name,
                 self.context.name,
                 node_template.name)
     ExceptionCollector.appendException(KeyError(msg))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:30,代码来源:functions.py

示例15: _get_capability_attribute

# 需要导入模块: from toscaparser.common.exception import ExceptionCollector [as 别名]
# 或者: from toscaparser.common.exception.ExceptionCollector import appendException [as 别名]
 def _get_capability_attribute(self,
                               node_template,
                               capability_name,
                               attr_name):
     """Gets a node template capability attribute."""
     caps = node_template.get_capabilities()
     if caps and capability_name in caps.keys():
         cap = caps[capability_name]
         attribute = None
         attrs = cap.definition.get_attributes_def()
         if attrs and attr_name in attrs.keys():
             attribute = attrs[attr_name]
         if not attribute:
             ExceptionCollector.appendException(
                 KeyError(_('Attribute "%(attr)s" was not found in '
                            'capability "%(cap)s" of node template '
                            '"%(ntpl1)s" referenced from node template '
                            '"%(ntpl2)s".') % {'attr': attr_name,
                                               'cap': capability_name,
                                               'ntpl1': node_template.name,
                                               'ntpl2': self.context.name}))
         return attribute
     msg = _('Requirement/Capability "{0}" referenced from node template '
             '"{1}" was not found in node template "{2}".').format(
                 capability_name,
                 self.context.name,
                 node_template.name)
     ExceptionCollector.appendException(KeyError(msg))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:30,代码来源:functions.py


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