Commit 37e7927d authored by Spiros Koulouzis's avatar Spiros Koulouzis

try to generate NodeTemplate from NodeType dictionary

parent 968191a4
...@@ -68,8 +68,5 @@ node_types: ...@@ -68,8 +68,5 @@ node_types:
Standard: Standard:
configure: configure:
implementation: playbooks/kubernetes_install.yaml implementation: playbooks/kubernetes_install.yaml
inputs:
kubernetes_master_ip: { get_property: [ SELF, kubernetes_master_ip ] }
kubernetes_worker_ips: { get_property: [ SELF, kubernetes_worker_ips] }
...@@ -6,11 +6,12 @@ from toscaparser.tosca_template import ToscaTemplate ...@@ -6,11 +6,12 @@ from toscaparser.tosca_template import ToscaTemplate
from toscaparser.topology_template import TopologyTemplate from toscaparser.topology_template import TopologyTemplate
from toscaparser.elements.nodetype import NodeType from toscaparser.elements.nodetype import NodeType
from toscaparser.nodetemplate import NodeTemplate from toscaparser.nodetemplate import NodeTemplate
import toscaparser.utils.yamlparser from toscaparser.utils import yamlparser
import urllib import urllib
import urllib.parse import urllib.parse
import sys import sys
import pdb import pdb
import names
...@@ -26,36 +27,44 @@ class BasicPlanner: ...@@ -26,36 +27,44 @@ class BasicPlanner:
self.all_nodes.update(self.all_custom_def.items()) self.all_nodes.update(self.all_custom_def.items())
capable_node_types = [] capable_node_types = []
node_templates = []
for node in self.template.nodetemplates: for node in self.template.nodetemplates:
missing_requirements = self.get_missing_requirements(node) missing_requirements = self.get_missing_requirements(node)
for req in missing_requirements: for req in missing_requirements:
for key in req: for key in req:
capable_nodes = self.get_node_types_by_capability(req[key]['capability']) capable_nodes = self.get_node_types_by_capability(req[key]['capability'])
capable_node_types.append(capable_nodes)
for node_type in capable_nodes: for node_type in capable_nodes:
capable_node = capable_nodes[node_type] capable_node = capable_nodes[node_type]
for cap in capable_node['capabilities']: for cap in capable_node['capabilities']:
capability_type = capable_node['capabilities'][cap]['type'] capability_type = capable_node['capabilities'][cap]['type']
if capability_type == req[key]['capability'] and self.has_capability_max_one_occurrence(capable_node['capabilities'][cap]): if capability_type == req[key]['capability'] and self.has_capability_max_one_occurrence(capable_node['capabilities'][cap]) and not self.contains_node_type(capable_node_types,node_type):
for capable_node_type in capable_node_types: capable_node_types.append(capable_nodes)
print(capable_node_type) break
elif capability_type == req[key]['capability'] and not self.has_capability_max_one_occurrence(capable_node['capabilities'][cap]):
# print(req[key]['capability']) capable_node_types.append(capable_nodes)
# print(capable_nodes[node_type]['capabilities']) break
# if self.has_capability_max_one_occurrence(capable_nodes[node_type]['capabilities']):
# capable_nodes_dict[node_type] = capable_nodes[node_type]
# for capable_node in capable_nodes:
# print(capable_node)
# capable_nodes.append(capable_nodes)
node.requirements.append(req) node.requirements.append(req)
# print(node.requirements) node_templates.append(node)
# print(capable_node_types)
for node_type in capable_nodes:
capable_node = capable_nodes[node_type]
nodetemplate = {}
nodetemplate[names.get_first_name().lower()] = node_type
print(nodetemplate)
self.template.nodetemplates = node_templates
tpl_snippet = '''
server:
type: tosca.my.nodes.Compute
properties:
cpu_frequency: 0.05 GHz
disk_size: 500 MB
mem_size: 1 MB
'''
nodetemplates = yamlparser.simple_parse(tpl_snippet)
# print(type(nodetemplates))
# nodetemplate = NodeTemplate('server', nodetemplates)
print('------------------') print('------------------')
# print(node.get_capabilities().keys) # print(node.get_capabilities().keys)
...@@ -119,15 +128,6 @@ class BasicPlanner: ...@@ -119,15 +128,6 @@ class BasicPlanner:
inherited_capabilities.append(parent_capabilities) inherited_capabilities.append(parent_capabilities)
for key in parent_capabilities: for key in parent_capabilities:
candidate_child_node['capabilities'][key] = parent_capabilities[key] 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 return candidate_child_node
...@@ -136,3 +136,11 @@ class BasicPlanner: ...@@ -136,3 +136,11 @@ class BasicPlanner:
return True return True
else: else:
return False return False
def contains_node_type(self,capable_node_types_list,node_type):
for capable_node_type in capable_node_types_list:
type_name = next(iter(capable_node_type))
if type_name == node_type:
return True
return False
\ 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