diff --git a/translator/toscalib/elements/TOSCA_definition.yaml b/translator/toscalib/elements/TOSCA_definition.yaml index f8fddfa..37b71ed 100644 --- a/translator/toscalib/elements/TOSCA_definition.yaml +++ b/translator/toscalib/elements/TOSCA_definition.yaml @@ -86,6 +86,9 @@ tosca.nodes.Compute: description: > The primary IP address assigned by the cloud provider that applications may use to access the Compute node. + attributes: + ip_address: + type: string capabilities: host: type: tosca.capabilities.Container diff --git a/translator/toscalib/elements/attribute_definition.py b/translator/toscalib/elements/attribute_definition.py new file mode 100644 index 0000000..783b16b --- /dev/null +++ b/translator/toscalib/elements/attribute_definition.py @@ -0,0 +1,23 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class AttributeDef(object): + '''TOSCA built-in Attribute type.''' + + def __init__(self, name, value=None, schema=None): + self.name = name + self.value = value + self.schema = schema diff --git a/translator/toscalib/elements/nodetype.py b/translator/toscalib/elements/nodetype.py index 0398b2c..0eb6847 100644 --- a/translator/toscalib/elements/nodetype.py +++ b/translator/toscalib/elements/nodetype.py @@ -14,6 +14,7 @@ # under the License. from translator.toscalib.common.exception import InvalidNodeTypeError +from translator.toscalib.elements.attribute_definition import AttributeDef from translator.toscalib.elements.capabilitytype import CapabilityTypeDef from translator.toscalib.elements.interfaces import InterfacesDef from translator.toscalib.elements.property_definition import PropertyDef @@ -21,10 +22,10 @@ from translator.toscalib.elements.relationshiptype import RelationshipType from translator.toscalib.elements.statefulentitytype import StatefulEntityType -SECTIONS = (DERIVED_FROM, PROPERTIES, REQUIREMENTS, +SECTIONS = (DERIVED_FROM, PROPERTIES, ATTRIBUTES, REQUIREMENTS, INTERFACES, CAPABILITIES) = \ - ('derived_from', 'properties', 'requirements', 'interfaces', - 'capabilities') + ('derived_from', 'properties', 'attributes', 'requirements', + 'interfaces', 'capabilities') class NodeType(StatefulEntityType): @@ -58,6 +59,15 @@ class NodeType(StatefulEntityType): properties.append(PropertyDef(prop, None, schema)) return properties + @property + def attributes_def(self): + '''Return a list of attribute definition objects.''' + attrs = self.get_value(ATTRIBUTES) + if attrs: + return [AttributeDef(attr, None, schema) + for attr, schema in attrs.items()] + return [] + @property def relationship(self): '''Return a dictionary of relationships to other node types. diff --git a/translator/toscalib/tests/test_toscadef.py b/translator/toscalib/tests/test_toscadef.py index 19e0562..b0c1aaf 100644 --- a/translator/toscalib/tests/test_toscadef.py +++ b/translator/toscalib/tests/test_toscadef.py @@ -43,6 +43,11 @@ class ToscaDefTest(TestCase): self.assertTrue([p.required for p in compute_type.properties_def if p.name == 'os_type']) + def test_attributes_def(self): + self.assertEqual( + ['ip_address'], + sorted([p.name for p in compute_type.attributes_def])) + def test_requirements(self): self.assertEqual(compute_type.requirements, None) self.assertEqual(