Merge "Add attributes of address to tosca.nodes.nfv.CP address"
[parser.git] / tosca2heat / tosca-parser / toscaparser / elements / artifacttype.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 from toscaparser.elements.statefulentitytype import StatefulEntityType
14
15
16 class ArtifactTypeDef(StatefulEntityType):
17     '''TOSCA built-in artifacts type.'''
18
19     def __init__(self, atype, custom_def=None):
20         super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX,
21                                               custom_def)
22         self.type = atype
23         self.properties = None
24         if self.PROPERTIES in self.defs:
25             self.properties = self.defs[self.PROPERTIES]
26         self.parent_artifacts = self._get_parent_artifacts()
27
28     def _get_parent_artifacts(self):
29         artifacts = {}
30         parent_artif = self.parent_type
31         if parent_artif:
32             while parent_artif != 'tosca.artifacts.Root':
33                 artifacts[parent_artif] = self.TOSCA_DEF[parent_artif]
34                 parent_artif = artifacts[parent_artif]['derived_from']
35         return artifacts
36
37     @property
38     def parent_type(self):
39         '''Return an artifact this artifact is derived from.'''
40         return self.derived_from(self.defs)
41
42     def get_artifact(self, name):
43         '''Return the definition of an artifact field by name.'''
44         if name in self.defs:
45             return self.defs[name]