Commit a9d61f92 authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed errors from using NodeTemplateMap

parent 6df3b431
...@@ -319,7 +319,7 @@ paths: ...@@ -319,7 +319,7 @@ paths:
schema: schema:
type: array type: array
items: items:
$ref: '#/definitions/NodeTemplate' $ref: '#/definitions/NodeTemplateMap'
"404": "404":
description: Not found description: Not found
"405": "405":
...@@ -618,7 +618,7 @@ paths: ...@@ -618,7 +618,7 @@ paths:
schema: schema:
type: array type: array
items: items:
$ref: '#/definitions/NodeTemplate' $ref: '#/definitions/NodeTemplateMap'
"404": "404":
description: Not found description: Not found
"405": "405":
...@@ -746,8 +746,6 @@ definitions: ...@@ -746,8 +746,6 @@ definitions:
NodeTemplate: NodeTemplate:
type: object type: object
properties: properties:
name:
type: string
derived_from: derived_from:
type: string type: string
properties: properties:
...@@ -790,3 +788,10 @@ definitions: ...@@ -790,3 +788,10 @@ definitions:
additionalProperties: additionalProperties:
type: object type: object
properties: {} properties: {}
NodeTemplateMap:
type: object
properties:
name:
type: string
nodeTemplate:
$ref: '#/definitions/NodeTemplate'
...@@ -176,10 +176,8 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, ...@@ -176,10 +176,8 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None,
:type has_capabilities: bool :type has_capabilities: bool
:param has_artifacts: filter if has artifacts :param has_artifacts: filter if has artifacts
:type has_artifacts: bool :type has_artifacts: bool
:param derived_from: derived from
:type derived_from: str
:rtype: List[NodeTemplate] :rtype: List[NodeTemplateMap]
""" """
res = tosca_template_service.get_node_templates(id, type_name=type_name, node_name=node_name, res = tosca_template_service.get_node_templates(id, type_name=type_name, node_name=node_name,
has_interfaces=has_interfaces, has_properties=has_properties, has_interfaces=has_interfaces, has_properties=has_properties,
...@@ -236,7 +234,7 @@ def get_related_nodes(id, node_name): # noqa: E501 ...@@ -236,7 +234,7 @@ def get_related_nodes(id, node_name): # noqa: E501
:param node_name: node_name :param node_name: node_name
:type node_name: str :type node_name: str
:rtype: List[NodeTemplate] :rtype: List[NodeTemplateMap]
""" """
res = tosca_template_service.get_related_nodes(id, node_name) res = tosca_template_service.get_related_nodes(id, node_name)
if res: if res:
......
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from sure_tosca.models import NodeTemplateModel
from sure_tosca.models.base_model_ import Model
from sure_tosca import util
class NodeTemplateMapModel(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, name=None, node_template=None): # noqa: E501
"""NodeTemplateMap - a model defined in Swagger
:param name: The name of this NodeTemplateMap. # noqa: E501
:type name: str
:param node_template: The node_template of this NodeTemplateMap. # noqa: E501
:type node_template: NodeTemplate
"""
self.swagger_types = {
'name': str,
'node_template': NodeTemplateModel
}
self.attribute_map = {
'name': 'name',
'node_template': 'nodeTemplate'
}
self._name = name
self._node_template = node_template
@classmethod
def from_dict(cls, dikt):
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The NodeTemplateMap of this NodeTemplateMap. # noqa: E501
:rtype: NodeTemplateMapModel
"""
return util.deserialize_model(dikt, cls)
@property
def name(self):
"""Gets the name of this NodeTemplateMap.
:return: The name of this NodeTemplateMap.
:rtype: str
"""
return self._name
@name.setter
def name(self, name):
"""Sets the name of this NodeTemplateMap.
:param name: The name of this NodeTemplateMap.
:type name: str
"""
self._name = name
@property
def node_template(self):
"""Gets the node_template of this NodeTemplateMap.
:return: The node_template of this NodeTemplateMap.
:rtype: NodeTemplate
"""
return self._node_template
@node_template.setter
def node_template(self, node_template):
"""Sets the node_template of this NodeTemplateMap.
:param node_template: The node_template of this NodeTemplateMap.
:type node_template: NodeTemplate
"""
self._node_template = node_template
...@@ -106,8 +106,9 @@ def get_node_types_with_interface(nodes): ...@@ -106,8 +106,9 @@ def get_node_types_with_interface(nodes):
return node_types_with_interface return node_types_with_interface
def node_dict_2_node_template(node_dict, all_custom_def): def node_dict_2_node_template(node_name,node_dict, all_custom_def):
node_name = next(iter(node_dict))
node_dict = {node_name:node_dict}
# node_type = node_dict[node_name]['type'] # node_type = node_dict[node_name]['type']
# for name_to_remove in node_type_key_names_to_remove: # for name_to_remove in node_type_key_names_to_remove:
......
...@@ -16,7 +16,9 @@ from toscaparser.tosca_template import ToscaTemplate ...@@ -16,7 +16,9 @@ from toscaparser.tosca_template import ToscaTemplate
from sure_tosca.models.base_model_ import Model from sure_tosca.models.base_model_ import Model
from sure_tosca.models.node_template import NodeTemplateModel as NodeTemplateModel from sure_tosca.models.node_template import NodeTemplateModel as NodeTemplateModel
from sure_tosca.models.node_template_map import NodeTemplateMapModel
from sure_tosca.models.tosca_template import ToscaTemplateModel as ToscaTemplateModel from sure_tosca.models.tosca_template import ToscaTemplateModel as ToscaTemplateModel
from sure_tosca.service import tosca_helper from sure_tosca.service import tosca_helper
# db = TinyDB(storage=CachingMiddleware(MemoryStorage)) # db = TinyDB(storage=CachingMiddleware(MemoryStorage))
...@@ -48,7 +50,7 @@ def query_db(queries, db=None): ...@@ -48,7 +50,7 @@ def query_db(queries, db=None):
res_copy.pop(root_key) res_copy.pop(root_key)
node = {key: res_copy} node = {key: res_copy}
else: else:
logging.error(str(res)+ ' has no '+root_key) logging.error(str(res) + ' has no ' + root_key)
updated_results.append(node) updated_results.append(node)
return updated_results return updated_results
return None return None
...@@ -120,10 +122,12 @@ def change_to_nodeTemplateModel(query_results): ...@@ -120,10 +122,12 @@ def change_to_nodeTemplateModel(query_results):
res = [] res = []
for node_template in query_results: for node_template in query_results:
# copy.deepcopy() # copy.deepcopy()
node_template_map = NodeTemplateMapModel()
name = next(iter(node_template)) name = next(iter(node_template))
node_template_map.name = name
node_template = node_template[name] node_template = node_template[name]
node_template['name'] = name node_template_map.node_template = NodeTemplateModel.from_dict(node_template)
res.append(NodeTemplateModel.from_dict(node_template)) res.append(node_template_map)
return res return res
...@@ -188,7 +192,6 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, ...@@ -188,7 +192,6 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None,
return change_to_nodeTemplateModel(query_results) return change_to_nodeTemplateModel(query_results)
def get_tosca_template_get_dsl_definitions(id, anchors, derived_from): def get_tosca_template_get_dsl_definitions(id, anchors, derived_from):
# interface_types_db.purge() # interface_types_db.purge()
if len(dsl_definitions_db) <= 1: if len(dsl_definitions_db) <= 1:
...@@ -240,14 +243,10 @@ def node_dict_2_node_template(id, node_name): ...@@ -240,14 +243,10 @@ def node_dict_2_node_template(id, node_name):
all_node_types.update(tosca_node_types.items()) all_node_types.update(tosca_node_types.items())
all_node_types.update(all_custom_def.items()) all_node_types.update(all_custom_def.items())
node_template_dict = get_node_templates(id, node_name=node_name)[0] node_template_map_dict = get_node_templates(id, node_name=node_name)[0]
the_node = tosca_helper.node_dict_2_node_template(node_template_map_dict.name,
if next(iter(node_template_dict)) != node_name: node_template_map_dict.node_template.to_dict(), all_node_types)
node_template_dict = {node_name: node_template_dict}
if isinstance(node_template_dict, dict):
the_node = tosca_helper.node_dict_2_node_template(node_template_dict, all_node_types)
return the_node, all_node_types, all_custom_def return the_node, all_node_types, all_custom_def
return None
def get_all_ancestors_requirements(id, node_root_key): def get_all_ancestors_requirements(id, node_root_key):
...@@ -310,22 +309,17 @@ def get_node_outputs(id, node_name): ...@@ -310,22 +309,17 @@ def get_node_outputs(id, node_name):
def get_node_properties(id, node_name): def get_node_properties(id, node_name):
node_template_dict = get_node_templates(id, node_name=node_name)[0] node_template_map = get_node_templates(id, node_name=node_name)[0]
if node_name in node_template_dict:
node_template_dict = node_template_dict[node_name]
properties = NodeTemplateModel.from_dict(node_template_dict).properties properties = node_template_map.node_template.properties
if properties: if properties:
return properties return properties
return None return None
def get_node_requirements(id, node_name): def get_node_requirements(id, node_name):
node_template_dict = get_node_templates(id, node_name=node_name)[0] node_template_map = get_node_templates(id, node_name=node_name)[0]
if node_name in node_template_dict: requirements = node_template_map.node_template.requirements
node_template_dict = node_template_dict[node_name]
requirements = NodeTemplateModel.from_dict(node_template_dict).requirements
if requirements: if requirements:
return requirements return requirements
return None return None
...@@ -349,11 +343,8 @@ def get_related_nodes(id, node_name): ...@@ -349,11 +343,8 @@ def get_related_nodes(id, node_name):
def get_node_type_name(id, node_name): def get_node_type_name(id, node_name):
node_template_dict = get_node_templates(id, node_name=node_name)[0] node_template_map = get_node_templates(id, node_name=node_name)[0]
if node_name in node_template_dict: type_name = node_template_map.node_template.type
node_template_dict = node_template_dict[node_name]
type_name = NodeTemplateModel.from_dict(node_template_dict).type
if type_name: if type_name:
return type_name return type_name
return None return None
...@@ -377,7 +368,7 @@ def set_node_properties(id, properties, node_name): ...@@ -377,7 +368,7 @@ def set_node_properties(id, properties, node_name):
node_template_model.properties = properties node_template_model.properties = properties
tosca_template_model.topology_template.node_templates[node_name] = node_template_model tosca_template_model.topology_template.node_templates[node_name] = node_template_model
return update(id,tosca_template_model.to_dict()) return update(id, tosca_template_model.to_dict())
return None return None
......
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