1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from aria.utils.caching import cachedmethod
17 from aria.parser import implements_specification
18 from aria.parser.presentation import (has_fields, object_sequenced_list_field, field_validator)
20 from .misc import ConstraintClause
21 from .presentation.extensible import ExtensiblePresentation
22 from .presentation.field_validators import (node_filter_properties_validator,
23 node_filter_capabilities_validator)
27 class CapabilityFilter(ExtensiblePresentation):
32 @object_sequenced_list_field(ConstraintClause)
37 def _get_node_type(self, context):
38 return self._container._get_node_type(context)
41 def _get_type_for_name(self, context, name):
42 node_type = self._get_node_type(context)
43 if node_type is not None:
44 capabilities = node_type._get_capabilities(context)
45 capability = capabilities.get(self._name)
46 properties = capability.properties if capability is not None else None
47 prop = properties.get(name) if properties is not None else None
48 return prop._get_type(context) if prop is not None else None
54 @implements_specification('3.5.4', 'tosca-simple-1.0')
55 class NodeFilter(ExtensiblePresentation):
57 A node filter definition defines criteria for selection of a TOSCA Node Template based upon the
58 template's property values, capabilities and capability properties.
60 See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
61 /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
62 #DEFN_ELEMENT_NODE_FILTER_DEFN>`__
65 @field_validator(node_filter_properties_validator)
66 @object_sequenced_list_field(ConstraintClause)
67 @implements_specification('3.5.3', 'tosca-simple-1.0')
70 An optional sequenced list of property filters that would be used to select (filter)
71 matching TOSCA entities (e.g., Node Template, Node Type, Capability Types, etc.) based upon
72 their property definitions' values.
74 See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
75 /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
76 #DEFN_ELEMENT_PROPERTY_FILTER_DEFN>`__
78 :type: list of (str, :class:`ConstraintClause`)
81 @field_validator(node_filter_capabilities_validator)
82 @object_sequenced_list_field(CapabilityFilter)
83 def capabilities(self):
85 An optional sequenced list of property filters that would be used to select (filter)
86 matching TOSCA entities (e.g., Node Template, Node Type, Capability Types, etc.) based upon
87 their capabilities' property definitions' values.
89 :type: list of (str, :class:`CapabilityDefinition`)
93 def _get_node_type(self, context):
94 if hasattr(self._container, '_get_node'):
95 node_type, node_type_variant = self._container._get_node(context)
96 return node_type if node_type_variant == 'node_type' else None
100 def _get_type_for_name(self, context, name):
101 node_type = self._get_node_type(context)
102 if node_type is not None:
103 properties = node_type._get_properties(context)
104 prop = properties.get(name)
105 return prop._get_type(context) if prop is not None else None