コード例 #1
0
ファイル: templates.py プロジェクト: vnigam1985/tosca
class PolicyTemplate(ExtensiblePresentation):
    """
    A policy definition defines a policy that can be associated with a TOSCA topology or top-level
    entity definition (e.g., group definition, node template, etc.).

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ELEMENT_POLICY_DEF>`__
    """

    @field_validator(type_validator('policy type', convert_name_to_full_type_name, 'policy_types'))
    @primitive_field(str, required=True)
    def type(self):
        """
        The required name of the policy type the policy definition is based upon.

        :type: :obj:`basestring`
        """

    @object_field(Description)
    def description(self):
        """
        The optional description for the policy definition.

        :type: :class:`Description`
        """

    @object_dict_field(PropertyAssignment)
    def properties(self):
        """
        An optional list of property value assignments for the policy definition.

        :type: {:obj:`basestring`: :class:`PropertyAssignment`
        """

    @field_validator(policy_targets_validator)
    @primitive_list_field(str)
    def targets(self):
        """
        An optional list of valid Node Templates or Groups the Policy can be applied to.

        :type: [:obj:`basestring`]
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_name(context, self.type, 'policy_types')

    @cachedmethod
    def _get_property_values(self, context):
        return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))

    @cachedmethod
    def _get_targets(self, context):
        node_templates, groups = get_policy_targets(context, self)
        return FrozenList(node_templates), FrozenList(groups)

    def _validate(self, context):
        super(PolicyTemplate, self)._validate(context)
        self._get_property_values(context)
コード例 #2
0
class RelationshipDefinition(ExtensiblePresentation):
    """
    Relationship definition.
    """
    @field_validator(
        type_validator('relationship type',
                       convert_shorthand_to_full_type_name,
                       'relationship_types'))
    @primitive_field(str, required=True)
    def type(self):
        """
        The optional reserved keyname used to provide the name of the Relationship Type for the
        requirement definition's relationship keyname.

        :type: :obj:`basestring`
        """

    @object_dict_field(InterfaceDefinition)
    def interfaces(self):
        """
        The optional reserved keyname used to reference declared (named) interface definitions of
        the corresponding Relationship Type in order to declare additional Property definitions for
        these interfaces or operations of these interfaces.

        :type: list of :class:`InterfaceDefinition`
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_full_or_shorthand_name(context, self.type,
                                                  'relationship_types')
コード例 #3
0
ファイル: misc.py プロジェクト: djay8887/incubator-ariatosca
class SubstitutionMappings(ExtensiblePresentation):
    @field_validator(
        type_validator('node type', convert_shorthand_to_full_type_name,
                       'node_types'))
    @primitive_field(str, required=True)
    def node_type(self):
        """
        :rtype: str
        """

    @object_dict_field(SubstitutionMappingsRequirement)
    def requirements(self):
        """
        :rtype: dict of str, :class:`SubstitutionMappingsRequirement`
        """

    @object_dict_field(SubstitutionMappingsCapability)
    def capabilities(self):
        """
        :rtype: dict of str, :class:`SubstitutionMappingsCapability`
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_full_or_shorthand_name(context, self.node_type,
                                                  'node_types')

    def _validate(self, context):
        super(SubstitutionMappings, self)._validate(context)
        self._get_type(context)

    def _dump(self, context):
        self._dump_content(context,
                           ('node_type', 'requirements', 'capabilities'))
コード例 #4
0
class InterfaceDefinition(ExtensiblePresentation):
    """
    An interface definition defines a named interface that can be associated with a Node or
    Relationship Type.

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ELEMENT_INTERFACE_DEF>`__
    """
    @field_validator(
        type_validator('interface type', convert_shorthand_to_full_type_name,
                       'interface_types'))
    @primitive_field(str)
    def type(self):
        """
        ARIA NOTE: This field is not mentioned in the spec, but is implied.

        :type: :obj:`basestring`
        """

    @object_dict_field(PropertyDefinition)
    def inputs(self):
        """
        The optional list of input property definitions available to all defined operations for
        interface definitions that are within TOSCA Node or Relationship Type definitions. This
        includes when interface definitions are included as part of a Requirement definition in a
        Node Type.

        :type: {:obj:`basestring`: :class:`PropertyDefinition`}
        """

    @object_dict_unknown_fields(OperationDefinition)
    def operations(self):
        """
        :type: {:obj:`basestring`: :class:`OperationDefinition`}
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_full_or_shorthand_name(context, self.type,
                                                  'interface_types')

    @cachedmethod
    def _get_inputs(self, context):
        return FrozenDict(
            get_and_override_input_definitions_from_type(context, self))

    @cachedmethod
    def _get_operations(self, context):
        return FrozenDict(
            get_and_override_operation_definitions_from_type(context, self))

    def _validate(self, context):
        super(InterfaceDefinition, self)._validate(context)
        if self.operations:
            for operation in self.operations.itervalues():  # pylint: disable=no-member
                operation._validate(context)
コード例 #5
0
class SubstitutionMappings(ExtensiblePresentation):
    """
    Substitution mappings.
    """
    @field_validator(
        type_validator('node type', convert_name_to_full_type_name,
                       'node_types'))
    @primitive_field(str, required=True)
    def node_type(self):
        """
        :type: :obj:`basestring`
        """

    @object_dict_field(SubstitutionMappingsRequirement)
    def requirements(self):
        """
        :type: {:obj:`basestring`: :class:`SubstitutionMappingsRequirement`}
        """

    @object_dict_field(SubstitutionMappingsCapability)
    def capabilities(self):
        """
        :type: {:obj:`basestring`: :class:`SubstitutionMappingsCapability`}
        """

    @object_dict_field(SubstitutionMappingsInterface)
    def interfaces(self):
        """
        :type: {:obj:`basestring`: :class:`SubstitutionMappingsInterface`}
        """

    @object_dict_field(SubstitutionMappingsProperty)
    def properties(self):
        """
        :type: {:obj:`basestring`: :class:`SubstitutionMappingsProperty`}
        """

    @object_dict_field(SubstitutionMappingsAttribute)
    def attributes(self):
        """
        :type: {:obj:`basestring`: :class:`SubstitutionMappingsAttribute`}
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_name(context, self.node_type, 'node_types')

    def _validate(self, context):
        super(SubstitutionMappings, self)._validate(context)
        self._get_type(context)

    def _dump(self, context):
        self._dump_content(
            context,
            ('node_type', 'requirements', 'capabilities', 'interfaces'))
コード例 #6
0
class CapabilityDefinition(ExtensiblePresentation):
    """
    A capability definition defines a named, typed set of data that can be associated with Node Type
    or Node Template to describe a transparent capability or feature of the software component the
    node describes.

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ELEMENT_CAPABILITY_DEFN>`__
    """
    @field_validator(
        type_validator('capability type', convert_shorthand_to_full_type_name,
                       'capability_types'))
    @primitive_field(str, required=True)
    def type(self):
        """
        The required name of the Capability Type the capability definition is based upon.

        :type: :obj:`basestring`
        """

    @object_field(Description)
    def description(self):
        """
        The optional description of the Capability definition.

        :type: :class:`Description`
        """

    @object_dict_field(PropertyDefinition)
    def properties(self):
        """
        An optional list of property definitions for the Capability definition.

        :type: {:obj:`basestring`: :class:`PropertyDefinition`}
        """

    @object_dict_field(AttributeDefinition)
    def attributes(self):
        """
        An optional list of attribute definitions for the Capability definition.

        :type: {:obj:`basestring`: :class:`AttributeDefinition`}
        """

    @field_validator(
        list_type_validator('node type', convert_shorthand_to_full_type_name,
                            'node_types'))
    @primitive_list_field(str)
    def valid_source_types(self):
        """
        An optional list of one or more valid names of Node Types that are supported as valid
        sources of any relationship established to the declared Capability Type.

        :type: [:obj:`basestring`]
        """

    @field_getter(data_type_class_getter(Range))
    @primitive_field()
    def occurrences(self):
        """
        The optional minimum and maximum occurrences for the capability. By default, an exported
        Capability should allow at least one relationship to be formed with it with a maximum of
        ``UNBOUNDED`` relationships.

        Note: the keyword ``UNBOUNDED`` is also supported to represent any positive integer.

        ARIA NOTE: The spec seems wrong here: the implied default should be ``[0,UNBOUNDED]``, not
        ``[1,UNBOUNDED]``, otherwise it would imply that at 1 least one relationship *must* be
        formed.

        :type: :class:`Range`
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_full_or_shorthand_name(context, self.type,
                                                  'capability_types')

    @cachedmethod
    def _get_parent(self, context):
        container_parent = self._container._get_parent(context)
        container_parent_capabilities = container_parent._get_capabilities(context) \
            if container_parent is not None else None
        return container_parent_capabilities.get(self._name) \
            if container_parent_capabilities is not None else None
コード例 #7
0
class RequirementDefinition(ExtensiblePresentation):
    """
    The Requirement definition describes a named requirement (dependencies) of a TOSCA Node Type or
    Node template which needs to be fulfilled by a matching Capability definition declared by
    another TOSCA modelable entity. The requirement definition may itself include the specific name
    of the fulfilling entity (explicitly) or provide an abstract type, along with additional
    filtering characteristics, that a TOSCA orchestrator can use to fulfill the capability at
    runtime (implicitly).

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ELEMENT_REQUIREMENT_DEF>`__
    """
    @field_validator(
        type_validator('capability type', convert_shorthand_to_full_type_name,
                       'capability_types'))
    @primitive_field(str, required=True)
    def capability(self):
        """
        The required reserved keyname used that can be used to provide the name of a valid
        Capability Type that can fulfill the requirement.

        :type: :obj:`basestring`
        """

    @field_validator(
        type_validator('node type', convert_shorthand_to_full_type_name,
                       'node_types'))
    @primitive_field(str)
    def node(self):
        """
        The optional reserved keyname used to provide the name of a valid Node Type that contains
        the capability definition that can be used to fulfill the requirement.

        :type: :obj:`basestring`
        """

    @object_field(RelationshipDefinition)
    def relationship(self):
        """
        The optional reserved keyname used to provide the name of a valid Relationship Type to
        construct when fulfilling the requirement.

        :type: :class:`RelationshipDefinition`
        """

    @field_getter(data_type_class_getter(Range))
    @primitive_field()
    def occurrences(self):
        """
        The optional minimum and maximum occurrences for the requirement.

        Note: the keyword UNBOUNDED is also supported to represent any positive integer.

        :type: :class:`Range`
        """

    @cachedmethod
    def _get_capability_type(self, context):
        return get_type_by_full_or_shorthand_name(context, self.capability,
                                                  'capability_types')

    @cachedmethod
    def _get_node_type(self, context):
        return context.presentation.get_from_dict('service_template',
                                                  'node_types', self.node)
コード例 #8
0
ファイル: templates.py プロジェクト: vnigam1985/tosca
class NodeTemplate(ExtensiblePresentation):
    """
    A Node Template specifies the occurrence of a manageable software component as part of an
    application's topology model which is defined in a TOSCA Service Template. A Node template is an
    instance of a specified Node Type and can provide customized properties, constraints or
    operations which override the defaults provided by its Node Type and its implementations.

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ENTITY_NODE_TEMPLATE>`__
    """

    @field_validator(type_validator('node type', convert_name_to_full_type_name, 'node_types'))
    @primitive_field(str, required=True)
    def type(self):
        """
        The required name of the Node Type the Node Template is based upon.

        :type: :obj:`basestring`
        """

    @object_field(Description)
    def description(self):
        """
        An optional description for the Node Template.

        :type: :class:`Description`
        """

    @primitive_list_field(str)
    def directives(self):
        """
        An optional list of directive values to provide processing instructions to orchestrators and
        tooling.

        :type: [:obj:`basestring`]
        """

    @object_dict_field(PropertyAssignment)
    def properties(self):
        """
        An optional list of property value assignments for the Node Template.

        :type: {:obj:`basestring`: :class:`PropertyAssignment`}
        """

    @object_dict_field(AttributeAssignment)
    def attributes(self):
        """
        An optional list of attribute value assignments for the Node Template.

        :type: {:obj:`basestring`: :class:`AttributeAssignment`}
        """

    @object_sequenced_list_field(RequirementAssignment)
    def requirements(self):
        """
        An optional sequenced list of requirement assignments for the Node Template.

        :type: list of (str, :class:`RequirementAssignment`)
        """

    @object_dict_field(CapabilityAssignment)
    def capabilities(self):
        """
        An optional list of capability assignments for the Node Template.

        :type: {:obj:`basestring`: :class:`CapabilityAssignment`}
        """

    @object_dict_field(InterfaceAssignment)
    def interfaces(self):
        """
        An optional list of named interface definitions for the Node Template.

        :type: {:obj:`basestring`: :class:`InterfaceAssignment`}
        """

    @object_dict_field(ArtifactAssignment)
    def artifacts(self):
        """
        An optional list of named artifact definitions for the Node Template.

        :type: {:obj:`basestring`: :class:`ArtifactAssignment`}
        """

    @object_field(NodeFilter)
    def node_filter(self):
        """
        The optional filter definition that TOSCA orchestrators would use to select the correct
        target node. This keyname is only valid if the directive has the value of "selectable" set.

        :type: :class:`NodeFilter`
        """

    @field_validator(copy_validator('node template', 'node_templates'))
    @primitive_field(str)
    def copy(self):
        """
        The optional (symbolic) name of another node template to copy into (all keynames and values)
        and use as a basis for this node template.

        :type: :obj:`basestring`
        """

    @cachedmethod
    def _get_default_raw(self):
        return get_default_raw_from_copy(self, 'node_templates')

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_name(context, self.type, 'node_types')

    @cachedmethod
    def _get_property_values(self, context):
        return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))

    @cachedmethod
    def _get_attribute_default_values(self, context):
        return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'attribute'))

    @cachedmethod
    def _get_requirements(self, context):
        return FrozenList(get_template_requirements(context, self))

    @cachedmethod
    def _get_capabilities(self, context):
        return FrozenDict(get_template_capabilities(context, self))

    @cachedmethod
    def _get_interfaces(self, context):
        return FrozenDict(get_template_interfaces(context, self, 'node template'))

    @cachedmethod
    def _get_artifacts(self, context):
        return FrozenDict(get_inherited_artifact_definitions(context, self))

    def _validate(self, context):
        super(NodeTemplate, self)._validate(context)
        self._get_property_values(context)
        self._get_attribute_default_values(context)
        self._get_requirements(context)
        self._get_capabilities(context)
        self._get_interfaces(context)
        self._get_artifacts(context)

    def _dump(self, context):
        self._dump_content(context, (
            'description',
            'type',
            'directives',
            'properties',
            'attributes',
            'requirements',
            'capabilities',
            'interfaces',
            'artifacts',
            'node_filter',
            'copy'))
コード例 #9
0
ファイル: templates.py プロジェクト: vnigam1985/tosca
class GroupTemplate(ExtensiblePresentation):
    """
    A group definition defines a logical grouping of node templates, typically for management
    purposes, but is separate from the application's topology template.

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ELEMENT_GROUP_DEF>`__
    """

    @field_validator(type_validator('group type', convert_name_to_full_type_name,
                                    'group_types'))
    @primitive_field(str, required=True)
    def type(self):
        """
        The required name of the group type the group definition is based upon.

        :type: :obj:`basestring`
        """

    @object_field(Description)
    def description(self):
        """
        The optional description for the group definition.

        :type: :class:`Description`
        """

    @object_dict_field(PropertyAssignment)
    def properties(self):
        """
        An optional list of property value assignments for the group definition.

        :type: {:obj:`basestring`: :class:`PropertyAssignment`}
        """

    @field_validator(group_members_validator)
    @primitive_list_field(str)
    def members(self):
        """
        The optional list of one or more node template names that are members of this group
        definition.

        :type: [:obj:`basestring`]
        """

    @object_dict_field(InterfaceAssignment)
    def interfaces(self):
        """
        An optional list of named interface definitions for the group definition.

        :type: {:obj:`basestring`: :class:`InterfaceDefinition`}
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_name(context, self.type, 'group_types')

    @cachedmethod
    def _get_property_values(self, context):
        return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))

    @cachedmethod
    def _get_interfaces(self, context):
        return FrozenDict(get_template_interfaces(context, self, 'group definition'))

    def _validate(self, context):
        super(GroupTemplate, self)._validate(context)
        self._get_property_values(context)
        self._get_interfaces(context)
コード例 #10
0
ファイル: templates.py プロジェクト: vnigam1985/tosca
class RelationshipTemplate(ExtensiblePresentation):
    """
    A Relationship Template specifies the occurrence of a manageable relationship between node
    templates as part of an application's topology model that is defined in a TOSCA Service
    Template. A Relationship template is an instance of a specified Relationship Type and can
    provide customized properties, constraints or operations which override the defaults provided by
    its Relationship Type and its implementations.

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ENTITY_RELATIONSHIP_TEMPLATE>`__
    """

    @field_validator(type_validator('relationship type', convert_name_to_full_type_name,
                                    'relationship_types'))
    @primitive_field(str, required=True)
    def type(self):
        """
        The required name of the Relationship Type the Relationship Template is based upon.

        :type: :obj:`basestring`
        """

    @object_field(Description)
    def description(self):
        """
        An optional description for the Relationship Template.

        :type: :class:`Description`
        """

    @object_dict_field(PropertyAssignment)
    def properties(self):
        """
        An optional list of property assignments for the Relationship Template.

        :type: {:obj:`basestring`: :class:`PropertyAssignment`}
        """

    @object_dict_field(AttributeAssignment)
    def attributes(self):
        """
        An optional list of attribute assignments for the Relationship Template.

        :type: {:obj:`basestring`: :class:`AttributeAssignment`}
        """

    @object_dict_field(InterfaceAssignment)
    def interfaces(self):
        """
        An optional list of named interface definitions for the Node Template.

        ARIA NOTE: Spec is wrong here, should be Relationship Template.

        :type: {:obj:`basestring`: :class:`InterfaceAssignment`}
        """

    @field_validator(copy_validator('relationship template', 'relationship_templates'))
    @primitive_field(str)
    def copy(self):
        """
        The optional (symbolic) name of another relationship template to copy into (all keynames and
        values) and use as a basis for this relationship template.

        :type: :obj:`basestring`
        """

    @cachedmethod
    def _get_default_raw(self):
        return get_default_raw_from_copy(self, 'relationship_templates')

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_name(context, self.type, 'relationship_types')

    @cachedmethod
    def _get_property_values(self, context):
        return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))

    @cachedmethod
    def _get_attribute_default_values(self, context):
        return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'attribute'))

    @cachedmethod
    def _get_interfaces(self, context):
        return FrozenDict(get_template_interfaces(context, self, 'relationship template'))

    def _validate(self, context):
        super(RelationshipTemplate, self)._validate(context)
        self._get_property_values(context)
        self._get_attribute_default_values(context)
        self._get_interfaces(context)

    def _dump(self, context):
        self._dump_content(context, (
            'description',
            'type',
            'properties',
            'attributes',
            'interfaces',
            'copy'))
コード例 #11
0
class ArtifactAssignmentForType(ExtensiblePresentation):
    """
    An artifact definition defines a named, typed file that can be associated with Node Type or Node
    Template and used by orchestration engine to facilitate deployment and implementation of
    interface operations.

    See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
    /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
    #DEFN_ENTITY_ARTIFACT_DEF>`__
    """
    @field_validator(
        type_validator('artifact type', convert_name_to_full_type_name,
                       'artifact_types'))
    @primitive_field(str, required=True)
    def type(self):
        """
        The required artifact type for the artifact definition.

        :type: :obj:`basestring`
        """

    @primitive_field(str, required=True)
    def file(self):
        """
        The required URI string (relative or absolute) which can be used to locate the artifact's
        file.

        :type: :obj:`basestring`
        """

    @field_validator(type_validator('repository', 'repositories'))
    @primitive_field(str)
    def repository(self):
        """
        The optional name of the repository definition which contains the location of the external
        repository that contains the artifact. The artifact is expected to be referenceable by its
        file URI within the repository.

        :type: :obj:`basestring`
        """

    @object_field(Description)
    def description(self):
        """
        The optional description for the artifact definition.

        :type: :class:`Description`
        """

    @primitive_field(str)
    def deploy_path(self):
        """
        The file path the associated file would be deployed into within the target node's container.

        :type: :obj:`basestring`
        """

    @object_dict_field(PropertyAssignment)
    def properties(self):
        """
        ARIA NOTE: This field is not mentioned in the spec, but is implied.

        :type: {:obj:`basestring`: :class:`PropertyAssignment`}
        """

    @cachedmethod
    def _get_type(self, context):
        return get_type_by_name(context, self.type, 'artifact_types')

    @cachedmethod
    def _get_repository(self, context):
        return context.presentation.get_from_dict('service_template',
                                                  'repositories',
                                                  self.repository)

    @cachedmethod
    def _get_property_values(self, context):
        return FrozenDict(
            get_assigned_and_defined_parameter_values(context, self,
                                                      'property'))

    @cachedmethod
    def _validate(self, context):
        super(ArtifactAssignmentForType, self)._validate(context)