Commit 1e62a63b authored by Spiros Koulouzis's avatar Spiros Koulouzis

moved some properties to attributes

new tosca example file 
parent e9c010de
tosca_definitions_version: tosca_simple_yaml_1_0
description: TOSCA example
imports:
- nodes: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/nodes.yaml
- capabilities: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/capabilities.yaml
- policies: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/policies.yaml
- interfaces: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/interfaces.yml
repositories:
docker_hub: https://hub.docker.com/
topology_template:
node_templates:
compute:
interfaces:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
host_name: vm
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
role: master
user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute
compute_1:
interfaces:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
host_name: vm
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
role: worker
user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute
compute_2:
interfaces:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
host_name: vm
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
role: worker
user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute
kubernetes:
interfaces:
Standard:
create: interfaces/playbooks/kubernetes_install.yaml
requirements:
- host:
capability: tosca.capabilities.ARTICONF.VM.topology
node: topology
relationship: tosca.relationships.HostedOn
- host:
capability: tosca.capabilities.ARTICONF.VM.topology
node: topology_1
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Orchestrator.Kubernetes
mysql:
artifacts:
image:
file: mysql:5.7
repository: docker_hub
type: tosca.artifacts.Deployment.Image.Container.Docker
properties:
environment:
MYSQL_DATABASE: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_USER: wordpress
ports:
- 3306:3306
volumes:
- db_data:/var/lib/mysql
requirements:
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker
topology:
interfaces:
Standard:
create: dumy.yaml
properties:
domain: UvA (Amsterdam, The Netherlands) XO Rack
provider: ExoGeni
requirements:
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute
relationship: tosca.relationships.DependsOn
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute_1
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
topology:
interfaces:
Standard:
create: dumy.yaml
properties:
domain: Some other Rack
provider: ExoGeni
requirements:
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute_2
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
wordpress:
artifacts:
image:
file: wordpress:latest
repository: docker_hub
type: tosca.artifacts.Deployment.Image.Container.Docker
properties:
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_USER: wordpress
ports:
- 8000:80
requirements:
- service:
node: mysql
relationship:
type: tosca.relationships.DependsOn
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker
policies:
- scalability:
properties:
fault_tolerance_level: 0
targets:
- mysql
type: tosca.policies.ARTICONF.FaultTolerance
outputs:
private_ip_compute:
description: The private IP address of the application’s first tier.
value: { get_attribute: [compute, private_address] }
private_ip_compute_1:
description: The private IP address of the application’s second tier.
value: { get_attribute: [compute_1, private_address] }
private_ip_compute_2:
description: The private IP address of the application’s second tier.
value: { get_attribute: [compute_2, private_address] }
......@@ -11,13 +11,59 @@ topology_template:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
host_name: vm
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
role: master
user_name: vm_user
cpu_frequency:
constraints:
- greater_or_equal: 0.5 GHz
required: false
type: scalar-unit.frequency
disk_size:
constraints:
- greater_or_equal: 15000 MB
default: 50000 MB
required: true
type: scalar-unit.size
host_name:
default: vm
required: true
type: string
mem_size:
constraints:
- greater_or_equal: 500 MB
default: 6000 MB
required: true
type: scalar-unit.size
node_type:
description: the type of VM depending on the provider. e.g. XOSmall, t.medium
etc. It has to match the mem_size, num_cores etc.
required: false
type: string
num_cores:
constraints:
- greater_or_equal: 1
default: 2
required: true
type: integer
os:
default: ubuntu 16
required: true
type: string
private_ip:
description: The private IP of the VM e.g. 192.168.10.10
required: false
type: string
role:
constraints:
- valid_values:
- master
- worker
default: master
description: the role of the VM in the topology
required: true
type: string
user_name:
default: vm_user
required: true
type: string
type: tosca.nodes.ARTICONF.VM.Compute
compute_1:
interfaces:
......@@ -32,7 +78,7 @@ topology_template:
role: worker
user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute
compute_3:
compute_2:
interfaces:
Standard:
create: dumy.yaml
......@@ -44,7 +90,7 @@ topology_template:
os: ubuntu 16
role: worker
user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute
type: tosca.nodes.ARTICONF.VM.Compute
kubernetes:
interfaces:
Standard:
......@@ -54,10 +100,6 @@ topology_template:
capability: tosca.capabilities.ARTICONF.VM.topology
node: topology
relationship: tosca.relationships.HostedOn
- host:
capability: tosca.capabilities.ARTICONF.VM.topology
node: topology_1
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Orchestrator.Kubernetes
mysql:
artifacts:
......@@ -86,31 +128,50 @@ topology_template:
Standard:
create: dumy.yaml
properties:
domain: UvA (Amsterdam, The Netherlands) XO Rack
provider: ExoGeni
credential:
required: false
type: tosca.datatypes.Credential
domain:
default: UvA (Amsterdam, The Netherlands) XO Rack
description: the domain of this topology e.g. California, UvA, etc
required: true
type: string
name:
description: the name of this topology
required: false
type: string
provider:
default: ExoGeni
description: The name of the provider e.g. EC2, ExoGeni etc.
required: true
type: string
subnet:
description: The subnet of the VMs this topology e.g. 192.168.10.10/24
required: false
type: string
requirements:
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute
relationship: tosca.relationships.DependsOn
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute_1
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
topology_1:
interfaces:
Standard:
create: dumy.yaml
properties:
domain: NICTA (Sydney, Australia) XO Rack
domain: Some other Rack
provider: ExoGeni
requirements:
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute_3
node: compute_2
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
wordpress:
artifacts:
image:
......
......@@ -11,6 +11,15 @@ repositories:
description: >
TOSCA example
interface_types:
tosca.interfaces.TEST.test:
description: test
derived_from: tosca.interfaces.node.lifecycle.Standard
create:
description: creates
configure:
description: configures
topology_template:
......
......@@ -50,7 +50,7 @@ node_types:
type: tosca.capabilities.Container.Docker
container:
type: tosca.capabilities.Container
properties:
attributes:
masters_num:
type: integer
required: true
......@@ -94,27 +94,28 @@ node_types:
topology:
type: tosca.capabilities.ARTICONF.VM.topology
properties:
provider:
type: string
required: true
default: "ExoGeni"
description: The name of the provider e.g. EC2, ExoGeni etc.
name:
type: string
required: false
description: the name of this topology
subnet:
type: string
required: false
description: The subnet of the VMs this topology e.g. 192.168.10.10/24
attributes:
domain:
type: string
required: true
default: "UvA (Amsterdam, The Netherlands) XO Rack"
description: the domain of this topology e.g. California, UvA, etc
description: the domain of this topology e.g. California, UvA, etc
credential:
type: tosca.datatypes.Credential
required: false
subnet:
required: false
provider:
type: string
required: false
description: The subnet of the VMs this topology e.g. 192.168.10.10/24
required: true
default: "ExoGeni"
description: The name of the provider e.g. EC2, ExoGeni etc.
interfaces:
Standard:
create: dumy.yaml
......@@ -126,14 +127,6 @@ node_types:
compute:
type: tosca.capabilities.ARTICONF.VM
properties:
user_name:
type: string
required: true
default: "vm_user"
host_name:
type: string
required: true
default: "vm"
num_cores:
type: integer
required: true
......@@ -161,22 +154,35 @@ node_types:
type: string
required: true
default: "ubuntu 16"
# outputs for this node
attributes:
private_ip:
type: string
required: false
description: The private IP of the VM e.g. 192.168.10.10
public_ip:
type: string
required: false
description: The public IP
role:
type: string
required: true
description: the role of the VM in the topology
default: "master"
constraints:
- valid_values: [ "master","worker" ]
private_ip:
type: string
required: false
description: The private IP of the VM e.g. 192.168.10.10
- valid_values: [ "master","worker" ]
node_type:
type: string
required: false
description: the type of VM depending on the provider. e.g. XOSmall, t.medium etc. It has to match the mem_size, num_cores etc.
description: the type of VM depending on the provider. e.g. XOSmall, t.medium etc. It has to match the mem_size, num_cores etc.
user_name:
type: string
required: true
default: "vm_user"
host_name:
type: string
required: true
default: "vm"
interfaces:
Standard:
create: dumy.yaml
......
......@@ -2,28 +2,18 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../TOSCA/application_example_output.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example_output.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../TOSCA/application_example_updated.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example_updated.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/requirements.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/controllers/default_controller.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/controllers/default_controller.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/base_model_.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/base_model_.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/node_template.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/node_template.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/topology_template.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/topology_template.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/tosca_template.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/models/tosca_template.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/swagger/swagger.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/swagger/swagger.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/chardetect" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/chardetect" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/connexion" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/connexion" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/flask" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/flask" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/jsonschema" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/jsonschema" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/openapi-spec-validator" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/openapi-spec-validator" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/pbr" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/pbr" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/pybabel" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/pybabel" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/tosca-parser" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/bin/tosca-parser" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/attr/converters.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/attr/converters.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/attr/filters.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/attr/filters.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/find_package.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/find_package.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/pbr_json.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/pbr_json.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/tests/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/tests/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/tests/testpackage/pbr_testpackage/wsgi.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/venv/lib/python3.6/site-packages/pbr/tests/testpackage/pbr_testpackage/wsgi.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/test/test_default_controller.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/test/test_default_controller.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -113,7 +103,7 @@
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/rpc_server.py" />
<option name="PARAMETERS" value="localhost planner" />
<option name="PARAMETERS" value="test_local" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
......@@ -302,7 +292,14 @@
<option name="project" value="LOCAL" />
<updated>1571760668434</updated>
</task>
<option name="localTasksCounter" value="19" />
<task id="LOCAL-00019" summary="we have a bug with setting default properties">
<created>1572451502431</created>
<option name="number" value="00019" />
<option name="presentableId" value="LOCAL-00019" />
<option name="project" value="LOCAL" />
<updated>1572451502431</updated>
</task>
<option name="localTasksCounter" value="20" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -336,7 +333,8 @@
<MESSAGE value="fixed policies error" />
<MESSAGE value="added test" />
<MESSAGE value="check if topology node has properties" />
<option name="LAST_COMMIT_MESSAGE" value="check if topology node has properties" />
<MESSAGE value="we have a bug with setting default properties" />
<option name="LAST_COMMIT_MESSAGE" value="we have a bug with setting default properties" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
......@@ -348,13 +346,13 @@
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/rpc_server.py</url>
<line>106</line>
<line>105</line>
<option name="timeStamp" value="302" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/rpc_server.py</url>
<line>138</line>
<option name="timeStamp" value="305" />
<url>file://$PROJECT_DIR$/venv/lib/python3.6/site-packages/toscaparser/elements/scalarunit.py</url>
<line>71</line>
<option name="timeStamp" value="311" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
......
This diff is collapsed.
......@@ -64,12 +64,3 @@ class Model(object):
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
# def __hash__(self):
# return hash(self.__dict__.keys())
def __key(self):
return tuple(sorted(self.to_dict()))
def __hash__(self):
return hash(self.__key())
\ No newline at end of file
......@@ -15,8 +15,7 @@ class NodeTemplate(Model):
Do not edit the class manually.
"""
def __init__(self, derived_from=None, properties=None, requirements=None, interfaces=None, capabilities=None,
type=None, description=None, directives=None, attributes=None, artifacts=None): # noqa: E501
def __init__(self, derived_from=None, properties=None, requirements=None, interfaces=None, capabilities=None, type=None, description=None, directives=None, attributes=None, artifacts=None): # noqa: E501
"""NodeTemplate - a model defined in Swagger
:param derived_from: The derived_from of this NodeTemplate. # noqa: E501
......
......@@ -245,8 +245,3 @@ class TopologyTemplate(Model):
"""
self._policies = policies
def __eq__(self, other):
if isinstance(other, TopologyTemplate):
return self.__key() == other.__key()
return NotImplemented
\ No newline at end of file
......@@ -16,11 +16,7 @@ class ToscaTemplate(Model):
Do not edit the class manually.
"""
def __init__(self, tosca_definitions_version=None, tosca_default_namespace=None, template_name=None,
topology_template=None, template_author=None, template_version=None, description=None, imports=None,
dsl_definitions=None, node_types=None, relationship_types=None, relationship_templates=None,
capability_types=None, artifact_types=None, data_types=None, interface_types=None, policy_types=None,
group_types=None, repositories=None): # noqa: E501
def __init__(self, tosca_definitions_version=None, tosca_default_namespace=None, template_name=None, topology_template=None, template_author=None, template_version=None, description=None, imports=None, dsl_definitions=None, node_types=None, relationship_types=None, relationship_templates=None, capability_types=None, artifact_types=None, data_types=None, interface_types=None, policy_types=None, group_types=None, repositories=None): # noqa: E501
"""ToscaTemplate - a model defined in Swagger
:param tosca_definitions_version: The tosca_definitions_version of this ToscaTemplate. # noqa: E501
......@@ -535,8 +531,3 @@ class ToscaTemplate(Model):
"""
self._repositories = repositories
def __eq__(self, other):
if isinstance(other, ToscaTemplate):
return self.__key() == other.__key()
return NotImplemented
import os
import uuid
import connexion
import six
import yaml
from tinydb.middlewares import CachingMiddleware
from typing import re
from sure_tosca.models.node_template import NodeTemplate as NodeTemplateModel
from sure_tosca.models.topology_template import TopologyTemplate as TopologyTemplateModel
......@@ -16,29 +15,47 @@ from toscaparser.nodetemplate import NodeTemplate
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.topology_template import TopologyTemplate
from tinydb.storages import MemoryStorage
from operator import and_, or_
from functools import reduce
from tinydb import where
from sure_tosca.service import tosca_helper
# db = TinyDB(storage=CachingMiddleware(MemoryStorage))
db_dir_path = tempfile.gettempdir()
tosca_templates_db_file_path = os.path.join(db_dir_path, "tosca_templates.json")
tosca_templates_db = TinyDB(tosca_templates_db_file_path, cache_size=30)
tosca_templates_db = TinyDB(tosca_templates_db_file_path)
# tosca_templates_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
node_templates_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
tmp_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
# interface_types_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
model_id_names = ['id']
root_key = 'root_key'
def query_tmp_db(queries):
if queries:
query = reduce(lambda a, b: a & b, queries)
results = tmp_db.search(query)
else:
results = tmp_db.all()
if results:
updated_results = []
for res in results:
key = res.pop(root_key)
node = {key: res}
updated_results.append(node)
return updated_results
return 'Not Found', 404
def get_tosca_template_model_by_id(id):
tosca_template_dict = get_tosca_template_dict_by_id(id)
if tosca_template_dict:
get_tosca_template_by_id(tosca_template_dict)
get_tosca_template(tosca_template_dict)
return ToscaTemplateModel.from_dict(tosca_template_dict)
return 'Not Found', 404
def get_tosca_template_by_id(tosca_template_dict):
def get_tosca_template(tosca_template_dict):
return ToscaTemplate(yaml_dict_tpl=tosca_template_dict)
......@@ -72,49 +89,153 @@ def save(file):
def get_interface_types(id, interface_type=None):
interface_types = get_tosca_template_model_by_id(id).interface_types
tmp_db.purge()
if interface_types:
if interface_type:
filtered_interface_types = []
for interface in interface_types:
type_name = next(iter(interface))
if type_name == interface_type:
filtered_interface_types.append({type_name: interface})
return filtered_interface_types
return 'Not Found', 404
def get_node_templates(id, name=None, node_type=None, has_interface=None):
node_templates_db.purge()
node_templates = get_tosca_template_model_by_id(id).topology_template.node_templates
if node_templates:
for node_template_name in node_templates:
node = {'name': node_template_name}
node.update(node_templates[node_template_name].to_dict())
node_templates_db.insert(node)
for interface_type_name in interface_types:
interface = {root_key: interface_type_name}
interface.update(interface_types[interface_type_name])
queries = []
if interface_type:
query = Query()
queries.append(query._name_key == interface_type)
return query_tmp_db(queries)
def get_node_templates(id, type_name=None, name_key=None, has_interfaces=None, has_properties=None, has_attributes=None,
has_requirements=None, has_capabilities=None, has_artifacts=None, derived_from=None):
tmp_db.purge()
object_list = get_tosca_template_model_by_id(id).topology_template.node_templates
if object_list:
for key in object_list:
node = {root_key: key}
node.update(object_list[key].to_dict())
tmp_db.insert(node)
queries = []
if name:
if name_key:
query = Query()
queries.append(query.root_key == name_key)
if type_name:
query = Query()
queries.append(query.type == type_name)
if derived_from:
query = Query()
queries.append(query.derived_from == derived_from)
if has_properties:
query = Query()
prop = None
queries.append(query.properties != prop)
if has_interfaces:
query = Query()
prop = None
queries.append(query.interfaces != prop)
if has_attributes:
query = Query()
queries.append(query.name == name)
if node_type:
prop = None
queries.append(query.attributes != prop)
if has_requirements:
query = Query()
queries.append(query.type == node_type)
if has_interface:
prop = None
queries.append(query.requirements != prop)
if has_capabilities:
query = Query()
prop = None
queries.append(query.capabilities != prop)
if has_artifacts:
query = Query()
prop = None
queries.append(query.artifacts != prop)
query_results = query_tmp_db(queries)
return query_results
def get_tosca_template_get_dsl_definitions(id, anchors, derived_from):
tmp_db.purge()
object_list = get_tosca_template_model_by_id(id).dsl_definitions
if object_list:
for key in object_list:
node = {key: object_list[key]}
tmp_db.insert(node)
queries = []
if derived_from:
query = Query()
queries.append(query.derived_from == derived_from)
if anchors:
for anchor in anchors:
query = Query()
interface = None
queries.append(query.interfaces != interface)
query = reduce(lambda a, b: a & b, queries)
query_results = node_templates_db.search(query)
if not query_results:
return 'Not Found', 404
results = []
for res in query_results:
name = res.pop('name')
node = {name: res}
if has_interface and 'interfaces' in res and res['interfaces'] is not None:
results.append(node)
elif not has_interface:
results.append(node)
return results
return 'Not Found', 404
return query_tmp_db(queries)
def get_relationship_templates(id, type_name, derived_from):
tmp_db.purge()
object_list = get_tosca_template_model_by_id(id).relationship_templates
if object_list:
for key in object_list:
node = {key: object_list[key]}
tmp_db.insert(node)
queries = []
if derived_from:
query = Query()
queries.append(query.derived_from == derived_from)
if type_name:
query = Query()
queries.append(query.type == type_name)
return query_tmp_db(queries)
def find_node_template(id, node_root_key):
tosca_template_dict = get_tosca_template_dict_by_id(id)
tosca_template = get_tosca_template(tosca_template_dict)
tosca_node_types = tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
all_custom_def = tosca_template.nodetemplates[0].custom_def
all_node_types = {}
all_node_types.update(tosca_node_types.items())
all_node_types.update(all_custom_def.items())
the_node = None
for node in tosca_template.nodetemplates:
if node.name == node_root_key:
the_node = node
break
if not the_node:
template = all_node_types[node_root_key]
the_node = tosca_helper.node_type_2_node_template({node_root_key: template}, all_custom_def)
return the_node, all_node_types, all_custom_def
def get_all_ancestors_requirements(id, node_root_key):
the_node, all_node_types, all_custom_def = find_node_template(id, node_root_key)
parent_requirements = tosca_helper.get_all_ancestors_requirements(the_node, all_node_types, all_custom_def)
return parent_requirements
def get_all_ancestor_properties(id, node_root_key):
the_node, all_node_types, all_custom_def = find_node_template(id, node_root_key)
properties = tosca_helper.get_all_ancestors_properties(the_node, all_node_types, all_custom_def)
properties_list = []
for prop in properties:
prop_dict = {prop.name: prop.value}
properties_list.append(prop_dict)
return properties_list
def get_all_ancestor_types(id, node_root_key):
the_node, all_node_types, all_custom_def = find_node_template(id, node_root_key)
all_ancestor_types = tosca_helper.get_all_ancestors_types(the_node, all_node_types, all_custom_def)
return all_ancestor_types
def get_parent_type_name(id, node_root_key):
the_node, all_node_types, all_custom_def = find_node_template(id, node_root_key)
return tosca_helper.get_parent_type(the_node)
def get_node_outputs(id, name_key):
outputs = get_tosca_template_model_by_id(id).topology_template.outputs
return None
\ 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