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.collections import (FrozenList, EMPTY_READ_ONLY_LIST)
17 from aria.utils.caching import cachedmethod
18 from aria.parser.presentation import Presenter
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
26 class ToscaSimplePresenter1_0(Presenter): # pylint: disable=invalid-name,abstract-method
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>`__.
31 Supported ``tosca_definitions_version`` values:
33 * ``tosca_simple_yaml_1_0``
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'
40 'aria-1.0': 'aria-1.0/aria-1.0.yaml',
41 'azure-plugin':'azure-plugin/azureplugin.yaml'}
45 def service_template(self):
46 return ServiceTemplate(raw=self._raw)
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}
63 def _dump(self, context):
64 self.service_template._dump(context)
66 def _validate(self, context):
67 self.service_template._validate(context)
72 def _get_import_locations(self, context):
74 if context.presentation.import_profile:
75 import_locations.append(self.SIMPLE_PROFILE_LOCATION)
76 imports = self._get('service_template', '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
82 def _get_model(self, context): # pylint: disable=no-self-use
83 return create_service_template_model(context)