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
5 # http://www.apache.org/licenses/LICENSE-2.0
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
13 from toscaparser.elements.statefulentitytype import StatefulEntityType
16 class ArtifactTypeDef(StatefulEntityType):
17 '''TOSCA built-in artifacts type.'''
19 def __init__(self, atype, custom_def=None):
20 super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX,
23 self.custom_def = custom_def
24 self.properties = None
25 if self.PROPERTIES in self.defs:
26 self.properties = self.defs[self.PROPERTIES]
27 self.parent_artifacts = self._get_parent_artifacts()
29 def _get_parent_artifacts(self):
31 parent_artif = self.parent_type.type if self.parent_type else None
33 while parent_artif != 'tosca.artifacts.Root':
34 artifacts[parent_artif] = self.TOSCA_DEF[parent_artif]
35 parent_artif = artifacts[parent_artif]['derived_from']
39 def parent_type(self):
40 '''Return a artifact entity from which this entity is derived.'''
41 if not hasattr(self, 'defs'):
43 partifact_entity = self.derived_from(self.defs)
45 return ArtifactTypeDef(partifact_entity, self.custom_def)
47 def get_artifact(self, name):
48 '''Return the definition of an artifact field by name.'''
50 return self.defs[name]