vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / extensions / aria_extension_tosca / simple_v1_0 / filters.py
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
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
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)
19
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)
24
25
26 @has_fields
27 class CapabilityFilter(ExtensiblePresentation):
28     """
29     Capability filter.
30     """
31
32     @object_sequenced_list_field(ConstraintClause)
33     def properties(self):
34         pass
35
36     @cachedmethod
37     def _get_node_type(self, context):
38         return self._container._get_node_type(context)
39
40     @cachedmethod
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
49
50         return None
51
52
53 @has_fields
54 @implements_specification('3.5.4', 'tosca-simple-1.0')
55 class NodeFilter(ExtensiblePresentation):
56     """
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.
59
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>`__
63     """
64
65     @field_validator(node_filter_properties_validator)
66     @object_sequenced_list_field(ConstraintClause)
67     @implements_specification('3.5.3', 'tosca-simple-1.0')
68     def properties(self):
69         """
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.
73
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>`__
77
78         :type: list of (str, :class:`ConstraintClause`)
79         """
80
81     @field_validator(node_filter_capabilities_validator)
82     @object_sequenced_list_field(CapabilityFilter)
83     def capabilities(self):
84         """
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.
88
89         :type: list of (str, :class:`CapabilityDefinition`)
90         """
91
92     @cachedmethod
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
97         return None
98
99     @cachedmethod
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
106
107         return None