TOSCA: interfaces for relationship templates

TOSCA relationship interfaces are provided for various configurations to run
on the host or target machine for pre, post configuration operations. Make
such interfaces available via relationship templates.

Change-Id: I6626e5baaa0ebc369d8e4ab74720e880d52926a7
This commit is contained in:
spzala 2015-05-14 04:33:35 -07:00
parent 3516ab4fda
commit e2143adbf8
4 changed files with 40 additions and 14 deletions

View File

@ -29,14 +29,16 @@ class InterfacesDef(StatefulEntityType):
node_template=None, name=None, value=None):
self.ntype = node_type
self.node_template = node_template
if self.INTERFACE_PREFIX not in interfacetype:
interfacetype = self.INTERFACE_PREFIX + interfacetype
self.type = interfacetype
self.name = name
self.value = value
self.implementation = None
self.inputs = None
self.defs = {}
if interfacetype == LIFECYCLE_SHORTNAME:
interfacetype = LIFECYCLE
if interfacetype == CONFIGURE_SHORTNAME:
interfacetype = CONFIGURE
if node_type:
self.defs = self.TOSCA_DEF[interfacetype]
if value:

View File

@ -218,8 +218,19 @@ class EntityTemplate(object):
def _create_interfaces(self):
interfaces = []
type_interfaces = self.type_definition.get_value(self.INTERFACES,
self.entity_tpl)
type_interfaces = None
if isinstance(self.type_definition, RelationshipType):
if isinstance(self.entity_tpl, dict):
for rel_def, value in self.entity_tpl.items():
if rel_def != 'type':
rel = self.entity_tpl.get(rel_def).get('relationship')
if rel:
if self.INTERFACES in rel:
type_interfaces = rel[self.INTERFACES]
break
else:
type_interfaces = self.type_definition.get_value(self.INTERFACES,
self.entity_tpl)
if type_interfaces:
for interface_type, value in type_interfaces.items():
for op, op_def in value.items():

View File

@ -202,19 +202,21 @@ class ToscaTemplateTest(TestCase):
def test_relationship_interface(self):
template = ToscaTemplate(self.tosca_elk_tpl)
for node_tpl in template.nodetemplates:
if node_tpl.name == 'nodejs':
config_interface = 'tosca.interfaces.relationship.Configure'
if node_tpl.name == 'logstash':
config_interface = 'Configure'
artifact = 'logstash/configure_elasticsearch.py'
relation = node_tpl.relationships
for key in relation.keys():
rel_tpl = relation.get(key).get_relationship_template()
interfaces = rel_tpl[0].interfaces
for interface in interfaces:
self.assertEqual(config_interface,
interface.type)
self.assertEqual('pre_configure_source',
interface.name)
self.assertEqual('nodejs/pre_configure_source.sh',
interface.implementation)
if rel_tpl:
interfaces = rel_tpl[0].interfaces
for interface in interfaces:
self.assertEqual(config_interface,
interface.type)
self.assertEqual('pre_configure_source',
interface.name)
self.assertEqual(artifact,
interface.implementation)
def test_template_macro(self):
template = ToscaTemplate(self.tosca_elk_tpl)

View File

@ -193,6 +193,17 @@ class TopologyTemplate(object):
for p, v in cap._properties.items():
if p == prop.name:
cap._properties[p] = propvalue
for rel, node in node_template.relationships.items():
rel_tpls = node.relationship_tpl
if rel_tpls:
for rel_tpl in rel_tpls:
for interface in rel_tpl.interfaces:
if interface.inputs:
for name, value in interface.inputs.items():
interface.inputs[name] = \
functions.get_function(self,
rel_tpl,
value)
for output in self.outputs:
func = functions.get_function(self, self.outputs, output.value)
if isinstance(func, functions.GetAttribute):