Commit ab6a1a17 authored by Spiros Koulouzis's avatar Spiros Koulouzis

removed policies

parent ae0db377
...@@ -2,7 +2,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0 ...@@ -2,7 +2,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0
imports: imports:
- nodes: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/nodes.yaml - nodes: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/nodes.yaml
- data: https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/TOSCA/types/data.yml - data: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/data.yml
- capabilities: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/capabilities.yaml - capabilities: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/capabilities.yaml
- policies: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/policies.yaml - policies: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/policies.yaml
- interfaces: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/interfaces.yml - interfaces: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/interfaces.yml
......
tosca_definitions_version: tosca_simple_yaml_1_0 tosca_definitions_version: tosca_simple_yaml_1_0
description: TOSCA example
imports: imports:
- nodes: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/nodes.yaml - nodes: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/nodes.yaml
- data: https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/TOSCA/types/data.yml - data: https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/TOSCA/types/data.yml
- capabilities: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/capabilities.yaml - capabilities: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/capabilities.yaml
- policies: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/policies.yaml - policies: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/policies.yaml
- interfaces: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/interfaces.yml - interfaces: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/interfaces.yml
repositories: topology_template:
docker_hub: https://hub.docker.com/ node_templates:
description: >
TOSCA example
topology_template: #topology:
#interfaces:
#CloudsStorm:
#provision:
#inputs:
#code_type: SEQ
#object_type: SubTopology
#properties:
#domain: UvA (Amsterdam, The Netherlands) XO Rack
#provider: ExoGENI
#type: tosca.nodes.ARTICONF.VM.topology
node_templates:
ws-pema-lifewatch: ws-pema-lifewatch:
type: tosca.nodes.ARTICONF.Container.Application.Docker type: tosca.nodes.ARTICONF.Container.Application.Docker
properties: properties:
...@@ -27,4 +35,15 @@ topology_template: ...@@ -27,4 +35,15 @@ topology_template:
type: tosca.artifacts.Deployment.Image.Container.Docker type: tosca.artifacts.Deployment.Image.Container.Docker
file: alogo53/ws-pema-lifewatch file: alogo53/ws-pema-lifewatch
repository: docker_hub repository: docker_hub
requirements:
- host:
capability: tosca.capabilities.ARTICONF.docker.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
kubernetes:
type: tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes
properties:
min_masters_num: 1
min_workers_num: 1
...@@ -14,13 +14,13 @@ services: ...@@ -14,13 +14,13 @@ services:
- "4369:4369" - "4369:4369"
- "15671:15671" - "15671:15671"
planner: #planner:
depends_on: #depends_on:
- rabbit #- rabbit
- sure-tosca #- sure-tosca
image: alogo53/planner:3.0.0 #image: alogo53/planner:3.0.0
environment: #environment:
RABBITMQ_HOST: rabbit #RABBITMQ_HOST: rabbit
provisioner: provisioner:
depends_on: depends_on:
...@@ -52,17 +52,17 @@ services: ...@@ -52,17 +52,17 @@ services:
ports: ports:
- "30000:8080" - "30000:8080"
sure-tosca: #sure-tosca:
image: alogo53/sure-tosca:3.0.0 #image: alogo53/sure-tosca:3.0.0
ports:
- "8081:8081"
#logspout:
#ports: #ports:
#- "30002:80" #- "8081:8081"
#volumes:
#- /etc/hostname:/etc/host_hostname:ro logspout:
#- /var/run/docker.sock:/var/run/docker.sock ports:
#environment: - "30002:80"
#publish: "127.0.0.1:30002:80" volumes:
#image: gliderlabs/logspout:latest - /etc/hostname:/etc/host_hostname:ro
- /var/run/docker.sock:/var/run/docker.sock
environment:
publish: "127.0.0.1:30002:80"
image: gliderlabs/logspout:latest
...@@ -12,6 +12,33 @@ from service.simple_spec_alayzer import SimpleAnalyzer ...@@ -12,6 +12,33 @@ from service.simple_spec_alayzer import SimpleAnalyzer
from util import tosca_helper from util import tosca_helper
def add_requirements(node, missing_requirements, capable_node_name):
"""Add the requirements to the node """
for req in missing_requirements:
req[next(iter(req))]['node'] = capable_node_name
if isinstance(node, NodeTemplate):
contains_requirement = False
for node_requirement in node.requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node.requirements.append(req)
elif isinstance(node, dict):
type_name = next(iter(node))
if 'requirements' not in node[type_name]:
node[type_name]['requirements'] = []
node_requirements = node[type_name]['requirements']
contains_requirement = False
for node_requirement in node_requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node[type_name]['requirements'].append(req)
return node
class Planner: class Planner:
def __init__(self, tosca_path=None, yaml_dict_tpl=None, spec_service=None): def __init__(self, tosca_path=None, yaml_dict_tpl=None, spec_service=None):
...@@ -105,7 +132,7 @@ class Planner: ...@@ -105,7 +132,7 @@ class Planner:
matching_node_type_name = next(iter(matching_node)) matching_node_type_name = next(iter(matching_node))
matching_node_template = tosca_helper.node_type_2_node_template(matching_node, self.all_custom_def) matching_node_template = tosca_helper.node_type_2_node_template(matching_node, self.all_custom_def)
# Add the requirements to the node we analyzed. e.g. docker needed host now we added the type and name of host # Add the requirements to the node we analyzed. e.g. docker needed host now we added the type and name of host
node = self.add_requirements(node, all_requirements, matching_node_template.name) node = add_requirements(node, all_requirements, matching_node_template.name)
if not tosca_helper.contains_node_type(self.required_nodes, matching_node_type_name) and \ if not tosca_helper.contains_node_type(self.required_nodes, matching_node_type_name) and \
not tosca_helper.contains_node_type(self.tosca_template.nodetemplates, matching_node_type_name): not tosca_helper.contains_node_type(self.tosca_template.nodetemplates, matching_node_type_name):
logging.info(' Adding: ' + str(matching_node_template.name)) logging.info(' Adding: ' + str(matching_node_template.name))
...@@ -179,11 +206,15 @@ class Planner: ...@@ -179,11 +206,15 @@ class Planner:
def find_best_node_for_requirements(self, all_requirements): def find_best_node_for_requirements(self, all_requirements):
"""Returns the 'best' node for a set of requirements. Here we count the number of requiremets that the node """Returns the 'best' node for a set of requirements. Here we count the number of requiremets that the node
can cover and return the one which covers the most """ can cover and return the one which covers the most """
# Check if we have a preference from policies
matching_nodes = {} matching_nodes = {}
number_of_matching_requirement = {} number_of_matching_requirement = {}
for req in all_requirements:
if 'capability' in req[next(iter(req))]:
capability = req[next(iter(req))]['capability']
logging.info(' Looking for nodes with capability: ' + capability)
# Check if we already cover the requirements within the topology
capable_nodes = self.get_node_templates_by_capability(capability)
# Loop requirements to find nodes per requirement # Loop requirements to find nodes per requirement
for req in all_requirements: for req in all_requirements:
if 'capability' in req[next(iter(req))]: if 'capability' in req[next(iter(req))]:
...@@ -226,28 +257,9 @@ class Planner: ...@@ -226,28 +257,9 @@ class Planner:
child_nodes[tosca_node_type] = self.all_node_types[tosca_node_type] child_nodes[tosca_node_type] = self.all_node_types[tosca_node_type]
return child_nodes return child_nodes
def add_requirements(self, node, missing_requirements, capable_node_name): def get_node_templates_by_capability(self, capability):
"""Add the requirements to the node """ candidate_nodes = {}
for req in missing_requirements: for node in self.tosca_template.nodetemplates:
req[next(iter(req))]['node'] = capable_node_name if node.type.startswith('tosca.nodes'):
if isinstance(node, NodeTemplate): tosca_helper.get_all_ancestors_types()
contains_requirement = False return capable_nodes
for node_requirement in node.requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node.requirements.append(req)
elif isinstance(node, dict):
type_name = next(iter(node))
if 'requirements' not in node[type_name]:
node[type_name]['requirements'] = []
node_requirements = node[type_name]['requirements']
contains_requirement = False
for node_requirement in node_requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node[type_name]['requirements'].append(req)
return node
werkzeug==1.0.0
PyYAML PyYAML
wheel==0.33.6 wheel==0.34.2
connexion == 2.4.0 connexion==2.6.0
python-dateutil == 2.8.0 python-dateutil==2.8.1
typing == 3.7.4.1 typing==3.7.4.1
swagger-ui-bundle == 0.0.5 swagger-ui-bundle==0.0.6
tinydb == 3.15.1 # tinydb==3.15.1
tosca-parser ==1.6.1 tosca-parser ==1.7.0
...@@ -4,7 +4,7 @@ import sys ...@@ -4,7 +4,7 @@ import sys
from setuptools import setup, find_packages from setuptools import setup, find_packages
NAME = "sure_tosca" NAME = "sure_tosca"
VERSION = "1.0.0" VERSION = "1.2.0"
# To install the library, run the following # To install the library, run the following
# #
......
#!/usr/bin/env python #!/usr/bin/env python3
import connexion import connexion
......
from sure_tosca.models.node_template import NodeTemplateModel # noqa: E501
from sure_tosca.models.node_template_map import NodeTemplateMapModel # noqa: E501
from sure_tosca.models.tosca_template import ToscaTemplateModel # noqa: E501
def add_type_definition(definition_map):
return None
def get_types(query):
return None
\ No newline at end of file
...@@ -4,4 +4,4 @@ coverage==5.0.3 ...@@ -4,4 +4,4 @@ coverage==5.0.3
nose>=1.3.7 nose>=1.3.7
pluggy>=0.13.1 pluggy>=0.13.1
randomize>=0.14 randomize>=0.14
Werkzeug==0.16.1 werkzeug==1.0.0
\ No newline at end of file \ 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