Commit ae0db377 authored by Spiros Koulouzis's avatar Spiros Koulouzis

removed policies

parent f77f926b
......@@ -28,17 +28,3 @@ topology_template:
file: alogo53/ws-pema-lifewatch
repository: docker_hub
#policies:
#- location:
#type: tosca.policies.ARTICONF.Requirement.Provider
#targets: [ ws-pema-lifewatch ]
#properties:
#accepted_providers:
#- ExoGENI
#- orchestrator:
#type: tosca.policies.ARTICONF.Requirement.docker.Orchestrator
#targets: [ ws-pema-lifewatch ]
#properties:
#accepted_orchestrator_types:
#- tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes
......@@ -39,24 +39,3 @@ policy_types:
type: integer
required: false
description: the minimum acceptable value
tosca.policies.ARTICONF.Requirement.Provider:
derived_from: tosca.policies.Root
description: defines cloud provider where vm topology can be deployed
properties:
accepted_providers:
type: list
description: list of the acceptable providers
schema_entry:
type: string
tosca.policies.ARTICONF.Requirement.docker.Orchestrator:
derived_from: tosca.policies.Root
description: defines type of docker.Orchestrator
properties:
accepted_orchestrator_types:
type: list
description: list of the acceptable orchestrator types e.g. tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes
schema_entry:
type: string
......@@ -10,6 +10,19 @@ from service.specification_analyzer import SpecificationAnalyzer
from util import tosca_helper
def get_defult_value(node_property):
if node_property and node_property.required and isinstance(node_property.value, dict) and 'required' in \
node_property.value and 'type' in node_property.value:
if node_property.default:
return {node_property.name: node_property.default}
if node_property.constraints:
for constraint in node_property.constraints:
print(constraint)
if node_property and node_property.required and node_property.value:
return {node_property.name: node_property.value}
return None
class SimpleAnalyzer(SpecificationAnalyzer):
def __init__(self, tosca_template):
......@@ -86,43 +99,18 @@ class SimpleAnalyzer(SpecificationAnalyzer):
return return_nodes
def set_node_specifications(self):
nodes_to_implement_policies = self.get_nodes_to_implement_policy()
affected_nodes = []
for node_name in nodes_to_implement_policies:
policies = nodes_to_implement_policies[node_name]
affected_node = self.set_specs(node_name, policies, self.tosca_template.nodetemplates)
if affected_node:
affected_nodes.append(affected_node)
return affected_nodes
def get_nodes_to_implement_policy(self):
nodes_to_implement_policies = {}
for policy in self.tosca_template.policies:
for target in policy.targets:
for leaf in self.leaf_nodes:
for affected_node_name in (nx.shortest_path(self.g, source=target, target=leaf)):
if affected_node_name not in nodes_to_implement_policies:
policy_list = []
nodes_to_implement_policies[affected_node_name] = policy_list
policy_list = nodes_to_implement_policies[affected_node_name]
policy_list.append(policy.type)
nodes_to_implement_policies[affected_node_name] = policy_list
return nodes_to_implement_policies
def set_node_properties_for_policy(self, affected_node, policies):
logging.info('Setting properties for: ' + str(affected_node.type))
nodes = []
for node_template in self.tosca_template.nodetemplates:
nodes.append(self.set_default_node_properties(node_template))
return nodes
# ancestors_types = tosca_helper.get_all_ancestors_types(affected_node, self.all_node_types, self.all_custom_def)
# if 'tosca.nodes.ARTICONF.docker.Orchestrator' in ancestors_types:
# logging.info('Do Something')
def set_default_node_properties(self, affected_node):
logging.info('Setting properties for: ' + str(affected_node.type))
ancestors_properties = tosca_helper.get_all_ancestors_properties(affected_node, self.all_node_types,
self.all_custom_def)
default_properties = {}
for ancestors_property in ancestors_properties:
default_property = self.get_defult_value(ancestors_property)
default_property = get_defult_value(ancestors_property)
if default_property:
default_properties[next(iter(default_property))] = default_property[next(iter(default_property))]
......@@ -138,35 +126,10 @@ class SimpleAnalyzer(SpecificationAnalyzer):
affected_node.templates[node_name]['properties'][prop_name]['required'] and \
'default' in affected_node.templates[node_name]['properties'][prop_name] and \
prop_name not in default_properties:
default_properties[prop_name] = affected_node.templates[node_name]['properties'][prop_name]['default']
default_properties[prop_name] = affected_node.templates[node_name]['properties'][prop_name][
'default']
logging.info('Adding to : ' + str(affected_node.templates[node_name])+ ' properties: '+str(default_properties))
logging.info(
'Adding to : ' + str(affected_node.templates[node_name]) + ' properties: ' + str(default_properties))
affected_node.templates[node_name]['properties'] = default_properties
return affected_node
else:
return None
def set_specs(self, node_name, policies, nodes_in_template):
logging.info('node_name: ' + str(node_name) + ' will implement policies: ' + str(len(policies)))
for node in nodes_in_template:
if node.name == node_name:
affected_node = node
break
logging.info('node: ' + str(affected_node.type) + ' will implement policies: ' + str(len(policies)))
affected_node = self.set_node_properties_for_policy(affected_node, policies)
return affected_node
def get_defult_value(self, node_property):
if node_property and node_property.required and isinstance(node_property.value, dict) and 'required' in \
node_property.value and 'type' in node_property.value:
if node_property.default:
return {node_property.name: node_property.default}
if node_property.constraints:
for constraint in node_property.constraints:
print(constraint)
if node_property and node_property.required and node_property.value:
return {node_property.name: node_property.value}
return None
......@@ -51,6 +51,9 @@ class SpecificationAnalyzer(metaclass=ABCMeta):
@abstractmethod
def set_node_specifications(self):
"""set the node_specifications
:rtype: list
"""
raise NotImplementedError('Must implement upload in subclasses')
@abstractmethod
......
......@@ -52,30 +52,30 @@ class MyTestCase(unittest.TestCase):
print("Output message:" + json.dumps(response))
self.assertEqual(True, True)
# def test_planner_policies(self):
# logger = logging.getLogger(__name__)
#
# input_tosca_file_path = get_tosca_files_path('lifeWatch_vre1.yaml')
#
# self.assertEqual(True, os.path.exists(input_tosca_file_path),
# "Input TOSCA file: " + input_tosca_file_path + " not found")
#
# conf = {'url': "http://host"}
# spec_service = SpecService(conf)
# test_planner = Planner(input_tosca_file_path, spec_service)
# test_tosca_template = test_planner.resolve_requirements()
# test_tosca_template = test_planner.set_infrastructure_specifications()
# template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary(test_tosca_template)
# logger.info("template ----: \n" + yaml.dump(template_dict))
# print(yaml.dump(template_dict))
# ToscaTemplate(yaml_dict_tpl=copy.deepcopy(template_dict))
#
# test_response = {'toscaTemplate': template_dict}
#
# response = {'toscaTemplate': template_dict}
# output_current_milli_time = int(round(time.time() * 1000))
# response["creationDate"] = output_current_milli_time
# response["parameters"] = []
# # print("Output message:" + json.dumps(response))
#
# self.assertEqual(True, True)
def test_planner_policies(self):
logger = logging.getLogger(__name__)
input_tosca_file_path = get_tosca_files_path('lifeWatch_vre1.yaml')
self.assertEqual(True, os.path.exists(input_tosca_file_path),
"Input TOSCA file: " + input_tosca_file_path + " not found")
conf = {'url': "http://host"}
spec_service = SpecService(conf)
test_planner = Planner(input_tosca_file_path, spec_service)
test_tosca_template = test_planner.resolve_requirements()
test_tosca_template = test_planner.set_infrastructure_specifications()
template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary(test_tosca_template)
logger.info("template ----: \n" + yaml.dump(template_dict))
print(yaml.dump(template_dict))
ToscaTemplate(yaml_dict_tpl=copy.deepcopy(template_dict))
test_response = {'toscaTemplate': template_dict}
response = {'toscaTemplate': template_dict}
output_current_milli_time = int(round(time.time() * 1000))
response["creationDate"] = output_current_milli_time
response["parameters"] = []
# print("Output message:" + json.dumps(response))
self.assertEqual(True, True)
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