Commit a910170f authored by Spiros Koulouzis's avatar Spiros Koulouzis

inherit capabilities with max occurrences 1

parent 80d57fd6
......@@ -33,7 +33,7 @@ node_types:
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: tosca.nodes.ARTICONF.Orchestrator
relationship: tosca.relationships.HostedOn
relationship: tosca.relationships.HostedOn
tosca.nodes.ARTICONF.Orchestrator:
derived_from: tosca.nodes.SoftwareComponent
......@@ -45,16 +45,31 @@ node_types:
relationship: tosca.relationships.HostedOn
capabilities:
host:
type: tosca.capabilities.ARTICONF.Orchestrator
type: tosca.capabilities.ARTICONF.Orchestrator
occurrences: [1, 1]
cap:
type: tosca.capabilities.ROOT
occurrences: [1, 1]
tosca.nodes.ARTICONF.Orchestrator.Kubernetes:
derived_from: tosca.nodes.ARTICONF.Orchestrator
description: Kubernetes orchestrator
capabilities:
cap_1:
type: tosca.capabilities.ROOT
occurrences: [1, 100]
requirements:
- host:
capability: tosca.capabilities.Scalable
node: tosca.nodes.Compute
relationship: tosca.relationships.HostedOn
relationship: tosca.relationships.HostedOn
interfaces:
Standard:
configure:
implementation: playbooks/kubernetes_install.yaml
inputs:
kubernetes_master_ip: { get_property: [ SELF, kubernetes_master_ip ] }
kubernetes_worker_ips: { get_property: [ SELF, kubernetes_worker_ips] }
......@@ -32,7 +32,7 @@ class BasicPlanner:
for key in req:
capable_nodes.append(self.get_node_types_by_capability(req[key]['capability']))
node.requirements.append(req)
# print((node.type_definition._get_node_type_by_cap('tosca.capabilities.ARTICONF.Orchestrator')))
print(capable_nodes)
print('------------------')
# print(node.get_capabilities().keys)
......@@ -59,10 +59,49 @@ class BasicPlanner:
def get_node_types_by_capability(self,cap):
capable_nodes = []
for tosca_node in self.all_nodes:
if 'capabilities' in self.all_nodes[tosca_node]:
for caps in self.all_nodes[tosca_node]['capabilities']:
if self.all_nodes[tosca_node]['capabilities'][caps]['type'] == cap:
capable_nodes.append(tosca_node)
return capable_nodes
\ No newline at end of file
candidate_nodes = {}
for tosca_node_type in self.all_nodes:
if tosca_node_type.startswith('tosca.nodes') and 'capabilities' in self.all_nodes[tosca_node_type]:
for caps in self.all_nodes[tosca_node_type]['capabilities']:
if self.all_nodes[tosca_node_type]['capabilities'][caps]['type'] == cap:
candidate_nodes[tosca_node_type] = self.all_nodes[tosca_node_type]
candidate_child_nodes = {}
for tosca_node_type in self.all_nodes:
if tosca_node_type.startswith('tosca.nodes') and 'derived_from' in self.all_nodes[tosca_node_type]:
candidate_child_node = (self.all_nodes[tosca_node_type])
for candidate_node_name in candidate_nodes:
if candidate_child_node['derived_from'] == candidate_node_name:
candidate_child_nodes[tosca_node_type] = self.all_nodes[tosca_node_type]
candidate_child_nodes[tosca_node_type] = self.inherit_capabilities_with_one_occurrences(candidate_nodes[candidate_node_name]['capabilities'],candidate_child_node)
candidate_nodes.update(candidate_child_nodes)
capable_nodes = {}
for candidate_node_name in candidate_nodes:
if 'interfaces' in candidate_nodes[candidate_node_name].keys():
capable_nodes[candidate_node_name] = candidate_nodes[candidate_node_name]
return capable_nodes
def inherit_capabilities_with_one_occurrences(self,parent_capabilities,candidate_child_node):
inherited_capabilities = []
if not 'capabilities' in candidate_child_node.keys():
candidate_child_node['capabilities'] = {}
for capability in parent_capabilities:
inherited_capability = parent_capabilities[capability]
if 'occurrences' in inherited_capability and inherited_capability['occurrences'][1] == 1:
inherited_capabilities.append(parent_capabilities)
for key in parent_capabilities:
candidate_child_node['capabilities'][key] = parent_capabilities[key]
# candidate_child_node['capabilities'][key] = inherited_capability[key]
# print(inherited_capability)
# for inherited_capability in inherited_capabilities:
# for key in inherited_capability:
# candidate_child_node['capabilities'][key] = inherited_capability[key]
return candidate_child_node
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment