Skip to content

Commit

Permalink
Update Tosca to use imports in all the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Feb 15, 2016
1 parent e5f8878 commit 40a967f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
47 changes: 1 addition & 46 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,10 @@
import urllib

from IM.uriparse import uriparse
import toscaparser.imports
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.elements.interfaces import InterfacesDef
from toscaparser.elements.entity_type import EntityType
from toscaparser.functions import Function, is_function, get_function, GetAttribute
from IM.radl.radl import system, deploy, network, Feature, configure, contextualize_item, RADL, contextualize
from toscaparser.utils.yamlparser import load_yaml

class IndigoToscaTemplate(ToscaTemplate):

CUSTOM_TYPES_FILE = os.path.dirname(os.path.realpath(__file__)) + "/tosca-types/custom_types.yaml"

def __init__(self, path, parsed_params=None, a_file=True):
# Load custom data
custom_def = load_yaml(self.CUSTOM_TYPES_FILE)
# and update tosca_def with the data
EntityType.TOSCA_DEF.update(custom_def)

super(IndigoToscaTemplate, self).__init__(path, parsed_params, a_file)

def _get_custom_types(self, type_definitions, imports=None):
"""Handle custom types defined in imported template files
This method loads the custom type definitions referenced in "imports"
section of the TOSCA YAML template.
"""

custom_defs = {}
type_defs = []
if not isinstance(type_definitions, list):
type_defs.append(type_definitions)
else:
type_defs = type_definitions

if not imports:
imports = self._tpl_imports()

if imports:
custom_defs = toscaparser.imports.\
ImportsLoader(imports, self.path,
type_defs).get_custom_defs()

# Handle custom types defined in current template file
for type_def in type_defs:
if type_def != "imports":
inner_custom_types = self.tpl.get(type_def) or {}
if inner_custom_types:
custom_defs.update(inner_custom_types)
return custom_defs

class Tosca:
"""
Expand All @@ -75,7 +30,7 @@ def __init__(self, yaml_str):
with tempfile.NamedTemporaryFile(suffix=".yaml") as f:
f.write(yaml_str)
f.flush()
self.tosca = IndigoToscaTemplate(f.name)
self.tosca = ToscaTemplate(f.name)

def to_radl(self, inf_info = None):
"""
Expand Down

0 comments on commit 40a967f

Please sign in to comment.