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 / templates.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.collections import (FrozenDict, FrozenList)
17 from aria.utils.caching import cachedmethod
18 from aria.parser import implements_specification
19 from aria.parser.presentation import (has_fields, primitive_field, primitive_list_field,
20                                       object_field, object_list_field, object_dict_field,
21                                       object_sequenced_list_field, field_validator,
22                                       type_validator, list_type_validator)
23
24 from .assignments import (PropertyAssignment, AttributeAssignment, RequirementAssignment,
25                           CapabilityAssignment, InterfaceAssignment, ArtifactAssignment)
26 from .definitions import ParameterDefinition
27 from .filters import NodeFilter
28 from .misc import (Description, MetaData, Repository, Import, SubstitutionMappings)
29 from .modeling.parameters import (get_assigned_and_defined_parameter_values, get_parameter_values)
30 from .modeling.interfaces import get_template_interfaces
31 from .modeling.requirements import get_template_requirements
32 from .modeling.capabilities import get_template_capabilities
33 from .modeling.artifacts import get_inherited_artifact_definitions
34 from .modeling.policies import get_policy_targets
35 from .modeling.copy import get_default_raw_from_copy
36 from .presentation.extensible import ExtensiblePresentation
37 from .presentation.field_validators import copy_validator, policy_targets_validator
38 from .presentation.types import (convert_name_to_full_type_name, get_type_by_name)
39 from .types import (ArtifactType, DataType, CapabilityType, InterfaceType, RelationshipType,
40                     NodeType, GroupType, PolicyType)
41
42
43 @has_fields
44 @implements_specification('3.7.3', 'tosca-simple-1.0')
45 class NodeTemplate(ExtensiblePresentation):
46     """
47     A Node Template specifies the occurrence of a manageable software component as part of an
48     application's topology model which is defined in a TOSCA Service Template. A Node template is an
49     instance of a specified Node Type and can provide customized properties, constraints or
50     operations which override the defaults provided by its Node Type and its implementations.
51
52     See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
53     /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
54     #DEFN_ENTITY_NODE_TEMPLATE>`__
55     """
56
57     @field_validator(type_validator('node type', convert_name_to_full_type_name, 'node_types'))
58     @primitive_field(str, required=True)
59     def type(self):
60         """
61         The required name of the Node Type the Node Template is based upon.
62
63         :type: :obj:`basestring`
64         """
65
66     @object_field(Description)
67     def description(self):
68         """
69         An optional description for the Node Template.
70
71         :type: :class:`Description`
72         """
73
74     @primitive_list_field(str)
75     def directives(self):
76         """
77         An optional list of directive values to provide processing instructions to orchestrators and
78         tooling.
79
80         :type: [:obj:`basestring`]
81         """
82
83     @object_dict_field(PropertyAssignment)
84     def properties(self):
85         """
86         An optional list of property value assignments for the Node Template.
87
88         :type: {:obj:`basestring`: :class:`PropertyAssignment`}
89         """
90
91     @object_dict_field(AttributeAssignment)
92     def attributes(self):
93         """
94         An optional list of attribute value assignments for the Node Template.
95
96         :type: {:obj:`basestring`: :class:`AttributeAssignment`}
97         """
98
99     @object_sequenced_list_field(RequirementAssignment)
100     def requirements(self):
101         """
102         An optional sequenced list of requirement assignments for the Node Template.
103
104         :type: list of (str, :class:`RequirementAssignment`)
105         """
106
107     @object_dict_field(CapabilityAssignment)
108     def capabilities(self):
109         """
110         An optional list of capability assignments for the Node Template.
111
112         :type: {:obj:`basestring`: :class:`CapabilityAssignment`}
113         """
114
115     @object_dict_field(InterfaceAssignment)
116     def interfaces(self):
117         """
118         An optional list of named interface definitions for the Node Template.
119
120         :type: {:obj:`basestring`: :class:`InterfaceAssignment`}
121         """
122
123     @object_dict_field(ArtifactAssignment)
124     def artifacts(self):
125         """
126         An optional list of named artifact definitions for the Node Template.
127
128         :type: {:obj:`basestring`: :class:`ArtifactAssignment`}
129         """
130
131     @object_field(NodeFilter)
132     def node_filter(self):
133         """
134         The optional filter definition that TOSCA orchestrators would use to select the correct
135         target node. This keyname is only valid if the directive has the value of "selectable" set.
136
137         :type: :class:`NodeFilter`
138         """
139
140     @field_validator(copy_validator('node template', 'node_templates'))
141     @primitive_field(str)
142     def copy(self):
143         """
144         The optional (symbolic) name of another node template to copy into (all keynames and values)
145         and use as a basis for this node template.
146
147         :type: :obj:`basestring`
148         """
149
150     @cachedmethod
151     def _get_default_raw(self):
152         return get_default_raw_from_copy(self, 'node_templates')
153
154     @cachedmethod
155     def _get_type(self, context):
156         return get_type_by_name(context, self.type, 'node_types')
157
158     @cachedmethod
159     def _get_property_values(self, context):
160         return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))
161
162     @cachedmethod
163     def _get_attribute_default_values(self, context):
164         return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'attribute'))
165
166     @cachedmethod
167     def _get_requirements(self, context):
168         return FrozenList(get_template_requirements(context, self))
169
170     @cachedmethod
171     def _get_capabilities(self, context):
172         return FrozenDict(get_template_capabilities(context, self))
173
174     @cachedmethod
175     def _get_interfaces(self, context):
176         return FrozenDict(get_template_interfaces(context, self, 'node template'))
177
178     @cachedmethod
179     def _get_artifacts(self, context):
180         return FrozenDict(get_inherited_artifact_definitions(context, self))
181
182     def _validate(self, context):
183         super(NodeTemplate, self)._validate(context)
184         self._get_property_values(context)
185         self._get_requirements(context)
186         self._get_capabilities(context)
187         self._get_interfaces(context)
188         self._get_artifacts(context)
189
190     def _dump(self, context):
191         self._dump_content(context, (
192             'description',
193             'type',
194             'directives',
195             'properties',
196             'attributes',
197             'requirements',
198             'capabilities',
199             'interfaces',
200             'artifacts',
201             'node_filter',
202             'copy'))
203
204
205 @has_fields
206 @implements_specification('3.7.4', 'tosca-simple-1.0')
207 class RelationshipTemplate(ExtensiblePresentation):
208     """
209     A Relationship Template specifies the occurrence of a manageable relationship between node
210     templates as part of an application's topology model that is defined in a TOSCA Service
211     Template. A Relationship template is an instance of a specified Relationship Type and can
212     provide customized properties, constraints or operations which override the defaults provided by
213     its Relationship Type and its implementations.
214
215     See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
216     /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
217     #DEFN_ENTITY_RELATIONSHIP_TEMPLATE>`__
218     """
219
220     @field_validator(type_validator('relationship type', convert_name_to_full_type_name,
221                                     'relationship_types'))
222     @primitive_field(str, required=True)
223     def type(self):
224         """
225         The required name of the Relationship Type the Relationship Template is based upon.
226
227         :type: :obj:`basestring`
228         """
229
230     @object_field(Description)
231     def description(self):
232         """
233         An optional description for the Relationship Template.
234
235         :type: :class:`Description`
236         """
237
238     @object_dict_field(PropertyAssignment)
239     def properties(self):
240         """
241         An optional list of property assignments for the Relationship Template.
242
243         :type: {:obj:`basestring`: :class:`PropertyAssignment`}
244         """
245
246     @object_dict_field(AttributeAssignment)
247     def attributes(self):
248         """
249         An optional list of attribute assignments for the Relationship Template.
250
251         :type: {:obj:`basestring`: :class:`AttributeAssignment`}
252         """
253
254     @object_dict_field(InterfaceAssignment)
255     def interfaces(self):
256         """
257         An optional list of named interface definitions for the Node Template.
258
259         ARIA NOTE: Spec is wrong here, should be Relationship Template.
260
261         :type: {:obj:`basestring`: :class:`InterfaceAssignment`}
262         """
263
264     @field_validator(copy_validator('relationship template', 'relationship_templates'))
265     @primitive_field(str)
266     def copy(self):
267         """
268         The optional (symbolic) name of another relationship template to copy into (all keynames and
269         values) and use as a basis for this relationship template.
270
271         :type: :obj:`basestring`
272         """
273
274     @cachedmethod
275     def _get_default_raw(self):
276         return get_default_raw_from_copy(self, 'relationship_templates')
277
278     @cachedmethod
279     def _get_type(self, context):
280         return get_type_by_name(context, self.type, 'relationship_types')
281
282     @cachedmethod
283     def _get_property_values(self, context):
284         return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))
285
286     @cachedmethod
287     def _get_interfaces(self, context):
288         return FrozenDict(get_template_interfaces(context, self, 'relationship template'))
289
290     def _validate(self, context):
291         super(RelationshipTemplate, self)._validate(context)
292         self._get_property_values(context)
293         self._get_interfaces(context)
294
295     def _dump(self, context):
296         self._dump_content(context, (
297             'description',
298             'type',
299             'properties',
300             'attributes',
301             'interfaces',
302             'copy'))
303
304
305 @has_fields
306 @implements_specification('3.7.5', 'tosca-simple-1.0')
307 class GroupTemplate(ExtensiblePresentation):
308     """
309     A group definition defines a logical grouping of node templates, typically for management
310     purposes, but is separate from the application's topology template.
311
312     See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
313     /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
314     #DEFN_ELEMENT_GROUP_DEF>`__
315     """
316
317     @field_validator(type_validator('group type', convert_name_to_full_type_name,
318                                     'group_types'))
319     @primitive_field(str, required=True)
320     def type(self):
321         """
322         The required name of the group type the group definition is based upon.
323
324         :type: :obj:`basestring`
325         """
326
327     @object_field(Description)
328     def description(self):
329         """
330         The optional description for the group definition.
331
332         :type: :class:`Description`
333         """
334
335     @object_dict_field(PropertyAssignment)
336     def properties(self):
337         """
338         An optional list of property value assignments for the group definition.
339
340         :type: {:obj:`basestring`: :class:`PropertyAssignment`}
341         """
342
343     @field_validator(list_type_validator('node template', 'topology_template', 'node_templates'))
344     @primitive_list_field(str)
345     def members(self):
346         """
347         The optional list of one or more node template names that are members of this group
348         definition.
349
350         :type: [:obj:`basestring`]
351         """
352
353     @object_dict_field(InterfaceAssignment)
354     def interfaces(self):
355         """
356         An optional list of named interface definitions for the group definition.
357
358         :type: {:obj:`basestring`: :class:`InterfaceDefinition`}
359         """
360
361     @cachedmethod
362     def _get_type(self, context):
363         return get_type_by_name(context, self.type, 'group_types')
364
365     @cachedmethod
366     def _get_property_values(self, context):
367         return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))
368
369     @cachedmethod
370     def _get_interfaces(self, context):
371         return FrozenDict(get_template_interfaces(context, self, 'group definition'))
372
373     def _validate(self, context):
374         super(GroupTemplate, self)._validate(context)
375         self._get_property_values(context)
376         self._get_interfaces(context)
377
378
379 @has_fields
380 @implements_specification('3.7.6', 'tosca-simple-1.0')
381 class PolicyTemplate(ExtensiblePresentation):
382     """
383     A policy definition defines a policy that can be associated with a TOSCA topology or top-level
384     entity definition (e.g., group definition, node template, etc.).
385
386     See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
387     /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
388     #DEFN_ELEMENT_POLICY_DEF>`__
389     """
390
391     @field_validator(type_validator('policy type', convert_name_to_full_type_name, 'policy_types'))
392     @primitive_field(str, required=True)
393     def type(self):
394         """
395         The required name of the policy type the policy definition is based upon.
396
397         :type: :obj:`basestring`
398         """
399
400     @object_field(Description)
401     def description(self):
402         """
403         The optional description for the policy definition.
404
405         :type: :class:`Description`
406         """
407
408     @object_dict_field(PropertyAssignment)
409     def properties(self):
410         """
411         An optional list of property value assignments for the policy definition.
412
413         :type: {:obj:`basestring`: :class:`PropertyAssignment`
414         """
415
416     @field_validator(policy_targets_validator)
417     @primitive_list_field(str)
418     def targets(self):
419         """
420         An optional list of valid Node Templates or Groups the Policy can be applied to.
421
422         :type: [:obj:`basestring`]
423         """
424
425     @cachedmethod
426     def _get_type(self, context):
427         return get_type_by_name(context, self.type, 'policy_types')
428
429     @cachedmethod
430     def _get_property_values(self, context):
431         return FrozenDict(get_assigned_and_defined_parameter_values(context, self, 'property'))
432
433     @cachedmethod
434     def _get_targets(self, context):
435         node_templates, groups = get_policy_targets(context, self)
436         return FrozenList(node_templates), FrozenList(groups)
437
438     def _validate(self, context):
439         super(PolicyTemplate, self)._validate(context)
440         self._get_property_values(context)
441
442
443 @has_fields
444 @implements_specification('3.8', 'tosca-simple-1.0')
445 class TopologyTemplate(ExtensiblePresentation):
446     """
447     This section defines the topology template of a cloud application. The main ingredients of the
448     topology template are node templates representing components of the application and relationship
449     templates representing links between the components. These elements are defined in the nested
450     ``node_templates`` section and the nested relationship_templates sections, respectively.
451     Furthermore, a topology template allows for defining input parameters, output parameters as well
452     as grouping of node templates.
453
454     See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
455     /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
456     #DEFN_ENTITY_TOPOLOGY_TEMPLATE>`__
457     """
458
459     @object_field(Description)
460     def description(self):
461         """
462         The optional description for the Topology Template.
463
464         :type: :class:`Description`
465         """
466
467     @object_dict_field(ParameterDefinition)
468     def inputs(self):
469         """
470         An optional list of input parameters (i.e., as parameter definitions) for the Topology
471         Template.
472
473         :type: {:obj:`basestring`: :class:`ParameterDefinition`}
474         """
475
476     @object_dict_field(NodeTemplate)
477     def node_templates(self):
478         """
479         An optional list of node template definitions for the Topology Template.
480
481         :type: {:obj:`basestring`: :class:`NodeTemplate`}
482         """
483
484     @object_dict_field(RelationshipTemplate)
485     def relationship_templates(self):
486         """
487         An optional list of relationship templates for the Topology Template.
488
489         :type: {:obj:`basestring`: :class:`RelationshipTemplate`}
490         """
491
492     @object_dict_field(GroupTemplate)
493     def groups(self):
494         """
495         An optional list of Group definitions whose members are node templates defined within this
496         same Topology Template.
497
498         :class:`GroupTemplate`
499         """
500
501     @object_dict_field(PolicyTemplate)
502     def policies(self):
503         """
504         An optional list of Policy definitions for the Topology Template.
505
506         :type: {:obj:`basestring`: :class:`PolicyTemplate`}
507         """
508
509     @object_dict_field(ParameterDefinition)
510     def outputs(self):
511         """
512         An optional list of output parameters (i.e., as parameter definitions) for the Topology
513         Template.
514
515         :type: {:obj:`basestring`: :class:`ParameterDefinition`}
516         """
517
518     @object_field(SubstitutionMappings)
519     def substitution_mappings(self):
520         """
521         An optional declaration that exports the topology template as an implementation of a Node
522         type.
523
524         This also includes the mappings between the external Node Types named capabilities and
525         requirements to existing implementations of those capabilities and requirements on Node
526         templates declared within the topology template.
527         """
528
529     @cachedmethod
530     def _get_input_values(self, context):
531         return FrozenDict(get_parameter_values(context, self, 'inputs'))
532
533     @cachedmethod
534     def _get_output_values(self, context):
535         return FrozenDict(get_parameter_values(context, self, 'outputs'))
536
537     def _validate(self, context):
538         super(TopologyTemplate, self)._validate(context)
539         self._get_input_values(context)
540         self._get_output_values(context)
541
542     def _dump(self, context):
543         self._dump_content(context, (
544             'description',
545             'inputs',
546             'node_templates',
547             'relationship_templates',
548             'groups',
549             'policies',
550             'outputs',
551             'substitution_mappings'))
552
553
554 @has_fields
555 @implements_specification('3.9', 'tosca-simple-1.0')
556 class ServiceTemplate(ExtensiblePresentation):
557     """
558     Servicate template.
559
560     See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
561     /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
562     #DEFN_ELEMENT_SERVICE_TEMPLATE>`__.
563     """
564
565     @primitive_field(str)
566     @implements_specification('3.9.3.1', 'tosca-simple-1.0')
567     def tosca_definitions_version(self):
568         """
569         Defines the version of the TOSCA Simple Profile specification the template (grammar)
570         complies with.
571
572         See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
573         /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
574         #_Toc379455047>`__
575
576         :type: :obj:`basestring`
577         """
578
579     @object_field(MetaData)
580     def metadata(self):
581         """
582         Defines a section used to declare additional metadata information. Domain-specific TOSCA
583         profile specifications may define keynames that are required for their implementations.
584
585         See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
586         /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
587         #_Toc379455048>`__
588
589         :type: :class:`MetaData`
590         """
591
592     @object_field(Description)
593     @implements_specification('3.9.3.6', 'tosca-simple-1.0')
594     def description(self):
595         """
596         Declares a description for this Service Template and its contents.
597
598         :type: :class:`Description`
599         """
600
601     @primitive_field()
602     @implements_specification('3.9.3.7', 'tosca-simple-1.0')
603     def dsl_definitions(self):
604         """
605         Declares optional DSL-specific definitions and conventions. For example, in YAML, this
606         allows defining reusable YAML macros (i.e., YAML alias anchors) for use throughout the TOSCA
607         Service Template.
608
609         See the `TOSCA Simple Profile v1.0 cos01 specification <http://docs.oasis-open.org/tosca
610         /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html
611         #_Toc397688790>`__
612         """
613
614     @object_dict_field(Repository)
615     @implements_specification('3.9.3.8', 'tosca-simple-1.0')
616     def repositories(self):
617         """
618         Declares the list of external repositories which contain artifacts that are referenced in
619         the service template along with their addresses and necessary credential information used to
620         connect to them in order to retrieve the artifacts.
621
622         :type: {:obj:`basestring`: :class:`Repository`}
623         """
624
625     @object_list_field(Import)
626     @implements_specification('3.9.3.9', 'tosca-simple-1.0')
627     def imports(self):
628         """
629         Declares import statements external TOSCA Definitions documents. For example, these may be
630         file location or URIs relative to the service template file within the same TOSCA CSAR file.
631
632         :type: list of :class:`Import`
633         """
634
635     @object_dict_field(ArtifactType)
636     @implements_specification('3.9.3.10', 'tosca-simple-1.0')
637     def artifact_types(self):
638         """
639         This section contains an optional list of artifact type definitions for use in the service
640         template.
641
642         :type: {:obj:`basestring`: :class:`ArtifactType`}
643         """
644
645     @object_dict_field(DataType)
646     @implements_specification('3.9.3.11', 'tosca-simple-1.0')
647     def data_types(self):
648         """
649         Declares a list of optional TOSCA Data Type definitions.
650
651         :type: {:obj:`basestring`: :class:`DataType`}
652         """
653
654     @object_dict_field(CapabilityType)
655     @implements_specification('3.9.3.12', 'tosca-simple-1.0')
656     def capability_types(self):
657         """
658         This section contains an optional list of capability type definitions for use in the service
659         template.
660
661         :type: {:obj:`basestring`: :class:`CapabilityType`}
662         """
663
664     @object_dict_field(InterfaceType)
665     @implements_specification('3.9.3.13', 'tosca-simple-1.0')
666     def interface_types(self):
667         """
668         This section contains an optional list of interface type definitions for use in the service
669         template.
670
671         :type: {:obj:`basestring`: :class:`InterfaceType`}
672         """
673
674     @object_dict_field(RelationshipType)
675     @implements_specification('3.9.3.14', 'tosca-simple-1.0')
676     def relationship_types(self):
677         """
678         This section contains a set of relationship type definitions for use in the service
679         template.
680
681         :type: {:obj:`basestring`: :class:`RelationshipType`}
682         """
683
684     @object_dict_field(NodeType)
685     @implements_specification('3.9.3.15', 'tosca-simple-1.0')
686     def node_types(self):
687         """
688         This section contains a set of node type definitions for use in the service template.
689
690         :type: {:obj:`basestring`: :class:`NodeType`}
691         """
692
693     @object_dict_field(GroupType)
694     @implements_specification('3.9.3.16', 'tosca-simple-1.0')
695     def group_types(self):
696         """
697         This section contains a list of group type definitions for use in the service template.
698
699         :type: {:obj:`basestring`: :class:`GroupType`}
700         """
701
702     @object_dict_field(PolicyType)
703     @implements_specification('3.9.3.17', 'tosca-simple-1.0')
704     def policy_types(self):
705         """
706         This section contains a list of policy type definitions for use in the service template.
707
708         :type: {:obj:`basestring`: :class:`PolicyType`}
709         """
710
711     @object_field(TopologyTemplate)
712     def topology_template(self):
713         """
714         Defines the topology template of an application or service, consisting of node templates
715         that represent the application's or service's components, as well as relationship templates
716         representing relations between the components.
717
718         :type: :class:`TopologyTemplate`
719         """
720
721     def _dump(self, context):
722         self._dump_content(context, (
723             'description',
724             'tosca_definitions_version',
725             'metadata',
726             'repositories',
727             'imports',
728             'artifact_types',
729             'data_types',
730             'capability_types',
731             'interface_types',
732             'relationship_types',
733             'node_types',
734             'group_types',
735             'policy_types',
736             'topology_template'))