Commit c4e39763 authored by Spiros Koulouzis's avatar Spiros Koulouzis

lots of stuff

parent a167ffb1
......@@ -8,49 +8,49 @@ from sure_tosca import util
from sure_tosca.service import tosca_template_service
def get_all_ancestor_properties(id, node_root_key): # noqa: E501
def get_all_ancestor_properties(id, node_name): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node's # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: List[Dict[str, object]]
"""
return tosca_template_service.get_all_ancestor_properties(id, node_root_key)
return tosca_template_service.get_all_ancestor_properties(id, node_name)
def get_all_ancestor_types(id, node_root_key): # noqa: E501
def get_all_ancestor_types(id, node_name): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node's # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: List[str]
"""
return tosca_template_service.get_all_ancestor_types(id, node_root_key)
return tosca_template_service.get_all_ancestor_types(id, node_name)
def get_ancestors_requirements(id, node_root_key): # noqa: E501
def get_ancestors_requirements(id, node_name): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node's # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: Dict[str, object]
"""
return tosca_template_service.get_all_ancestors_requirements(id, node_root_key)
return tosca_template_service.get_all_ancestors_requirements(id, node_name)
def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501
......@@ -83,54 +83,52 @@ def get_imports(id): # noqa: E501
return tosca_template_service.get_tosca_template_model_by_id(id).imports
def get_node_outputs(id, node_root_key): # noqa: E501
def get_node_outputs(id, node_name): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: Dict[str, object]
"""
return tosca_template_service.get_node_outputs(id, name_key=node_root_key)
return tosca_template_service.get_node_outputs(id, node_name)
def get_node_properties(id, node_root_key): # noqa: E501
def get_node_properties(id, node_name): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: Dict[str, object]
"""
return tosca_template_service.get_node_templates(id, name_key=node_root_key)[0].properties
return tosca_template_service.get_node_properties(id, node_name)
def get_node_requirements(id, node_root_key): # noqa: E501
def get_node_requirements(id, node_name): # noqa: E501
"""get_node_requirements
Returns the requirements for an input node as described in the template not in the node's definition # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: Dict[str, object]
"""
return tosca_template_service.get_node_templates(id, name_key=node_root_key)[0].requirements
return tosca_template_service.get_node_requirements(id, node_name)
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
def get_node_templates(id, type_name=None, node_name=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
......@@ -139,8 +137,8 @@ def get_node_templates(id, type_name=None, name_key=None, has_interfaces=None, h
:type id: str
:param type_name: The type
:type type_name: str
:param name_key: the name key
:type name_key: str
:param node_name: the name
:type node_name: str
:param has_interfaces: filter if has interfaces
:type has_interfaces: bool
:param has_properties: filter if has properties
......@@ -158,56 +156,56 @@ def get_node_templates(id, type_name=None, name_key=None, has_interfaces=None, h
:rtype: List[NodeTemplate]
"""
return tosca_template_service.get_node_templates(id, type_name=type_name, name_key=name_key,
return tosca_template_service.get_node_templates(id, type_name=type_name, node_name=node_name,
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, node_root_key): # noqa: E501
def get_node_type_name(id, node_name): # noqa: E501
"""
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: str
"""
return tosca_template_service.get_node_type_name(id, node_root_key)
return tosca_template_service.get_node_type_name(id, node_name)
def get_parent_type_name(id, node_root_key): # noqa: E501
def get_parent_type_name(id, node_name): # noqa: E501
"""
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: str
"""
return tosca_template_service.get_parent_type_name(id, node_root_key)
return tosca_template_service.get_parent_type_name(id, node_name)
def get_related_nodes(id, node_root_key): # noqa: E501
def get_related_nodes(id, node_name): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: List[NodeTemplate]
"""
return tosca_template_service.get_related_nodes(id, node_root_key)
return tosca_template_service.get_related_nodes(id, node_name)
def get_relationship_templates(id, type_name=None, derived_from=None): # noqa: E501
......@@ -253,8 +251,7 @@ def get_tosca_template(id): # noqa: E501
return tosca_template_service.get_tosca_template_model_by_id(id)
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
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
"""
returns the interface types # noqa: E501
......@@ -289,7 +286,7 @@ def get_types(id, kind_of_type=None, has_interfaces=None, type_name=None, has_pr
derived_from=derived_from)
def set_node_properties(id, properties, node_root_key): # noqa: E501
def set_node_properties(id, properties, node_name): # noqa: E501
"""
s # noqa: E501
......@@ -298,12 +295,12 @@ def set_node_properties(id, properties, node_root_key): # noqa: E501
:type id: str
:param properties:
:type properties:
:param node_root_key: node_root_key
:type node_root_key: str
:param node_name: node_name
:type node_name: str
:rtype: Dict[str, object]
:rtype: NodeTemplate
"""
return tosca_template_service.set_node_properties(id, properties, node_root_key)
return tosca_template_service.set_node_properties(id, properties, node_name)
def upload_tosca_template(file): # noqa: E501
......
......@@ -3,10 +3,10 @@
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from toscaparser.nodetemplate import NodeTemplate
from typing import List, Dict # noqa: F401
from sure_tosca.models.base_model_ import Model
from sure_tosca.models.node_template import NodeTemplate # noqa: F401,E501
from sure_tosca import util
......@@ -28,7 +28,7 @@ class TopologyTemplate(Model):
:param relationship_templates: The relationship_templates of this TopologyTemplate. # noqa: E501
:type relationship_templates: Dict[str, object]
:param outputs: The outputs of this TopologyTemplate. # noqa: E501
:type outputs: Dict[str, object]
:type outputs: str
:param groups: The groups of this TopologyTemplate. # noqa: E501
:type groups: Dict[str, object]
:param substitution_mappings: The substitution_mappings of this TopologyTemplate. # noqa: E501
......@@ -41,7 +41,7 @@ class TopologyTemplate(Model):
'inputs': List[Dict[str, object]],
'node_templates': Dict[str, NodeTemplate],
'relationship_templates': Dict[str, object],
'outputs': Dict[str, object],
'outputs': str,
'groups': Dict[str, object],
'substitution_mappings': Dict[str, object],
'policies': List[Dict[str, object]]
......@@ -168,7 +168,7 @@ class TopologyTemplate(Model):
:return: The outputs of this TopologyTemplate.
:rtype: Dict[str, object]
:rtype: str
"""
return self._outputs
......@@ -178,7 +178,7 @@ class TopologyTemplate(Model):
:param outputs: The outputs of this TopologyTemplate.
:type outputs: Dict[str, object]
:type outputs: str
"""
self._outputs = outputs
......
......@@ -3,10 +3,10 @@
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from toscaparser.topology_template import TopologyTemplate
from typing import List, Dict # noqa: F401
from sure_tosca.models.base_model_ import Model
from sure_tosca.models.topology_template import TopologyTemplate # noqa: F401,E501
from sure_tosca import util
......
......@@ -106,6 +106,28 @@ def get_node_types_with_interface(nodes):
return node_types_with_interface
def node_dict_2_node_template(node_dict, all_custom_def):
node_name = next(iter(node_dict))
node_type = node_dict[node_name]['type']
# for name_to_remove in node_type_key_names_to_remove:
# if name_to_remove in node_dict[node_name][node_name]:
# node_dict[node_name].pop(name_to_remove)
node_template = NodeTemplate(node_name, node_templates=node_dict, custom_def=all_custom_def)
# 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 node_type_2_node_template(node_type, all_custom_def):
node_template_dict = {}
type_name = next(iter(node_type))
......@@ -166,6 +188,10 @@ def contains_node_type(node_types_list, node_type_name):
def get_node_properties(node):
node_type_name = get_node_type_name(node)
if 'properties' in node[node_type_name]:
return node[node_type_name]['properties']
if 'properties' in node.entity_tpl:
return node.entity_tpl['properties']
return node[node_type_name]['properties']
......
......@@ -286,9 +286,9 @@ paths:
description: "The type"
required: false
type: "string"
- name: "name_key"
- name: "node_name"
in: "query"
description: "the name key"
description: "the name"
required: false
type: "string"
- name: "has_interfaces"
......@@ -338,7 +338,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/type_name:
/tosca_template/{id}/topology_template/node_templates/{node_name}/type_name:
get:
summary: ""
description: ""
......@@ -351,9 +351,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -366,7 +366,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/requirements:
/tosca_template/{id}/topology_template/node_templates/{node_name}/requirements:
get:
description: "Returns the requirements for an input node as described in the\
\ template not in the node's definition "
......@@ -379,9 +379,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -397,7 +397,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/derived_from:
/tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from:
get:
summary: ""
description: ""
......@@ -410,9 +410,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -425,7 +425,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_requirements:
/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements:
get:
summary: ""
description: "Recursively get all requirements all the way to the ROOT including\
......@@ -439,9 +439,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -457,7 +457,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_types:
/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types:
get:
summary: ""
description: "Recursively get all requirements all the way to the ROOT including\
......@@ -471,9 +471,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -488,7 +488,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/ancestors_properties:
/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties:
get:
summary: ""
description: "Recursively get all requirements all the way to the ROOT including\
......@@ -502,9 +502,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -522,7 +522,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/properties:
/tosca_template/{id}/topology_template/node_templates/{node_name}/properties:
get:
summary: ""
description: "s"
......@@ -535,9 +535,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -571,26 +571,24 @@ paths:
schema:
type: "object"
additionalProperties:
type: "string"
- name: "node_root_key"
type: "object"
properties: {}
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "object"
properties: {}
$ref: "#/definitions/NodeTemplate"
404:
description: "Not found"
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/outputs:
/tosca_template/{id}/topology_template/node_templates/{node_name}/outputs:
get:
summary: ""
description: "s"
......@@ -603,9 +601,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -621,7 +619,7 @@ paths:
405:
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_root_key}/related:
/tosca_template/{id}/topology_template/node_templates/{node_name}/related:
get:
summary: ""
description: "s"
......@@ -634,9 +632,9 @@ paths:
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_root_key"
- name: "node_name"
in: "path"
description: "node_root_key"
description: "node_name"
required: true
type: "string"
responses:
......@@ -736,8 +734,7 @@ definitions:
policy_types:
key: "policy_types"
topology_template:
outputs:
key: "{}"
outputs: "outputs"
substitution_mappings:
key: "{}"
inputs:
......@@ -821,10 +818,7 @@ definitions:
type: "object"
properties: {}
outputs:
type: "object"
additionalProperties:
type: "object"
properties: {}
type: "string"
groups:
type: "object"
additionalProperties:
......@@ -843,8 +837,7 @@ definitions:
type: "object"
properties: {}
example:
outputs:
key: "{}"
outputs: "outputs"
substitution_mappings:
key: "{}"
inputs:
......
......@@ -20,7 +20,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -31,7 +31,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -42,7 +42,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -78,7 +78,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/outputs'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -89,7 +89,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -100,7 +100,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/requirements'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -111,7 +111,7 @@ class TestDefaultController(BaseTestCase):
"""
query_string = [('type_name', 'type_name_example'),
('name_key', 'name_key_example'),
('node_name', 'node_name_example'),
('has_interfaces', true),
('has_properties', true),
('has_attributes', true),
......@@ -132,7 +132,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/type_name'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -143,7 +143,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -154,7 +154,7 @@ class TestDefaultController(BaseTestCase):
"""
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/related'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -223,7 +223,7 @@ class TestDefaultController(BaseTestCase):
"""
properties = None
response = self.client.open(
'/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'),
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(id='id_example', node_name='node_name_example'),
method='PUT',
data=json.dumps(properties),
content_type='application/json')
......
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