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 / presenter.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 (FrozenList, EMPTY_READ_ONLY_LIST)
17 from aria.utils.caching import cachedmethod
18 from aria.parser.presentation import Presenter
19
20 from .modeling import create_service_template_model
21 from .modeling.functions import (Concat, Token, GetInput, GetProperty, GetAttribute,
22                                  GetOperationOutput, GetNodesOfType, GetArtifact)
23 from .templates import ServiceTemplate
24
25
26 class ToscaSimplePresenter1_0(Presenter): # pylint: disable=invalid-name,abstract-method
27     """
28     ARIA presenter for the `TOSCA Simple Profile v1.0 cos01 <http://docs.oasis-open.org/tosca
29     /TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html>`__.
30
31     Supported ``tosca_definitions_version`` values:
32
33     * ``tosca_simple_yaml_1_0``
34     """
35
36     DSL_VERSIONS = ('tosca_simple_yaml_1_0',)
37     ALLOWED_IMPORTED_DSL_VERSIONS = ('tosca_simple_yaml_1_0',)
38     SIMPLE_PROFILE_LOCATION = 'tosca-simple-1.0/tosca-simple-1.0.yaml'
39     SPECIAL_IMPORTS = {
40         'aria-1.0': 'aria-1.0/aria-1.0.yaml',
41     'azure-plugin':'azure-plugin/azureplugin.yaml'}
42
43     @property
44     @cachedmethod
45     def service_template(self):
46         return ServiceTemplate(raw=self._raw)
47
48     @property
49     @cachedmethod
50     def functions(self):
51         return {
52             'concat': Concat,
53             'token': Token,
54             'get_input': GetInput,
55             'get_property': GetProperty,
56             'get_attribute': GetAttribute,
57             'get_operation_output': GetOperationOutput,
58             'get_nodes_of_type': GetNodesOfType,
59             'get_artifact': GetArtifact}
60
61     # Presentation
62
63     def _dump(self, context):
64         self.service_template._dump(context)
65
66     def _validate(self, context):
67         self.service_template._validate(context)
68
69     # Presenter
70
71     @cachedmethod
72     def _get_import_locations(self, context):
73         import_locations = []
74         if context.presentation.import_profile:
75             import_locations.append(self.SIMPLE_PROFILE_LOCATION)
76         imports = self._get('service_template', 'imports')
77         if imports:
78             import_locations += [self.SPECIAL_IMPORTS.get(i.file, i.file) for i in imports]
79         return FrozenList(import_locations) if import_locations else EMPTY_READ_ONLY_LIST
80
81     @cachedmethod
82     def _get_model(self, context): # pylint: disable=no-self-use
83         return create_service_template_model(context)