Add type attributes
Read the schema definitions of type attributes into node type. Change-Id: I555382c656eab87972619a4e92c9f057ce1de9e1 Implements: blueprint tosca-type-attributes
This commit is contained in:
@@ -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
|
||||
|
||||
23
translator/toscalib/elements/attribute_definition.py
Normal file
23
translator/toscalib/elements/attribute_definition.py
Normal file
@@ -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
|
||||
@@ -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.
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user