diff options
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/elements')
5 files changed, 31 insertions, 9 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py b/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py index 3bfd7d0..887e99a 100644 --- a/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py +++ b/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py @@ -20,6 +20,7 @@ class ArtifactTypeDef(StatefulEntityType): super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX, custom_def) self.type = atype + self.custom_def = custom_def self.properties = None if self.PROPERTIES in self.defs: self.properties = self.defs[self.PROPERTIES] @@ -27,17 +28,24 @@ class ArtifactTypeDef(StatefulEntityType): def _get_parent_artifacts(self): artifacts = {} - parent_artif = self.parent_type + parent_artif = self.parent_type.type if self.parent_type else None if parent_artif: while parent_artif != 'tosca.artifacts.Root': + # only support normative artifact, shall be modified future artifacts[parent_artif] = self.TOSCA_DEF[parent_artif] parent_artif = artifacts[parent_artif]['derived_from'] return artifacts @property def parent_type(self): - '''Return an artifact this artifact is derived from.''' - return self.derived_from(self.defs) + '''Return a artifact entity from which this entity is derived.''' + if not hasattr(self, 'defs'): + return None + partifact_entity = self.derived_from(self.defs) + if partifact_entity: + return ArtifactTypeDef(partifact_entity, self.custom_def) + else: + return None def get_artifact(self, name): '''Return the definition of an artifact field by name.''' diff --git a/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py b/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py index 5d620a5..72e7e3f 100644 --- a/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py +++ b/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py @@ -106,8 +106,13 @@ class EntityType(object): value[k] = v if isinstance(value, list): for p_value in parent_value: - if p_value not in value: - value.append(p_value) + if isinstance(p_value, dict): + if p_value.keys()[0] not in [ + item.keys()[0] for item in value]: + value.append(p_value) + else: + if p_value not in value: + value.append(p_value) else: value = copy.copy(parent_value) p = p.parent_type diff --git a/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py b/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py index 148d2b6..f5e4eb0 100644 --- a/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py +++ b/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py @@ -98,6 +98,10 @@ class NodeType(StatefulEntityType): provided capability. ''' + # All types,include normative and custom types, here will + # be substituted because the global moification of TOSCA_DEF + self.TOSCA_DEF.update(self.custom_def) + # Filter the node types node_types = [node_type for node_type in self.TOSCA_DEF.keys() if node_type.startswith(self.NODE_PREFIX) and diff --git a/tosca2heat/tosca-parser/toscaparser/elements/policytype.py b/tosca2heat/tosca-parser/toscaparser/elements/policytype.py index 04cbab5..8fbb0f0 100644 --- a/tosca2heat/tosca-parser/toscaparser/elements/policytype.py +++ b/tosca2heat/tosca-parser/toscaparser/elements/policytype.py @@ -28,6 +28,7 @@ class PolicyType(StatefulEntityType): super(PolicyType, self).__init__(ptype, self.POLICY_PREFIX, custom_def) self.type = ptype + self.custom_def = custom_def self._validate_keys() self.meta_data = None @@ -55,7 +56,7 @@ class PolicyType(StatefulEntityType): def _get_parent_policies(self): policies = {} - parent_policy = self.parent_type + parent_policy = self.parent_type.type if self.parent_type else None if parent_policy: while parent_policy != 'tosca.policies.Root': policies[parent_policy] = self.TOSCA_DEF[parent_policy] @@ -64,8 +65,12 @@ class PolicyType(StatefulEntityType): @property def parent_type(self): - '''Return a policy this policy is derived from.''' - return self.derived_from(self.defs) + '''Return a policy statefulentity of this node is derived from.''' + if not hasattr(self, 'defs'): + return None + ppolicy_entity = self.derived_from(self.defs) + if ppolicy_entity: + return PolicyType(ppolicy_entity, self.custom_def) def get_policy(self, name): '''Return the definition of a policy field by name.''' diff --git a/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py b/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py index 9462d38..25440ca 100644 --- a/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py +++ b/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py @@ -26,7 +26,7 @@ class RelationshipType(StatefulEntityType): '''Return a relationship this reletionship is derived from.''' prel = self.derived_from(self.defs) if prel: - return RelationshipType(prel) + return RelationshipType(prel, self.custom_def) @property def valid_target_types(self): |