http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60ea3ebb/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py index f61cb99..9c3ea42 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py @@ -58,7 +58,8 @@ def get_inherited_property_definitions(context, presentation, field_name, for_pr # NodeTemplate, RelationshipTemplate, GroupTemplate, PolicyTemplate # -def get_assigned_and_defined_property_values(context, presentation): +def get_assigned_and_defined_property_values(context, presentation, field_name='property', + field_name_plural='properties'): """ Returns the assigned property values while making sure they are defined in our type. @@ -70,8 +71,9 @@ def get_assigned_and_defined_property_values(context, presentation): values = OrderedDict() the_type = presentation._get_type(context) - assignments = presentation.properties - definitions = the_type._get_properties(context) if the_type is not None else None + assignments = getattr(presentation, field_name_plural) + get_fn_name = '_get_{0}'.format(field_name_plural) + definitions = getattr(the_type, get_fn_name)(context) if the_type is not None else None # Fill in our assignments, but make sure they are defined if assignments: @@ -80,14 +82,14 @@ def get_assigned_and_defined_property_values(context, presentation): definition = definitions[name] values[name] = coerce_property_value(context, value, definition, value.value) else: - context.validation.report('assignment to undefined property "%s" in "%s"' - % (name, presentation._fullname), + context.validation.report('assignment to undefined {0} "{1}" in "{2}"' + .format(field_name, name, presentation._fullname), locator=value._locator, level=Issue.BETWEEN_TYPES) # Fill in defaults from the definitions if definitions: for name, definition in definitions.iteritems(): - if (values.get(name) is None) and (definition.default is not None): + if values.get(name) is None: values[name] = coerce_property_value(context, presentation, definition, definition.default) @@ -181,7 +183,8 @@ def merge_property_definitions(context, presentation, property_definitions, def coerce_property_value(context, presentation, definition, value, aspect=None): the_type = definition._get_type(context) if definition is not None else None entry_schema = definition.entry_schema if definition is not None else None - constraints = definition._get_constraints(context) if definition is not None else None + constraints = definition._get_constraints(context) \ + if ((definition is not None) and hasattr(definition, '_get_constraints')) else None value = coerce_value(context, presentation, the_type, entry_schema, constraints, value, aspect) if (the_type is not None) and hasattr(the_type, '_name'): type_name = the_type._name
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60ea3ebb/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py b/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py index 6ff4384..d7b03ae 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py +++ b/extensions/aria_extension_tosca/simple_v1_0/presentation/field_validators.py @@ -16,7 +16,7 @@ import re from aria.utils.formatting import safe_repr -from aria.parser import dsl_specification +from aria.parser import implements_specification from aria.parser.presentation import (report_issue_for_unknown_type, derived_from_validator) from aria.parser.validation import Issue @@ -28,8 +28,7 @@ from .types import get_type_by_full_or_shorthand_name, convert_shorthand_to_full # NodeTemplate, RelationshipTemplate # -@dsl_specification('3.7.3.3', 'tosca-simple-1.0') -@dsl_specification('3.7.4.3', 'tosca-simple-1.0') +@implements_specification('3.7.3.3', 'tosca-simple-1.0') def copy_validator(template_type_name, templates_dict_name): """ Makes sure that the field refers to an existing template defined in the root presenter. @@ -304,8 +303,12 @@ def constraint_clause_pattern_validator(field, presentation, context): value = getattr(presentation, field.name) if value is not None: try: - # Note: the TOSCA 1.0 spec does not specify the regular expression grammar, so we will - # just use Python's + # From TOSCA 1.0 3.5.2.1: + # + # "Note: Future drafts of this specification will detail the use of regular expressions + # and reference an appropriate standardized grammar." + # + # So we will just use Python's. re.compile(value) except re.error as e: context.validation.report( http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60ea3ebb/extensions/aria_extension_tosca/simple_v1_0/presenter.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/presenter.py b/extensions/aria_extension_tosca/simple_v1_0/presenter.py index c88decd..f64078f 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/presenter.py +++ b/extensions/aria_extension_tosca/simple_v1_0/presenter.py @@ -17,9 +17,9 @@ from aria.utils.collections import FrozenList, EMPTY_READ_ONLY_LIST from aria.utils.caching import cachedmethod from aria.parser.presentation import Presenter -from .functions import (Concat, Token, GetInput, GetProperty, GetAttribute, GetOperationOutput, - GetNodesOfType, GetArtifact) from .modeling import create_service_template_model +from .modeling.functions import (Concat, Token, GetInput, GetProperty, GetAttribute, + GetOperationOutput, GetNodesOfType, GetArtifact) from .templates import ServiceTemplate class ToscaSimplePresenter1_0(Presenter): # pylint: disable=invalid-name,abstract-method http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60ea3ebb/extensions/aria_extension_tosca/simple_v1_0/templates.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/templates.py b/extensions/aria_extension_tosca/simple_v1_0/templates.py index 6860b72..ce6b5d9 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/templates.py +++ b/extensions/aria_extension_tosca/simple_v1_0/templates.py @@ -15,7 +15,7 @@ from aria.utils.collections import FrozenDict, FrozenList from aria.utils.caching import cachedmethod -from aria.parser import dsl_specification +from aria.parser import implements_specification from aria.parser.presentation import (has_fields, primitive_field, primitive_list_field, object_field, object_list_field, object_dict_field, object_sequenced_list_field, field_validator, @@ -26,7 +26,7 @@ from .assignments import (PropertyAssignment, AttributeAssignment, RequirementAs from .definitions import ParameterDefinition from .filters import NodeFilter from .misc import (Description, MetaData, Repository, Import, SubstitutionMappings) -from .modeling.properties import get_assigned_and_defined_property_values, get_parameter_values +from .modeling.properties import (get_assigned_and_defined_property_values, get_parameter_values) from .modeling.interfaces import get_template_interfaces from .modeling.requirements import get_template_requirements from .modeling.capabilities import get_template_capabilities @@ -41,7 +41,7 @@ from .types import (ArtifactType, DataType, CapabilityType, InterfaceType, Relat NodeType, GroupType, PolicyType) @has_fields -@dsl_specification('3.7.3', 'tosca-simple-1.0') +@implements_specification('3.7.3', 'tosca-simple-1.0') class NodeTemplate(ExtensiblePresentation): """ A Node Template specifies the occurrence of a manageable software component as part of an @@ -160,6 +160,11 @@ class NodeTemplate(ExtensiblePresentation): return FrozenDict(get_assigned_and_defined_property_values(context, self)) @cachedmethod + def _get_attribute_default_values(self, context): + return FrozenDict(get_assigned_and_defined_property_values(context, self, + 'attribute', 'attributes')) + + @cachedmethod def _get_requirements(self, context): return FrozenList(get_template_requirements(context, self)) @@ -198,7 +203,7 @@ class NodeTemplate(ExtensiblePresentation): 'copy')) @has_fields -@dsl_specification('3.7.4', 'tosca-simple-1.0') +@implements_specification('3.7.4', 'tosca-simple-1.0') class RelationshipTemplate(ExtensiblePresentation): """ A Relationship Template specifies the occurrence of a manageable relationship between node @@ -297,7 +302,7 @@ class RelationshipTemplate(ExtensiblePresentation): 'copy')) @has_fields -@dsl_specification('3.7.5', 'tosca-simple-1.0') +@implements_specification('3.7.5', 'tosca-simple-1.0') class GroupTemplate(ExtensiblePresentation): """ A group definition defines a logical grouping of node templates, typically for management @@ -370,7 +375,7 @@ class GroupTemplate(ExtensiblePresentation): self._get_interfaces(context) @has_fields -@dsl_specification('3.7.6', 'tosca-simple-1.0') +@implements_specification('3.7.6', 'tosca-simple-1.0') class PolicyTemplate(ExtensiblePresentation): """ A policy definition defines a policy that can be associated with a TOSCA topology or top-level @@ -434,7 +439,7 @@ class PolicyTemplate(ExtensiblePresentation): self._get_property_values(context) @has_fields -@dsl_specification('3.8', 'tosca-simple-1.0') +@implements_specification('3.8', 'tosca-simple-1.0') class TopologyTemplate(ExtensiblePresentation): """ This section defines the topology template of a cloud application. The main ingredients of the @@ -544,7 +549,7 @@ class TopologyTemplate(ExtensiblePresentation): 'substitution_mappings')) @has_fields -@dsl_specification('3.9', 'tosca-simple-1.0') +@implements_specification('3.9', 'tosca-simple-1.0') class ServiceTemplate(ExtensiblePresentation): """ See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca @@ -553,7 +558,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @primitive_field(str) - @dsl_specification('3.9.3.1', 'tosca-simple-1.0') + @implements_specification('3.9.3.1', 'tosca-simple-1.0') def tosca_definitions_version(self): """ Defines the version of the TOSCA Simple Profile specification the template (grammar) @@ -580,7 +585,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_field(Description) - @dsl_specification('3.9.3.6', 'tosca-simple-1.0') + @implements_specification('3.9.3.6', 'tosca-simple-1.0') def description(self): """ Declares a description for this Service Template and its contents. @@ -589,7 +594,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @primitive_field() - @dsl_specification('3.9.3.7', 'tosca-simple-1.0') + @implements_specification('3.9.3.7', 'tosca-simple-1.0') def dsl_definitions(self): """ Declares optional DSL-specific definitions and conventions. For example, in YAML, this @@ -602,7 +607,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(Repository) - @dsl_specification('3.9.3.8', 'tosca-simple-1.0') + @implements_specification('3.9.3.8', 'tosca-simple-1.0') def repositories(self): """ Declares the list of external repositories which contain artifacts that are referenced in @@ -613,7 +618,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_list_field(Import) - @dsl_specification('3.9.3.9', 'tosca-simple-1.0') + @implements_specification('3.9.3.9', 'tosca-simple-1.0') def imports(self): """ Declares import statements external TOSCA Definitions documents. For example, these may be @@ -623,7 +628,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(ArtifactType) - @dsl_specification('3.9.3.10', 'tosca-simple-1.0') + @implements_specification('3.9.3.10', 'tosca-simple-1.0') def artifact_types(self): """ This section contains an optional list of artifact type definitions for use in the service @@ -633,7 +638,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(DataType) - @dsl_specification('3.9.3.11', 'tosca-simple-1.0') + @implements_specification('3.9.3.11', 'tosca-simple-1.0') def data_types(self): """ Declares a list of optional TOSCA Data Type definitions. @@ -642,7 +647,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(CapabilityType) - @dsl_specification('3.9.3.12', 'tosca-simple-1.0') + @implements_specification('3.9.3.12', 'tosca-simple-1.0') def capability_types(self): """ This section contains an optional list of capability type definitions for use in the service @@ -652,7 +657,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(InterfaceType) - @dsl_specification('3.9.3.13', 'tosca-simple-1.0') + @implements_specification('3.9.3.13', 'tosca-simple-1.0') def interface_types(self): """ This section contains an optional list of interface type definitions for use in the service @@ -662,7 +667,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(RelationshipType) - @dsl_specification('3.9.3.14', 'tosca-simple-1.0') + @implements_specification('3.9.3.14', 'tosca-simple-1.0') def relationship_types(self): """ This section contains a set of relationship type definitions for use in the service @@ -672,7 +677,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(NodeType) - @dsl_specification('3.9.3.15', 'tosca-simple-1.0') + @implements_specification('3.9.3.15', 'tosca-simple-1.0') def node_types(self): """ This section contains a set of node type definitions for use in the service template. @@ -681,7 +686,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(GroupType) - @dsl_specification('3.9.3.16', 'tosca-simple-1.0') + @implements_specification('3.9.3.16', 'tosca-simple-1.0') def group_types(self): """ This section contains a list of group type definitions for use in the service template. @@ -690,7 +695,7 @@ class ServiceTemplate(ExtensiblePresentation): """ @object_dict_field(PolicyType) - @dsl_specification('3.9.3.17', 'tosca-simple-1.0') + @implements_specification('3.9.3.17', 'tosca-simple-1.0') def policy_types(self): """ This section contains a list of policy type definitions for use in the service template. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60ea3ebb/extensions/aria_extension_tosca/simple_v1_0/types.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/types.py b/extensions/aria_extension_tosca/simple_v1_0/types.py index 2112f7f..bc80eb9 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/types.py @@ -15,7 +15,7 @@ from aria.utils.collections import FrozenDict, FrozenList from aria.utils.caching import cachedmethod -from aria.parser import dsl_specification +from aria.parser import implements_specification from aria.parser.presentation import (has_fields, allow_unknown_fields, primitive_field, primitive_list_field, object_field, object_dict_field, object_list_field, object_sequenced_list_field, @@ -46,7 +46,7 @@ from .presentation.field_validators import (data_type_derived_from_validator, from .presentation.types import convert_shorthand_to_full_type_name @has_fields -@dsl_specification('3.6.3', 'tosca-simple-1.0') +@implements_specification('3.6.3', 'tosca-simple-1.0') class ArtifactType(ExtensiblePresentation): """ An Artifact Type is a reusable entity that defines the type of one or more files that are used @@ -131,7 +131,7 @@ class ArtifactType(ExtensiblePresentation): 'properties')) @has_fields -@dsl_specification('3.6.5', 'tosca-simple-1.0') +@implements_specification('3.6.5', 'tosca-simple-1.0') class DataType(ExtensiblePresentation): """ A Data Type definition defines the schema for new named datatypes in TOSCA. @@ -225,7 +225,7 @@ class DataType(ExtensiblePresentation): 'properties')) @has_fields -@dsl_specification('3.6.6', 'tosca-simple-1.0') +@implements_specification('3.6.6', 'tosca-simple-1.0') class CapabilityType(ExtensiblePresentation): """ A Capability Type is a reusable entity that describes a kind of capability that a Node Type can @@ -328,7 +328,7 @@ class CapabilityType(ExtensiblePresentation): @allow_unknown_fields @has_fields -@dsl_specification('3.6.4', 'tosca-simple-1.0') +@implements_specification('3.6.4', 'tosca-simple-1.0') class InterfaceType(ExtensiblePresentation): """ An Interface Type is a reusable entity that describes a set of operations that can be used to @@ -406,7 +406,7 @@ class InterfaceType(ExtensiblePresentation): 'operations')) @has_fields -@dsl_specification('3.6.9', 'tosca-simple-1.0') +@implements_specification('3.6.9', 'tosca-simple-1.0') class RelationshipType(ExtensiblePresentation): """ A Relationship Type is a reusable entity that defines the type of one or more relationships @@ -520,7 +520,7 @@ class RelationshipType(ExtensiblePresentation): 'interfaces')) @has_fields -@dsl_specification('3.6.8', 'tosca-simple-1.0') +@implements_specification('3.6.8', 'tosca-simple-1.0') class NodeType(ExtensiblePresentation): """ A Node Type is a reusable entity that defines the type of one or more Node Templates. As such, a @@ -668,7 +668,7 @@ class NodeType(ExtensiblePresentation): 'capabilities')) @has_fields -@dsl_specification('3.6.10', 'tosca-simple-1.0') +@implements_specification('3.6.10', 'tosca-simple-1.0') class GroupType(ExtensiblePresentation): """ A Group Type defines logical grouping types for nodes, typically for different management @@ -781,7 +781,7 @@ class GroupType(ExtensiblePresentation): 'interfaces')) @has_fields -@dsl_specification('3.6.11', 'tosca-simple-1.0') +@implements_specification('3.6.11', 'tosca-simple-1.0') class PolicyType(ExtensiblePresentation): """ A Policy Type defines a type of requirement that affects or governs an application or service's http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60ea3ebb/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml ---------------------------------------------------------------------- diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml index 349a166..8e80640 100644 --- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml +++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml @@ -33,6 +33,7 @@ imports: - types/mongodb.yaml - types/nginx.yaml - aria-1.0 + dsl_definitions: default_openstack_credential: &DEFAULT_OPENSTACK_CREDENTIAL @@ -94,8 +95,11 @@ topology_template: properties: unpack_credential: user: gigaspaces - token: { get_property: [ SELF, app_endpoint, protocol ] } + token: { get_attribute: [ SELF, tosca_id ] } + #token: { get_property: [ SELF, app_endpoint, protocol ] } #token: { get_property: [ HOST, flavor_name ] } + #token: { token: [ { get_property: [ HOST, flavor_name ] }, '.', 1 ] } + #token: { token: [ 'zero.one|two-three', '.|-', 3 ] } interfaces: Maintenance: enable: juju > charm.maintenance_on