Commit 7ec82d5e authored by Spiros Koulouzis's avatar Spiros Koulouzis

changed ids

made deep copy for tosa template
parent 7e75bf9e
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment=""> <list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../TOSCA/application_example_2_topologies.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example_2_topologies.yaml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../openAPI/TOSCA/TopologyTemplate.yml" beforeDir="false" afterPath="$PROJECT_DIR$/../openAPI/TOSCA/TopologyTemplate.yml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../openAPI/TOSCA/OutputParameters.yml" beforeDir="false" afterPath="$PROJECT_DIR$/../openAPI/TOSCA/OutputParameters.yml" 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/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/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/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" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
......
--- ---
definitions: definitions:
docsoasisopenorgtoscans201112:OutputParameters: Output:
required: properties:
- OutputParameter name:
type: object type: string
properties: type:
OutputParameter: type: string
type: array description:
items: type: string
"$ref": "#/definitions/docsoasisopenorgtoscans201112:tParameter" required:
type: boolean
docsoasisopenorgtoscans201112:tParameter: value:
properties: type: $ref: "#/definitions/Value"
name: Value:
type: string properties:
type: name:
type: string type: string
required:
type: boolean
required:
- name
- type
type: object
lang:
type: string
space:
enum:
- default
- preserve
type: string
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
outputs: outputs:
type: string type: string
additionalProperties: additionalProperties:
type: object type: object
groups: groups:
type: object type: object
additionalProperties: additionalProperties:
......
import connexion import connexion
import six import six
from sure_tosca.models.node_template import NodeTemplate # noqa: E501 from sure_tosca.models.node_template import NodeTemplateModel # noqa: E501
from sure_tosca.models.topology_template import TopologyTemplate # noqa: E501 from sure_tosca.models.topology_template import TopologyTemplateModel # noqa: E501
from sure_tosca.models.tosca_template import ToscaTemplate # noqa: E501 from sure_tosca.models.tosca_template import ToscaTemplateModel # noqa: E501
from sure_tosca import util from sure_tosca import util
from sure_tosca.service import tosca_template_service from sure_tosca.service import tosca_template_service
...@@ -20,7 +20,10 @@ def get_all_ancestor_properties(id, node_name): # noqa: E501 ...@@ -20,7 +20,10 @@ def get_all_ancestor_properties(id, node_name): # noqa: E501
:rtype: List[Dict[str, object]] :rtype: List[Dict[str, object]]
""" """
return tosca_template_service.get_all_ancestor_properties(id, node_name) res = tosca_template_service.get_all_ancestor_properties(id, node_name)
if res:
return res
return 'Not Found', 404
def get_all_ancestor_types(id, node_name): # noqa: E501 def get_all_ancestor_types(id, node_name): # noqa: E501
...@@ -35,7 +38,10 @@ def get_all_ancestor_types(id, node_name): # noqa: E501 ...@@ -35,7 +38,10 @@ def get_all_ancestor_types(id, node_name): # noqa: E501
:rtype: List[str] :rtype: List[str]
""" """
return tosca_template_service.get_all_ancestor_types(id, node_name) res = tosca_template_service.get_all_ancestor_types(id, node_name)
if res:
return res
return 'Not Found', 404
def get_ancestors_requirements(id, node_name): # noqa: E501 def get_ancestors_requirements(id, node_name): # noqa: E501
...@@ -50,7 +56,10 @@ def get_ancestors_requirements(id, node_name): # noqa: E501 ...@@ -50,7 +56,10 @@ def get_ancestors_requirements(id, node_name): # noqa: E501
:rtype: Dict[str, object] :rtype: Dict[str, object]
""" """
return tosca_template_service.get_all_ancestors_requirements(id, node_name) res = tosca_template_service.get_all_ancestors_requirements(id, node_name)
if res:
return res
return 'Not Found', 404
def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501 def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501
...@@ -67,7 +76,10 @@ def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501 ...@@ -67,7 +76,10 @@ def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501
:rtype: List[Dict[str, object]] :rtype: List[Dict[str, object]]
""" """
return tosca_template_service.get_tosca_template_model_by_id(id).dsl_definitions res = tosca_template_service.get_tosca_template_model_by_id(id).dsl_definitions
if res:
return res
return 'Not Found', 404
def get_imports(id): # noqa: E501 def get_imports(id): # noqa: E501
...@@ -80,7 +92,10 @@ def get_imports(id): # noqa: E501 ...@@ -80,7 +92,10 @@ def get_imports(id): # noqa: E501
:rtype: List[Dict[str, object]] :rtype: List[Dict[str, object]]
""" """
return tosca_template_service.get_tosca_template_model_by_id(id).imports res = tosca_template_service.get_tosca_template_model_by_id(id).imports
if res:
return res
return 'Not Found', 404
def get_node_outputs(id, node_name): # noqa: E501 def get_node_outputs(id, node_name): # noqa: E501
...@@ -95,7 +110,10 @@ def get_node_outputs(id, node_name): # noqa: E501 ...@@ -95,7 +110,10 @@ def get_node_outputs(id, node_name): # noqa: E501
:rtype: Dict[str, object] :rtype: Dict[str, object]
""" """
return tosca_template_service.get_node_outputs(id, node_name) res = tosca_template_service.get_node_outputs(id, node_name)
if res:
return res
return 'Not Found', 404
def get_node_properties(id, node_name): # noqa: E501 def get_node_properties(id, node_name): # noqa: E501
...@@ -110,7 +128,10 @@ def get_node_properties(id, node_name): # noqa: E501 ...@@ -110,7 +128,10 @@ def get_node_properties(id, node_name): # noqa: E501
:rtype: Dict[str, object] :rtype: Dict[str, object]
""" """
return tosca_template_service.get_node_properties(id, node_name) res = tosca_template_service.get_node_properties(id, node_name)
if res:
return res
return 'Not Found', 404
def get_node_requirements(id, node_name): # noqa: E501 def get_node_requirements(id, node_name): # noqa: E501
...@@ -125,10 +146,15 @@ def get_node_requirements(id, node_name): # noqa: E501 ...@@ -125,10 +146,15 @@ def get_node_requirements(id, node_name): # noqa: E501
:rtype: Dict[str, object] :rtype: Dict[str, object]
""" """
return tosca_template_service.get_node_requirements(id, node_name) res = tosca_template_service.get_node_requirements(id, node_name)
if res:
return res
return 'Not Found', 404
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 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 """get_node_templates
returns nodes templates in topology # noqa: E501 returns nodes templates in topology # noqa: E501
...@@ -156,11 +182,14 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, ...@@ -156,11 +182,14 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None,
:rtype: List[NodeTemplate] :rtype: List[NodeTemplate]
""" """
return 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,
has_attributes=has_attributes, has_requirements=has_requirements, has_attributes=has_attributes, has_requirements=has_requirements,
has_capabilities=has_capabilities, has_artifacts=has_artifacts, has_capabilities=has_capabilities, has_artifacts=has_artifacts,
derived_from=derived_from) derived_from=derived_from)
if res:
return res
return 'Not Found', 404
def get_node_type_name(id, node_name): # noqa: E501 def get_node_type_name(id, node_name): # noqa: E501
...@@ -175,7 +204,10 @@ def get_node_type_name(id, node_name): # noqa: E501 ...@@ -175,7 +204,10 @@ def get_node_type_name(id, node_name): # noqa: E501
:rtype: str :rtype: str
""" """
return tosca_template_service.get_node_type_name(id, node_name) res = tosca_template_service.get_node_type_name(id, node_name)
if res:
return res
return 'Not Found', 404
def get_parent_type_name(id, node_name): # noqa: E501 def get_parent_type_name(id, node_name): # noqa: E501
...@@ -190,7 +222,10 @@ def get_parent_type_name(id, node_name): # noqa: E501 ...@@ -190,7 +222,10 @@ def get_parent_type_name(id, node_name): # noqa: E501
:rtype: str :rtype: str
""" """
return tosca_template_service.get_parent_type_name(id, node_name) res = tosca_template_service.get_parent_type_name(id, node_name)
if res:
return res
return 'Not Found', 404
def get_related_nodes(id, node_name): # noqa: E501 def get_related_nodes(id, node_name): # noqa: E501
...@@ -205,7 +240,10 @@ def get_related_nodes(id, node_name): # noqa: E501 ...@@ -205,7 +240,10 @@ def get_related_nodes(id, node_name): # noqa: E501
:rtype: List[NodeTemplate] :rtype: List[NodeTemplate]
""" """
return tosca_template_service.get_related_nodes(id, node_name) res = tosca_template_service.get_related_nodes(id, node_name)
if res:
return res
return 'Not Found', 404
def get_relationship_templates(id, type_name=None, derived_from=None): # noqa: E501 def get_relationship_templates(id, type_name=None, derived_from=None): # noqa: E501
...@@ -222,7 +260,10 @@ def get_relationship_templates(id, type_name=None, derived_from=None): # noqa: ...@@ -222,7 +260,10 @@ def get_relationship_templates(id, type_name=None, derived_from=None): # noqa:
:rtype: List[Dict[str, object]] :rtype: List[Dict[str, object]]
""" """
return tosca_template_service.get_relationship_templates(id, type_name=type_name, derived_from=derived_from) res = tosca_template_service.get_relationship_templates(id, type_name=type_name, derived_from=derived_from)
if res:
return res
return 'Not Found', 404
def get_topology_template(id): # noqa: E501 def get_topology_template(id): # noqa: E501
...@@ -233,9 +274,12 @@ def get_topology_template(id): # noqa: E501 ...@@ -233,9 +274,12 @@ def get_topology_template(id): # noqa: E501
:param id: ID of topolog template uplodaed :param id: ID of topolog template uplodaed
:type id: str :type id: str
:rtype: TopologyTemplate :rtype: TopologyTemplateModel
""" """
return tosca_template_service.get_tosca_template_dict_by_id(id) res = tosca_template_service.get_tosca_template_model_by_id(id).topology_template
if res:
return res
return 'Not Found', 404
def get_tosca_template(id): # noqa: E501 def get_tosca_template(id): # noqa: E501
...@@ -246,12 +290,16 @@ def get_tosca_template(id): # noqa: E501 ...@@ -246,12 +290,16 @@ def get_tosca_template(id): # noqa: E501
:param id: ID of topolog template uplodaed :param id: ID of topolog template uplodaed
:type id: str :type id: str
:rtype: ToscaTemplate :rtype: ToscaTemplateModel
""" """
return tosca_template_service.get_tosca_template_model_by_id(id) res = tosca_template_service.get_tosca_template_model_by_id(id)
if res:
return res
return 'Not Found', 404
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 returns the interface types # noqa: E501
...@@ -279,11 +327,14 @@ def get_types(id, kind_of_type=None, has_interfaces=None, type_name=None, has_pr ...@@ -279,11 +327,14 @@ def get_types(id, kind_of_type=None, has_interfaces=None, type_name=None, has_pr
:rtype: List[Dict[str, object]] :rtype: List[Dict[str, object]]
""" """
return tosca_template_service.get_types(id, kind_of_type=kind_of_type, has_interfaces=has_interfaces, res = tosca_template_service.get_types(id, kind_of_type=kind_of_type, has_interfaces=has_interfaces,
type_name=type_name, has_properties=has_properties, type_name=type_name, has_properties=has_properties,
has_attributes=has_attributes, has_requirements=has_requirements, has_attributes=has_attributes, has_requirements=has_requirements,
has_capabilities=has_capabilities, has_artifacts=has_artifacts, has_capabilities=has_capabilities, has_artifacts=has_artifacts,
derived_from=derived_from) derived_from=derived_from)
if res:
return res
return 'Not Found', 404
def set_node_properties(id, properties, node_name): # noqa: E501 def set_node_properties(id, properties, node_name): # noqa: E501
...@@ -298,9 +349,12 @@ def set_node_properties(id, properties, node_name): # noqa: E501 ...@@ -298,9 +349,12 @@ def set_node_properties(id, properties, node_name): # noqa: E501
:param node_name: node_name :param node_name: node_name
:type node_name: str :type node_name: str
:rtype: NodeTemplate :rtype: NodeTemplateModel
""" """
return tosca_template_service.set_node_properties(id, properties, node_name) res = tosca_template_service.set_node_properties(id, properties, node_name)
if res:
return res
return 'Not Found', 404
def upload_tosca_template(file): # noqa: E501 def upload_tosca_template(file): # noqa: E501
...@@ -313,4 +367,7 @@ def upload_tosca_template(file): # noqa: E501 ...@@ -313,4 +367,7 @@ def upload_tosca_template(file): # noqa: E501
:rtype: str :rtype: str
""" """
return tosca_template_service.save(file) res = tosca_template_service.save(file)
if res:
return res
return 'Bad Request', 400
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
# flake8: noqa # flake8: noqa
from __future__ import absolute_import from __future__ import absolute_import
# import models into model package # import models into model package
from sure_tosca.models.node_template import NodeTemplate from sure_tosca.models.node_template import NodeTemplateModel
from sure_tosca.models.topology_template import TopologyTemplate from sure_tosca.models.topology_template import TopologyTemplateModel
from sure_tosca.models.tosca_template import ToscaTemplate from sure_tosca.models.tosca_template import ToscaTemplateModel
...@@ -9,7 +9,7 @@ from sure_tosca.models.base_model_ import Model ...@@ -9,7 +9,7 @@ from sure_tosca.models.base_model_ import Model
from sure_tosca import util from sure_tosca import util
class NodeTemplate(Model): class NodeTemplateModel(Model):
"""NOTE: This class is auto generated by the swagger code generator program. """NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually. Do not edit the class manually.
...@@ -84,7 +84,7 @@ class NodeTemplate(Model): ...@@ -84,7 +84,7 @@ class NodeTemplate(Model):
:param dikt: A dict. :param dikt: A dict.
:type: dict :type: dict
:return: The NodeTemplate of this NodeTemplate. # noqa: E501 :return: The NodeTemplate of this NodeTemplate. # noqa: E501
:rtype: NodeTemplate :rtype: NodeTemplateModel
""" """
return util.deserialize_model(dikt, cls) return util.deserialize_model(dikt, cls)
......
...@@ -5,12 +5,12 @@ from datetime import date, datetime # noqa: F401 ...@@ -5,12 +5,12 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401 from typing import List, Dict # noqa: F401
from sure_tosca.models import NodeTemplate from sure_tosca.models import NodeTemplateModel
from sure_tosca.models.base_model_ import Model from sure_tosca.models.base_model_ import Model
from sure_tosca import util from sure_tosca import util
class TopologyTemplate(Model): class TopologyTemplateModel(Model):
"""NOTE: This class is auto generated by the swagger code generator program. """NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually. Do not edit the class manually.
...@@ -24,11 +24,11 @@ class TopologyTemplate(Model): ...@@ -24,11 +24,11 @@ class TopologyTemplate(Model):
:param inputs: The inputs of this TopologyTemplate. # noqa: E501 :param inputs: The inputs of this TopologyTemplate. # noqa: E501
:type inputs: List[Dict[str, object]] :type inputs: List[Dict[str, object]]
:param node_templates: The node_templates of this TopologyTemplate. # noqa: E501 :param node_templates: The node_templates of this TopologyTemplate. # noqa: E501
:type node_templates: Dict[str, NodeTemplate] :type node_templates: Dict[str, NodeTemplateModel]
:param relationship_templates: The relationship_templates of this TopologyTemplate. # noqa: E501 :param relationship_templates: The relationship_templates of this TopologyTemplate. # noqa: E501
:type relationship_templates: Dict[str, object] :type relationship_templates: Dict[str, object]
:param outputs: The outputs of this TopologyTemplate. # noqa: E501 :param outputs: The outputs of this TopologyTemplate. # noqa: E501
:type outputs: str :type outputs: Dict[str, object]
:param groups: The groups of this TopologyTemplate. # noqa: E501 :param groups: The groups of this TopologyTemplate. # noqa: E501
:type groups: Dict[str, object] :type groups: Dict[str, object]
:param substitution_mappings: The substitution_mappings of this TopologyTemplate. # noqa: E501 :param substitution_mappings: The substitution_mappings of this TopologyTemplate. # noqa: E501
...@@ -39,9 +39,9 @@ class TopologyTemplate(Model): ...@@ -39,9 +39,9 @@ class TopologyTemplate(Model):
self.swagger_types = { self.swagger_types = {
'description': str, 'description': str,
'inputs': List[Dict[str, object]], 'inputs': List[Dict[str, object]],
'node_templates': Dict[str, NodeTemplate], 'node_templates': Dict[str, NodeTemplateModel],
'relationship_templates': Dict[str, object], 'relationship_templates': Dict[str, object],
'outputs': str, 'outputs': Dict[str, object],
'groups': Dict[str, object], 'groups': Dict[str, object],
'substitution_mappings': Dict[str, object], 'substitution_mappings': Dict[str, object],
'policies': List[Dict[str, object]] 'policies': List[Dict[str, object]]
...@@ -74,7 +74,7 @@ class TopologyTemplate(Model): ...@@ -74,7 +74,7 @@ class TopologyTemplate(Model):
:param dikt: A dict. :param dikt: A dict.
:type: dict :type: dict
:return: The TopologyTemplate of this TopologyTemplate. # noqa: E501 :return: The TopologyTemplate of this TopologyTemplate. # noqa: E501
:rtype: TopologyTemplate :rtype: TopologyTemplateModel
""" """
return util.deserialize_model(dikt, cls) return util.deserialize_model(dikt, cls)
...@@ -126,7 +126,7 @@ class TopologyTemplate(Model): ...@@ -126,7 +126,7 @@ class TopologyTemplate(Model):
:return: The node_templates of this TopologyTemplate. :return: The node_templates of this TopologyTemplate.
:rtype: Dict[str, NodeTemplate] :rtype: Dict[str, NodeTemplateModel]
""" """
return self._node_templates return self._node_templates
...@@ -136,7 +136,7 @@ class TopologyTemplate(Model): ...@@ -136,7 +136,7 @@ class TopologyTemplate(Model):
:param node_templates: The node_templates of this TopologyTemplate. :param node_templates: The node_templates of this TopologyTemplate.
:type node_templates: Dict[str, NodeTemplate] :type node_templates: Dict[str, NodeTemplateModel]
""" """
self._node_templates = node_templates self._node_templates = node_templates
...@@ -247,6 +247,6 @@ class TopologyTemplate(Model): ...@@ -247,6 +247,6 @@ class TopologyTemplate(Model):
self._policies = policies self._policies = policies
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, TopologyTemplate): if isinstance(other, TopologyTemplateModel):
return self.__key() == other.__key() return self.__key() == other.__key()
return NotImplemented return NotImplemented
\ No newline at end of file
...@@ -5,12 +5,12 @@ from datetime import date, datetime # noqa: F401 ...@@ -5,12 +5,12 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401 from typing import List, Dict # noqa: F401
from sure_tosca.models import TopologyTemplate from sure_tosca.models import TopologyTemplateModel
from sure_tosca.models.base_model_ import Model from sure_tosca.models.base_model_ import Model
from sure_tosca import util from sure_tosca import util
class ToscaTemplate(Model): class ToscaTemplateModel(Model):
"""NOTE: This class is auto generated by the swagger code generator program. """NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually. Do not edit the class manually.
...@@ -30,7 +30,7 @@ class ToscaTemplate(Model): ...@@ -30,7 +30,7 @@ class ToscaTemplate(Model):
:param template_name: The template_name of this ToscaTemplate. # noqa: E501 :param template_name: The template_name of this ToscaTemplate. # noqa: E501
:type template_name: str :type template_name: str
:param topology_template: The topology_template of this ToscaTemplate. # noqa: E501 :param topology_template: The topology_template of this ToscaTemplate. # noqa: E501
:type topology_template: TopologyTemplate :type topology_template: TopologyTemplateModel
:param template_author: The template_author of this ToscaTemplate. # noqa: E501 :param template_author: The template_author of this ToscaTemplate. # noqa: E501
:type template_author: str :type template_author: str
:param template_version: The template_version of this ToscaTemplate. # noqa: E501 :param template_version: The template_version of this ToscaTemplate. # noqa: E501
...@@ -66,7 +66,7 @@ class ToscaTemplate(Model): ...@@ -66,7 +66,7 @@ class ToscaTemplate(Model):
'tosca_definitions_version': str, 'tosca_definitions_version': str,
'tosca_default_namespace': str, 'tosca_default_namespace': str,
'template_name': str, 'template_name': str,
'topology_template': TopologyTemplate, 'topology_template': TopologyTemplateModel,
'template_author': str, 'template_author': str,
'template_version': str, 'template_version': str,
'description': str, 'description': str,
...@@ -133,7 +133,7 @@ class ToscaTemplate(Model): ...@@ -133,7 +133,7 @@ class ToscaTemplate(Model):
:param dikt: A dict. :param dikt: A dict.
:type: dict :type: dict
:return: The ToscaTemplate of this ToscaTemplate. # noqa: E501 :return: The ToscaTemplate of this ToscaTemplate. # noqa: E501
:rtype: ToscaTemplate :rtype: ToscaTemplateModel
""" """
return util.deserialize_model(dikt, cls) return util.deserialize_model(dikt, cls)
...@@ -206,7 +206,7 @@ class ToscaTemplate(Model): ...@@ -206,7 +206,7 @@ class ToscaTemplate(Model):
:return: The topology_template of this ToscaTemplate. :return: The topology_template of this ToscaTemplate.
:rtype: TopologyTemplate :rtype: TopologyTemplateModel
""" """
return self._topology_template return self._topology_template
...@@ -216,7 +216,7 @@ class ToscaTemplate(Model): ...@@ -216,7 +216,7 @@ class ToscaTemplate(Model):
:param topology_template: The topology_template of this ToscaTemplate. :param topology_template: The topology_template of this ToscaTemplate.
:type topology_template: TopologyTemplate :type topology_template: TopologyTemplateModel
""" """
self._topology_template = topology_template self._topology_template = topology_template
...@@ -537,6 +537,6 @@ class ToscaTemplate(Model): ...@@ -537,6 +537,6 @@ class ToscaTemplate(Model):
self._repositories = repositories self._repositories = repositories
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, ToscaTemplate): if isinstance(other, ToscaTemplateModel):
return self.__key() == other.__key() return self.__key() == other.__key()
return NotImplemented return NotImplemented
...@@ -108,13 +108,13 @@ def get_node_types_with_interface(nodes): ...@@ -108,13 +108,13 @@ def get_node_types_with_interface(nodes):
def node_dict_2_node_template(node_dict, all_custom_def): def node_dict_2_node_template(node_dict, all_custom_def):
node_name = next(iter(node_dict)) node_name = next(iter(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:
# if name_to_remove in node_dict[node_name][node_name]: # if name_to_remove in node_dict[node_name][node_name]:
# node_dict[node_name].pop(name_to_remove) # node_dict[node_name].pop(name_to_remove)
node_template = NodeTemplate(node_name, node_templates=node_dict, custom_def=all_custom_def) node_template = NodeTemplate(node_name, node_templates=copy.deepcopy(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 # 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" # manually. We get 'toscaparser.common.exception.InvalidTypeError: Type "tosca.nodes.ARTICONF.Orchestrator"
# is not a valid type.' # is not a valid type.'
......
import json import json
import logging
import os import os
import sys import tempfile
import uuid import uuid
from collections import defaultdict from functools import reduce
import copy
import yaml import yaml
from tinydb.database import Document from tinydb import TinyDB, Query
from tinydb.middlewares import CachingMiddleware from tinydb.middlewares import CachingMiddleware
from tinydb.storages import MemoryStorage
from toscaparser.functions import GetAttribute from toscaparser.functions import GetAttribute
from typing import re 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 NodeTemplate as NodeTemplateModel from sure_tosca.models.node_template import NodeTemplateModel as NodeTemplateModel
from sure_tosca.models.topology_template import TopologyTemplate as TopologyTemplateModel from sure_tosca.models.tosca_template import ToscaTemplateModel as ToscaTemplateModel
from sure_tosca.models.tosca_template import ToscaTemplate as ToscaTemplateModel
from sure_tosca import util
from tinydb import TinyDB, Query
import tempfile
from toscaparser.nodetemplate import NodeTemplate
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.topology_template import TopologyTemplate
from toscaparser.parameters import Output
from tinydb.storages import MemoryStorage
from functools import reduce
from sure_tosca.service import tosca_helper from sure_tosca.service import tosca_helper
import logging
# db = TinyDB(storage=CachingMiddleware(MemoryStorage)) # db = TinyDB(storage=CachingMiddleware(MemoryStorage))
db_dir_path = tempfile.gettempdir() db_dir_path = tempfile.gettempdir()
...@@ -37,7 +29,6 @@ dsl_definitions_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) ...@@ -37,7 +29,6 @@ dsl_definitions_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
relationship_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) relationship_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
interface_types_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) interface_types_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
model_id_names = ['id']
root_key = 'root_key' root_key = 'root_key'
...@@ -57,54 +48,46 @@ def query_db(queries, db=None): ...@@ -57,54 +48,46 @@ def query_db(queries, db=None):
node = res node = res
updated_results.append(node) updated_results.append(node)
return updated_results return updated_results
return 'Not Found', 404 return None
def get_tosca_template_model_by_id(id): def get_tosca_template_model_by_id(id):
tosca_template_dict = get_tosca_template_dict_by_id(id) tosca_template_dict = get_tosca_template_dict_by_id(id)
tosca_template_model = ToscaTemplateModel.from_dict(tosca_template_dict) tosca_template_model = ToscaTemplateModel.from_dict(tosca_template_dict)
tosca_template_dict = deTOSCAfy_topology_template(tosca_template_dict) # tosca_template_dict = deTOSCAfy_topology_template(tosca_template_dict)
if tosca_template_dict: if tosca_template_dict:
get_tosca_template(tosca_template_dict) get_tosca_template(tosca_template_dict)
return tosca_template_model return tosca_template_model
return 'Not Found', 404 return None
def get_tosca_template(tosca_template_dict): def get_tosca_template(tosca_template_dict):
return ToscaTemplate(yaml_dict_tpl=tosca_template_dict) return ToscaTemplate(yaml_dict_tpl=copy.deepcopy(tosca_template_dict))
def get_tosca_template_dict_by_id(id): def get_tosca_template_dict_by_id(id):
query = Query() tosca_template_dict = tosca_templates_db.get(doc_id=int(id))
tosca_template_list_dict = tosca_templates_db.search(query.id == id) return tosca_template_dict
if tosca_template_list_dict:
tosca_template_dict = tosca_template_list_dict[0]
for id_name in model_id_names: # def deTOSCAfy_topology_template(dictionary):
if id_name in tosca_template_dict: # # outputs out of nowhere is instantiated as GetAttribute or str
tosca_template_dict.pop(id_name) # if 'outputs' in dictionary['topology_template']:
break # outputs = dictionary['topology_template']['outputs']
return deTOSCAfy_topology_template(tosca_template_dict) # if isinstance(outputs, str):
return 'Not Found', 404 # json_acceptable_string = outputs.replace("'", "\"")
# d = json.loads(json_acceptable_string)
# outputs = d
def deTOSCAfy_topology_template(dictionary): # if not isinstance(outputs, dict):
# outputs out of nowhere is instantiated as GetAttribute # for output_name in outputs:
if 'outputs' in dictionary['topology_template']: # output = outputs[output_name]
outputs = dictionary['topology_template']['outputs'] # if isinstance(output['value'], GetAttribute):
if isinstance(outputs,str): # args = output['value'].args
json_acceptable_string = outputs.replace("'", "\"") # assert isinstance(args, list)
d = json.loads(json_acceptable_string) # output['value'] = {'get_attribute': args}
outputs = d # dictionary['topology_template']['outputs'] = outputs
elif not isinstance(outputs,dict): #
for output_name in outputs: # return dictionary
output = outputs[output_name]
if isinstance(output['value'], GetAttribute):
args = output['value'].args
assert isinstance(args, list)
output['value'] = {'get_attribute': args}
dictionary['topology_template']['outputs'] = outputs
return dictionary
def save(file): def save(file):
...@@ -112,16 +95,9 @@ def save(file): ...@@ -112,16 +95,9 @@ def save(file):
# tosca_template_file_path = os.path.join(db_dir_path, file.filename) # tosca_template_file_path = os.path.join(db_dir_path, file.filename)
dictionary = yaml.safe_load(file.stream) dictionary = yaml.safe_load(file.stream)
tosca_template = ToscaTemplate(yaml_dict_tpl=dictionary) tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary))
dictionary = deTOSCAfy_topology_template(dictionary)
tosca_template_model = ToscaTemplateModel.from_dict(dictionary) tosca_template_model = ToscaTemplateModel.from_dict(dictionary)
doc_id = str(uuid.uuid4()) doc_id = tosca_templates_db.insert(dictionary)
tosca_template_dict_with_id = {model_id_names[0]: doc_id}
tosca_template_dict_with_id.update(tosca_template_model.to_dict())
tosca_templates_db.insert(tosca_template_dict_with_id)
# tosca_templates_db.close() # tosca_templates_db.close()
return doc_id return doc_id
except Exception as e: except Exception as e:
...@@ -147,8 +123,6 @@ def get_interface_types(id, interface_type=None): ...@@ -147,8 +123,6 @@ def get_interface_types(id, interface_type=None):
def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, has_properties=None, def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, has_properties=None,
has_attributes=None, has_attributes=None,
has_requirements=None, has_capabilities=None, has_artifacts=None, derived_from=None): has_requirements=None, has_capabilities=None, has_artifacts=None, derived_from=None):
# tmp_db.purge()
if len(node_template_db) <= 1: if len(node_template_db) <= 1:
tosca_template_model = get_tosca_template_model_by_id(id) tosca_template_model = get_tosca_template_model_by_id(id)
object_list = tosca_template_model.topology_template.node_templates object_list = tosca_template_model.topology_template.node_templates
...@@ -252,6 +226,8 @@ def get_relationship_templates(id, type_name=None, derived_from=None): ...@@ -252,6 +226,8 @@ def get_relationship_templates(id, type_name=None, derived_from=None):
def node_dict_2_node_template(id, node_name): def node_dict_2_node_template(id, node_name):
tosca_template_dict = get_tosca_template_dict_by_id(id) tosca_template_dict = get_tosca_template_dict_by_id(id)
if tosca_template_dict is None:
return None
tosca_template = get_tosca_template(tosca_template_dict) tosca_template = get_tosca_template(tosca_template_dict)
tosca_node_types = tosca_template.nodetemplates[0].type_definition.TOSCA_DEF tosca_node_types = tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
all_custom_def = tosca_template.nodetemplates[0].custom_def all_custom_def = tosca_template.nodetemplates[0].custom_def
...@@ -260,22 +236,29 @@ def node_dict_2_node_template(id, node_name): ...@@ -260,22 +236,29 @@ def node_dict_2_node_template(id, node_name):
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_dict = get_node_templates(id, node_name=node_name)[0]
node_template_dict = {node_name: node_template_dict}
if next(iter(node_template_dict)) != node_name:
node_template_dict = {node_name: node_template_dict}
if isinstance(node_template_dict, dict): if isinstance(node_template_dict, dict):
the_node = tosca_helper.node_dict_2_node_template(node_template_dict, all_node_types) 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 return None
def get_all_ancestors_requirements(id, node_root_key): def get_all_ancestors_requirements(id, node_root_key):
the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key) try:
the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key)
except Exception as e:
return None
parent_requirements = tosca_helper.get_all_ancestors_requirements(the_node, all_node_types, all_custom_def) parent_requirements = tosca_helper.get_all_ancestors_requirements(the_node, all_node_types, all_custom_def)
return parent_requirements return parent_requirements
def get_all_ancestor_properties(id, node_root_key): def get_all_ancestor_properties(id, node_root_key):
the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key) try:
the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key)
except Exception as e:
return None
properties = tosca_helper.get_all_ancestors_properties(the_node, all_node_types, all_custom_def) properties = tosca_helper.get_all_ancestors_properties(the_node, all_node_types, all_custom_def)
properties_list = [] properties_list = []
for prop in properties: for prop in properties:
...@@ -288,7 +271,7 @@ def get_all_ancestor_types(id, node_root_key): ...@@ -288,7 +271,7 @@ def get_all_ancestor_types(id, node_root_key):
try: try:
the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key) the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key)
except Exception as e: except Exception as e:
return 'Not Found', 404 return None
all_ancestor_types = tosca_helper.get_all_ancestors_types(the_node, all_node_types, all_custom_def) all_ancestor_types = tosca_helper.get_all_ancestors_types(the_node, all_node_types, all_custom_def)
return all_ancestor_types return all_ancestor_types
...@@ -297,21 +280,21 @@ def get_parent_type_name(id, node_root_key): ...@@ -297,21 +280,21 @@ def get_parent_type_name(id, node_root_key):
try: try:
the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key) the_node, all_node_types, all_custom_def = node_dict_2_node_template(id, node_root_key)
except Exception as e: except Exception as e:
return 'Not Found', 404 return None
return tosca_helper.get_parent_type(the_node) return tosca_helper.get_parent_type(the_node)
def get_node_outputs(id, node_nme): def get_node_outputs(id, node_name):
matching_outputs = {} matching_outputs = {}
matching_output_names = [] matching_output_names = []
tosca_template_dict = get_tosca_template_dict_by_id(id) tosca_template_dict = get_tosca_template_dict_by_id(id)
tosca_template = get_tosca_template(tosca_template_dict) tosca_template = get_tosca_template(tosca_template_dict)
outputs = tosca_template.topology_template.outputs outputs = tosca_template.topology_template.outputs
for output in outputs: for output in outputs:
if node_nme == output.value.node_template_name: if node_name == output.value.node_template_name:
matching_output_names.append(output.name) matching_output_names.append(output.name)
tosca_template_dict = deTOSCAfy_topology_template(tosca_template_dict) # tosca_template_dict = deTOSCAfy_topology_template(tosca_template_dict)
tosca_template_model = ToscaTemplateModel.from_dict(tosca_template_dict) tosca_template_model = ToscaTemplateModel.from_dict(tosca_template_dict)
for matching_output_name in matching_output_names: for matching_output_name in matching_output_names:
matching_outputs[matching_output_name] = tosca_template_model.topology_template.outputs[matching_output_name] matching_outputs[matching_output_name] = tosca_template_model.topology_template.outputs[matching_output_name]
...@@ -327,7 +310,7 @@ def get_node_properties(id, node_name): ...@@ -327,7 +310,7 @@ def get_node_properties(id, node_name):
properties = NodeTemplateModel.from_dict(node_template_dict).properties properties = NodeTemplateModel.from_dict(node_template_dict).properties
if properties: if properties:
return properties return properties
return 'Not Found', 404 return None
def get_node_requirements(id, node_name): def get_node_requirements(id, node_name):
...@@ -338,7 +321,7 @@ def get_node_requirements(id, node_name): ...@@ -338,7 +321,7 @@ def get_node_requirements(id, node_name):
requirements = NodeTemplateModel.from_dict(node_template_dict).requirements requirements = NodeTemplateModel.from_dict(node_template_dict).requirements
if requirements: if requirements:
return requirements return requirements
return 'Not Found', 404 return None
def get_related_nodes(id, node_name): def get_related_nodes(id, node_name):
...@@ -366,11 +349,11 @@ def get_node_type_name(id, node_name): ...@@ -366,11 +349,11 @@ def get_node_type_name(id, node_name):
type_name = NodeTemplateModel.from_dict(node_template_dict).type type_name = NodeTemplateModel.from_dict(node_template_dict).type
if type_name: if type_name:
return type_name return type_name
return 'Not Found', 404 return None
def set_node_properties(id, properties, node_name): def set_node_properties(id, properties, node_name):
node_template_dict = get_node_templates(id, node_name=node_name)[0] node_template_dict = get_node_templates(id, node_name=node_name)[0]
if node_name in node_template_dict: if node_name in node_template_dict:
node_template_dict = node_template_dict[node_name] node_template_dict = node_template_dict[node_name]
return None return None
\ No newline at end of file
...@@ -5,9 +5,9 @@ from __future__ import absolute_import ...@@ -5,9 +5,9 @@ from __future__ import absolute_import
from flask import json from flask import json
from six import BytesIO from six import BytesIO
from sure_tosca.models.node_template import NodeTemplate # noqa: E501 from sure_tosca.models.node_template import NodeTemplateModel # noqa: E501
from sure_tosca.models.topology_template import TopologyTemplate # noqa: E501 from sure_tosca.models.topology_template import TopologyTemplateModel # noqa: E501
from sure_tosca.models.tosca_template import ToscaTemplate # noqa: E501 from sure_tosca.models.tosca_template import ToscaTemplateModel # noqa: E501
from sure_tosca.test import BaseTestCase from sure_tosca.test import BaseTestCase
......
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