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
......@@ -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,29 +128,48 @@ 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
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
wordpress:
......
......@@ -12,6 +12,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:
node_templates:
......
......@@ -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,15 +94,15 @@ 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
......@@ -111,10 +111,11 @@ node_types:
credential:
type: tosca.datatypes.Credential
required: false
subnet:
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,6 +154,16 @@ 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
......@@ -168,15 +171,18 @@ node_types:
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
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.
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>
......
import copy
from itertools import chain
from toscaparser import tosca_template
from toscaparser.elements.nodetype import NodeType
from toscaparser.nodetemplate import NodeTemplate
import yaml
import logging
# TOSCA template key names
SECTIONS = (DEFINITION_VERSION, DEFAULT_NAMESPACE, TEMPLATE_NAME,
TOPOLOGY_TEMPLATE, TEMPLATE_AUTHOR, TEMPLATE_VERSION,
DESCRIPTION, IMPORTS, DSL_DEFINITIONS, NODE_TYPES,
RELATIONSHIP_TYPES, RELATIONSHIP_TEMPLATES,
CAPABILITY_TYPES, ARTIFACT_TYPES, DATA_TYPES, INTERFACE_TYPES,
POLICY_TYPES, GROUP_TYPES, REPOSITORIES, INPUTS, NODE_TEMPLATES,
OUTPUTS, GROUPS, SUBSTITUION_MAPPINGS, POLICIES, TYPE, REQUIREMENTS,
ARTIFACTS, PROPERTIES, INTERFACES) = \
('tosca_definitions_version', 'tosca_default_namespace',
'template_name', 'tosca_template', 'template_author',
'template_version', 'description', 'imports', 'dsl_definitions',
'node_types', 'relationship_types', 'relationship_templates',
'capability_types', 'artifact_types', 'data_types',
'interface_types', 'policy_types', 'group_types', 'repositories',
'inputs', 'node_templates', 'outputs', 'groups', 'substitution_mappings',
'policies', 'type', 'requirements', 'artifacts', 'properties', 'interfaces')
node_type_key_names_to_remove = ['capabilities', 'derived_from']
def get_node_type_name(node):
"""Returns the node's type name as string"""
if isinstance(node, NodeTemplate):
if node.type:
if node.type and isinstance(node.type, str):
node_type = node.type
elif isinstance(node.type, NodeTemplate):
node_type = node.type.type
else:
node_type = None
elif isinstance(node, dict):
node_type = next(iter(node))
return node_type
def get_node_requirements(node):
if isinstance(node, NodeTemplate):
node_requirements = node.requirements
elif isinstance(node, dict):
node_type_name = get_node_type_name(node)
if 'requirements' not in node[node_type_name]:
node[node_type_name]['requirements'] = {}
node_requirements = node[node_type_name]['requirements']
return node_requirements
def get_parent_type(node):
if isinstance(node, NodeTemplate):
if node.parent_type:
parent_type = node.parent_type.type
else:
parent_type = None
elif isinstance(node, dict):
parent_type = node[next(iter(node))]['derived_from']
return parent_type
def get_node_type_requirements(type_name, all_nodes):
"""Returns the requirements for an input node as described in the template not in the node's definition """
def_type = all_nodes[type_name]
if 'requirements' in def_type.keys():
return def_type['requirements']
return None
def get_ancestors_requirements(node, all_nodes, all_custom_def, parent_requirements=None):
"""Recursively get all requirements all the way to the ROOT including the input node's"""
if not parent_requirements:
parent_requirements = []
if isinstance(node, NodeTemplate):
# If node has parent and parent has requirements add them
if node.parent_type and node.parent_type.requirements:
if isinstance(node.parent_type.requirements, dict):
parent_requirements.append(node.parent_type.requirements)
elif isinstance(node.parent_type.requirements, list):
parent_requirements.extend(node.parent_type.requirements)
# Make parent type to NodeTemplate to continue
if node.parent_type.type:
parent_template = node_type_2_node_template({'name': all_nodes[node.parent_type.type]}, all_custom_def)
if parent_template:
get_ancestors_requirements(parent_template, all_nodes, parent_requirements)
elif isinstance(node, dict):
node_type_name = get_node_type_name(node)
node_template = node_type_2_node_template({'name': all_nodes[node_type_name]}, all_custom_def)
return get_ancestors_requirements(node_template, all_nodes, all_custom_def, parent_requirements)
return parent_requirements
def get_node_types_with_interface(nodes):
node_types_with_interface = []
for node_name in nodes:
if 'interfaces' in nodes[node_name].keys() and 'tosca.nodes.Root' != node_name:
node_types_with_interface.append(node_name)
return node_types_with_interface
def node_type_2_node_template(node_type, all_custom_def):
node_template_dict = {}
type_name = next(iter(node_type))
node_type_array = type_name.split(".")
name = node_type_array[len(node_type_array) - 1].lower()
node_template_dict[name] = node_type[next(iter(node_type))].copy()
node_template_dict[name]['type'] = type_name
for name_to_remove in node_type_key_names_to_remove:
if name_to_remove in node_template_dict[name]:
node_template_dict[name].pop(name_to_remove)
if 'type' in node_type[next(iter(node_type))]:
node_type[next(iter(node_type))].pop('type')
node_template = NodeTemplate(name, node_template_dict, node_type)
# For some reason the tosca.nodes.ARTICONF.Orchestrator doesn't have all definitions so we need to add them
# manually. We get 'toscaparser.common.exception.InvalidTypeError: Type "tosca.nodes.ARTICONF.Orchestrator"
# is not a valid type.'
if len(node_template.custom_def) < len(all_custom_def):
for def_key in all_custom_def:
if isinstance(def_key, dict):
node_template.custom_def.update(def_key)
else:
node_template.custom_def[def_key] = all_custom_def[def_key]
return node_template
def get_tosca_template_2_topology_template_dictionary(template):
yaml_str = tosca_template2_yaml(template)
tosca_template_dict = yaml.load(yaml_str, Loader=yaml.FullLoader)
this_tosca_template = tosca_template_dict['tosca_template']
tosca_template_dict.pop('tosca_template')
tosca_template_dict['topology_template'] = this_tosca_template
if template.policies and 'policies' not in tosca_template_dict['topology_template']:
policies_list = []
for policy in template.policies:
policy_dict = {policy.name: policy.entity_tpl}
policies_list.append(policy_dict)
tosca_template_dict['topology_template']['policies'] = policies_list
return tosca_template_dict
def contains_node_type(node_types_list, node_type_name):
if node_types_list is None:
return False
for node_type in node_types_list:
if isinstance(node_type, NodeTemplate):
type_name = node_type.type
elif isinstance(node_type, dict):
type_name = next(iter(node_type))
if type_name == node_type_name:
return True
return False
def get_node_properties(node):
node_type_name = get_node_type_name(node)
return node[node_type_name]['properties']
def set_node_properties(node, properties):
node_type_name = get_node_type_name(node)
node[node_type_name]['properties'] = properties
return node
def get_nodes_by_type(node_type, nodes, all_node_types, all_custom_def):
nodes_by_type = []
for node in nodes:
if node.type == node_type:
nodes_by_type.append(node)
break
elif node_type in get_all_ancestors_types(node, all_node_types, all_custom_def):
nodes_by_type.append(node)
return nodes_by_type
def get_all_ancestors_types(child_node, all_node_types, all_custom_def, ancestors_types=None):
if not ancestors_types:
ancestors_types = [get_node_type_name(child_node)]
parent_type = get_parent_type(child_node)
if parent_type:
ancestors_types.append(parent_type)
parent_type = node_type_2_node_template({'name': all_node_types[parent_type]}, all_custom_def)
get_all_ancestors_types(parent_type, all_node_types, all_custom_def, ancestors_types)
return ancestors_types
def get_all_ancestors_properties(node, all_nodes, all_custom_def, ancestors_properties=None, ancestors_types=None):
if not ancestors_properties:
ancestors_properties = []
ancestors_properties_names = []
node_prop_names = []
if node.get_properties_objects():
for node_prop in node.get_properties_objects():
node_prop_names.append(node_prop.name)
ancestors_properties.append(node_prop)
if not ancestors_types:
ancestors_types = get_all_ancestors_types(node, all_nodes, all_custom_def)
for ancestors_type in ancestors_types:
ancestor = node_type_2_node_template({'name': all_nodes[ancestors_type]}, all_custom_def)
if ancestor.get_properties_objects():
for ancestor_prop in ancestor.get_properties_objects():
if ancestor_prop.name not in ancestors_properties_names and ancestor_prop.name not in node_prop_names:
ancestors_properties_names.append(ancestor_prop.name)
ancestors_properties.append(ancestor_prop)
return ancestors_properties
def get_nodes_with_occurrences_in_requirements(topology_nodes):
nodes_with_occurrences_in_requirement = []
for node in topology_nodes:
for requirement in node.requirements:
requirement_dict = requirement[next(iter(requirement))]
if 'occurrences' in requirement_dict:
nodes_with_occurrences_in_requirement.append(node)
break
return nodes_with_occurrences_in_requirement
def tosca_template2_yaml(tosca_template):
topology_dict = {DEFINITION_VERSION: tosca_template.version, IMPORTS: tosca_template._tpl_imports(),
DESCRIPTION: tosca_template.description, TOPOLOGY_TEMPLATE: {}}
topology_dict[TOPOLOGY_TEMPLATE][NODE_TEMPLATES] = {}
node_templates = tosca_template.nodetemplates
for node_template in node_templates:
node_template_dict = get_node_template_dict(node_template)
topology_dict[TOPOLOGY_TEMPLATE][NODE_TEMPLATES][node_template.name] = node_template_dict
# If we don't add this then dump uses references for the same dictionary entries i.e. '&id001'
yaml.Dumper.ignore_aliases = lambda *args: True
return yaml.dump(topology_dict, default_flow_style=False)
def get_node_template_dict(node_template):
node_template_dict = {TYPE: node_template.type}
# node_template_dict[REQUIREMENTS] = {}
if node_template.requirements:
node_template_dict[REQUIREMENTS] = node_template.requirements
# if node_template.interfaces:
# interfaces = {}
# for interface in node_template.interfaces:
# interfaces[interface.type] = {}
# interfaces[interface.type][interface.name] = interface.implementation
# print( node_template.templates[node_template.name] )
if ARTIFACTS in node_template.templates[node_template.name].keys():
node_template_dict[ARTIFACTS] = node_template.templates[node_template.name][ARTIFACTS]
if PROPERTIES in node_template.templates[node_template.name].keys():
node_template_dict[PROPERTIES] = node_template.templates[node_template.name][PROPERTIES]
if INTERFACES in node_template.templates[node_template.name].keys():
node_template_dict[INTERFACES] = node_template.templates[node_template.name][INTERFACES]
# print(dir(node_template))
# print(node_template.templates)
return node_template_dict
from toscaparser.topology_template import TopologyTemplate
from toscaparser.tosca_template import ToscaTemplate
from sure_tosca.service import tosca_template_service
from sure_tosca.service.tosca_template_service import *
import connexion
import six
......@@ -11,213 +5,226 @@ from sure_tosca.models.node_template import NodeTemplate # noqa: E501
from sure_tosca.models.topology_template import TopologyTemplate # noqa: E501
from sure_tosca.models.tosca_template import ToscaTemplate # noqa: E501
from sure_tosca import util
from sure_tosca.service import tosca_template_service
def get_all_ancestor_properties(id, body=None, node_name=None): # noqa: E501
def get_all_ancestor_properties(id, node_root_key): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node&#39;s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: List[Dict[str, object]]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_all_ancestor_properties(id, node_root_key)
def get_all_ancestor_types(id, body=None, node_name=None): # noqa: E501
def get_all_ancestor_types(id, node_root_key): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node&#39;s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: List[str]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_all_ancestor_types(id, node_root_key)
def get_ancestors_requirements(id, body=None, node_name=None): # noqa: E501
def get_ancestors_requirements(id, node_root_key): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node&#39;s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_all_ancestors_requirements(id, node_root_key)
def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501
"""
returns the interface types # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param anchors: the anchors the definition is for
:type anchors: List[str]
:param derived_from: derived from
:type derived_from: str
:rtype: List[Dict[str, object]]
"""
return tosca_template_service.get_tosca_template_model_by_id(id).dsl_definitions
def get_node_outputs(id, nodeTemplate=None, node_name=None): # noqa: E501
def get_imports(id): # noqa: E501
"""
returns the interface types # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:rtype: List[Dict[str, object]]
"""
return tosca_template_service.get_tosca_template_model_by_id(id).imports
def get_node_outputs(id, node_root_key): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param nodeTemplate:
:type nodeTemplate: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
nodeTemplate = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_node_outputs(id, name_key=node_root_key)
def get_node_properties(id, body=None, node_name=None): # noqa: E501
def get_node_properties(id, node_root_key): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_node_templates(id, name_key=node_root_key)[0].properties
def get_node_requirements(id, body=None, node_name=None): # noqa: E501
def get_node_requirements(id, node_root_key): # noqa: E501
"""get_node_requirements
Returns the requirements for an input node as described in the template not in the node&#39;s definition # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_node_templates(id, name_key=node_root_key)[0].requirements
def get_node_templates(id, node_name=None, node_type=None, has_interface=None): # noqa: E501
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): # noqa: E501
"""get_node_templates
returns nodes templates in topology # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_name: filter by node name
:type node_name: str
:param node_type: filter by node type
:type node_type: str
:param has_interface: filter if node has interface
:type has_interface: bool
:param type_name: The type
:type type_name: str
:param name_key: the name key
:type name_key: str
:param has_interfaces: filter if has interfaces
:type has_interfaces: bool
:param has_properties: filter if has properties
:type has_properties: bool
:param has_attributes: filter if has attributes
:type has_attributes: bool
:param has_requirements: filter if has requirements
:type has_requirements: bool
:param has_capabilities: filter if has capabilities
:type has_capabilities: bool
:param has_artifacts: filter if has artifacts
:type has_artifacts: bool
:param derived_from: derived from
:type derived_from: str
:rtype: List[NodeTemplate]
"""
return tosca_template_service.get_node_templates(id, name=node_name, node_type=node_type, has_interface=has_interface)
return tosca_template_service.get_node_templates(id, type_name=type_name, name_key=name_key,
has_interfaces=has_interfaces, has_properties=has_properties,
has_attributes=has_attributes, has_requirements=has_requirements,
has_capabilities=has_capabilities, has_artifacts=has_artifacts,
derived_from=derived_from)
def get_node_type_name(id, nodeTemplate=None, node_name=None): # noqa: E501
def get_node_type_name(id, node_root_key): # noqa: E501
"""
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param nodeTemplate: the NodeTemplate
:type nodeTemplate: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: str
"""
if connexion.request.is_json:
nodeTemplate = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_node_type_name(id, node_root_key)
def get_parent_type_name(id, nodeTemplate=None, node_name=None): # noqa: E501
def get_parent_type_name(id, node_root_key): # noqa: E501
"""
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: str
"""
if connexion.request.is_json:
nodeTemplate = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_parent_type_name(id, node_root_key)
def get_related_node(id, nodeTemplate=None, node_name=None): # noqa: E501
def get_related_nodes(id, node_root_key): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param nodeTemplate:
:type nodeTemplate: dict | bytes
:param node_name: The node name
:type node_name: str
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: List[NodeTemplate]
"""
if connexion.request.is_json:
nodeTemplate = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.get_related_nodes(id, node_root_key)
def set_node_properties(id, properties, node_name): # noqa: E501
def get_relationship_templates(id, type_name=None, derived_from=None): # noqa: E501
"""
s # noqa: E501
returns the interface types # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param properties:
:type properties:
:param node_name: The node name
:type node_name: str
:param type_name: The relationship type
:type type_name: str
:param derived_from: derived from
:type derived_from: str
:rtype: Dict[str, object]
:rtype: List[Dict[str, object]]
"""
return 'do some magic!'
return tosca_template_service.get_relationship_templates(id, type_name=type_name, derived_from=derived_from)
def get_topology_template(id): # noqa: E501
......@@ -230,7 +237,7 @@ def get_topology_template(id): # noqa: E501
:rtype: TopologyTemplate
"""
return tosca_template_service.get_tosca_template_model_by_id(id).topology_template
return tosca_template_service.get_tosca_template_dict_by_id(id)
def get_tosca_template(id): # noqa: E501
......@@ -246,48 +253,67 @@ def get_tosca_template(id): # noqa: E501
return tosca_template_service.get_tosca_template_model_by_id(id)
def upload_tosca_template(file): # noqa: E501
"""upload a tosca template description file
def get_types(id, kind_of_type=None, has_interfaces=None, type_name=None, has_properties=None, has_attributes=None,
has_requirements=None, has_capabilities=None, has_artifacts=None, derived_from=None): # noqa: E501
"""
upload and validate a tosca template description file # noqa: E501
returns the interface types # noqa: E501
:param file: tosca Template description
:type file: werkzeug.datastructures.FileStorage
:param id: ID of topolog template uplodaed
:type id: str
:param kind_of_type: the type we are looking for e.g. capability_types, artifact_types. etc.
:type kind_of_type: str
:param has_interfaces: filter if has interfaces
:type has_interfaces: bool
:param type_name: The relationship type
:type type_name: str
:param has_properties: filter if has properties
:type has_properties: bool
:param has_attributes: filter if has attributes
:type has_attributes: bool
:param has_requirements: filter if has requirements
:type has_requirements: bool
:param has_capabilities: filter if has capabilities
:type has_capabilities: bool
:param has_artifacts: filter if has artifacts
:type has_artifacts: bool
:param derived_from: derived from
:type derived_from: str
:rtype: str
:rtype: List[Dict[str, object]]
"""
return tosca_template_service.save(file)
return tosca_template_service.get_types(id, kind_of_type=kind_of_type, has_interfaces=has_interfaces,
type_name=type_name, has_properties=has_properties,
has_attributes=has_attributes, has_requirements=has_requirements,
has_capabilities=has_capabilities, has_artifacts=has_artifacts,
derived_from=derived_from)
def get_related_nodes(id, nodeTemplate=None, node_name=None): # noqa: E501
def set_node_properties(id, properties, node_root_key): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param nodeTemplate:
:type nodeTemplate: dict | bytes
:param node_name: The node name
:type node_name: str
:param properties:
:type properties:
:param node_root_key: node_root_key
:type node_root_key: str
:rtype: List[NodeTemplate]
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
nodeTemplate = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
return tosca_template_service.set_node_properties(id, properties, node_root_key)
def get_interface_types(id, interface_type=None): # noqa: E501
"""
def upload_tosca_template(file): # noqa: E501
"""upload a tosca template description file
returns the interface types # noqa: E501
upload and validate a tosca template description file # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param interface_type: The interface type
:type interface_type: str
:param file: tosca Template description
:type file: werkzeug.datastructures.FileStorage
:rtype: List[Dict[str, object]]
:rtype: str
"""
return tosca_template_service.get_interface_types(id, interface_type=interface_type)
return tosca_template_service.save(file)
......@@ -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:
for interface_type_name in interface_types:
interface = {root_key: interface_type_name}
interface.update(interface_types[interface_type_name])
queries = []
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
query = Query()
queries.append(query._name_key == interface_type)
return query_tmp_db(queries)
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)
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()
queries.append(query.name == name)
if node_type:
prop = None
queries.append(query.interfaces != prop)
if has_attributes:
query = Query()
queries.append(query.type == node_type)
if has_interface:
prop = None
queries.append(query.attributes != prop)
if has_requirements:
query = Query()
interface = None
queries.append(query.interfaces != 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 = 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
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()
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
......@@ -57,6 +57,196 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/imports:
get:
summary: ""
description: "returns the interface types"
operationId: "get_imports"
produces:
- "application/json"
parameters:
- name: "id"
in: "path"
description: "ID of topolog template uplodaed"
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
type: "object"
additionalProperties:
type: "object"
properties: {}
404:
description: "Not found"
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/dsl_definitions:
get:
summary: ""
description: "returns the interface types"
operationId: "get_dsl_definitions"
produces:
- "application/json"
parameters:
- name: "id"
in: "path"
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "anchors"
in: "query"
description: "the anchors the definition is for"
required: false
type: "array"
items:
type: "string"
collectionFormat: "multi"
- name: "derived_from"
in: "query"
description: "derived from"
required: false
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
type: "object"
additionalProperties:
type: "object"
properties: {}
404:
description: "Not found"
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/types:
get:
summary: ""
description: "returns the interface types"
operationId: "get_types"
produces:
- "application/json"
parameters:
- name: "id"
in: "path"
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "kind_of_type"
in: "query"
description: "the type we are looking for e.g. capability_types, artifact_types.\
\ etc."
required: false
type: "string"
enum:
- "node_types"
- "relationship_types"
- "capability_types"
- "artifact_types"
- "data_types"
- "interface_types"
- "policy_types"
- "group_types"
- name: "has_interfaces"
in: "query"
description: "filter if has interfaces"
required: false
type: "boolean"
- name: "type_name"
in: "query"
description: "The relationship type"
required: false
type: "string"
- name: "has_properties"
in: "query"
description: "filter if has properties"
required: false
type: "boolean"
- name: "has_attributes"
in: "query"
description: "filter if has attributes"
required: false
type: "boolean"
- name: "has_requirements"
in: "query"
description: "filter if has requirements"
required: false
type: "boolean"
- name: "has_capabilities"
in: "query"
description: "filter if has capabilities"
required: false
type: "boolean"
- name: "has_artifacts"
in: "query"
description: "filter if has artifacts"
required: false
type: "boolean"
- name: "derived_from"
in: "query"
description: "derived from"
required: false
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
type: "object"
additionalProperties:
type: "object"
properties: {}
404:
description: "Not found"
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/relationship_templates:
get:
summary: ""
description: "returns the interface types"
operationId: "get_relationship_templates"
produces:
- "application/json"
parameters:
- name: "id"
in: "path"
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "type_name"
in: "query"
description: "The relationship type"
required: false
type: "string"
- name: "derived_from"
in: "query"
description: "derived from"
required: false
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
type: "object"
additionalProperties:
type: "object"
properties: {}
404:
description: "Not found"
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template:
get:
description: "r"
......@@ -91,21 +281,51 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_name"
- name: "type_name"
in: "query"
description: "filter by node name"
description: "The type"
required: false
type: "string"
- name: "node_type"
- name: "name_key"
in: "query"
description: "filter by node type"
description: "the name key"
required: false
type: "string"
- name: "has_interface"
- name: "has_interfaces"
in: "query"
description: "filter if has interfaces"
required: false
type: "boolean"
- name: "has_properties"
in: "query"
description: "filter if has properties"
required: false
type: "boolean"
- name: "has_attributes"
in: "query"
description: "filter if node has interface"
description: "filter if has attributes"
required: false
type: "boolean"
- name: "has_requirements"
in: "query"
description: "filter if has requirements"
required: false
type: "boolean"
- name: "has_capabilities"
in: "query"
description: "filter if has capabilities"
required: false
type: "boolean"
- name: "has_artifacts"
in: "query"
description: "filter if has artifacts"
required: false
type: "boolean"
- name: "derived_from"
in: "query"
description: "derived from"
required: false
type: "string"
responses:
200:
description: "successful operation"
......@@ -118,7 +338,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/type_name:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/type_name:
get:
summary: ""
description: ""
......@@ -131,16 +351,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
description: "the NodeTemplate"
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -152,7 +366,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/requirements:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/requirements:
get:
description: "Returns the requirements for an input node as described in the\
\ template not in the node's definition "
......@@ -165,16 +379,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
description: ""
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -189,7 +397,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/parent_type_name:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/derived_from:
get:
summary: ""
description: ""
......@@ -202,16 +410,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
description: ""
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -223,7 +425,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/ancestors_requirements:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_requirements:
get:
summary: ""
description: "Recursively get all requirements all the way to the ROOT including\
......@@ -237,15 +439,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -260,7 +457,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/ancestors_types:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_types:
get:
summary: ""
description: "Recursively get all requirements all the way to the ROOT including\
......@@ -274,15 +471,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -296,7 +488,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/ancestors_properties:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_properties:
get:
summary: ""
description: "Recursively get all requirements all the way to the ROOT including\
......@@ -310,15 +502,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -335,7 +522,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/properties:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/properties:
get:
summary: ""
description: "s"
......@@ -348,15 +535,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -390,9 +572,9 @@ paths:
type: "object"
additionalProperties:
type: "string"
- name: "node_name"
in: "query"
description: "The node name"
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
......@@ -408,7 +590,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/outputs:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/outputs:
get:
summary: ""
description: "s"
......@@ -421,15 +603,10 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
- name: "node_root_key"
in: "path"
description: "node_root_key"
required: true
type: "string"
responses:
200:
......@@ -444,7 +621,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/related:
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/related:
get:
summary: ""
description: "s"
......@@ -457,56 +634,18 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "nodeTemplate"
required: false
schema:
$ref: "#/definitions/NodeTemplate"
- name: "node_name"
in: "query"
description: "The node name"
required: false
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/NodeTemplate"
404:
description: "Not found"
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/interface_types:
get:
summary: ""
description: "returns the interface types"
operationId: "get_interface_types"
produces:
- "application/json"
parameters:
- name: "id"
- name: "node_root_key"
in: "path"
description: "ID of topolog template uplodaed"
description: "node_root_key"
required: true
type: "string"
- name: "interface_type"
in: "query"
description: "The interface type"
required: false
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
type: "object"
additionalProperties:
type: "object"
properties: {}
$ref: "#/definitions/NodeTemplate"
404:
description: "Not found"
405:
......
......@@ -19,14 +19,9 @@ class TestDefaultController(BaseTestCase):
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/ancestors_properties'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_properties'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -35,14 +30,9 @@ class TestDefaultController(BaseTestCase):
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/ancestors_types'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_types'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -51,46 +41,45 @@ class TestDefaultController(BaseTestCase):
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/ancestors_requirements'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_requirements'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_interface_types(self):
"""Test case for get_interface_types
def test_get_dsl_definitions(self):
"""Test case for get_dsl_definitions
"""
body = NodeTemplate()
query_string = [('interface_type', 'interface_type_example')]
query_string = [('anchors', 'anchors_example'),
('derived_from', 'derived_from_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/interface_types'.format(id='id_example'),
'/tosca-sure/1.0.0/tosca_template/{id}/dsl_definitions'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_imports(self):
"""Test case for get_imports
"""
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/imports'.format(id='id_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_node_outputs(self):
"""Test case for get_node_outputs
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/outputs'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/outputs'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -99,14 +88,9 @@ class TestDefaultController(BaseTestCase):
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/properties'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/properties'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -115,14 +99,9 @@ class TestDefaultController(BaseTestCase):
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/requirements'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/requirements'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -131,9 +110,15 @@ class TestDefaultController(BaseTestCase):
"""
query_string = [('node_name', 'node_name_example'),
('node_type', 'node_type_example'),
('has_interface', true)]
query_string = [('type_name', 'type_name_example'),
('name_key', 'name_key_example'),
('has_interfaces', true),
('has_properties', true),
('has_attributes', true),
('has_requirements', true),
('has_capabilities', true),
('has_artifacts', true),
('derived_from', 'derived_from_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates'.format(id='id_example'),
method='GET',
......@@ -146,14 +131,9 @@ class TestDefaultController(BaseTestCase):
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/type_name'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/type_name'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -162,29 +142,33 @@ class TestDefaultController(BaseTestCase):
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/parent_type_name'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/derived_from'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_related_node(self):
"""Test case for get_related_node
def test_get_related_nodes(self):
"""Test case for get_related_nodes
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/related'.format(id='id_example'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/related'.format(id='id_example', node_root_key='node_root_key_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_relationship_templates(self):
"""Test case for get_relationship_templates
"""
query_string = [('type_name', 'type_name_example'),
('derived_from', 'derived_from_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/relationship_templates'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -211,19 +195,38 @@ class TestDefaultController(BaseTestCase):
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_types(self):
"""Test case for get_types
"""
query_string = [('kind_of_type', 'kind_of_type_example'),
('has_interfaces', true),
('type_name', 'type_name_example'),
('has_properties', true),
('has_attributes', true),
('has_requirements', true),
('has_capabilities', true),
('has_artifacts', true),
('derived_from', 'derived_from_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/types'.format(id='id_example'),
method='GET',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_set_node_properties(self):
"""Test case for set_node_properties
"""
properties = None
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/properties'.format(id='id_example'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_root_key}/properties'.format(id='id_example', node_root_key='node_root_key_example'),
method='PUT',
data=json.dumps(properties),
content_type='application/json',
query_string=query_string)
content_type='application/json')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......
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