summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/imports.py
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2016-06-05 01:37:11 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2016-06-05 01:43:32 +0800
commita17eab054e89552cfafdad1b0f45d5a613cc2ba6 (patch)
treef9f73035d7d6b2275c39f1f106cbd8e792298851 /tosca2heat/tosca-parser/toscaparser/imports.py
parent920592786aabee78752cf35a293a74151b9f3c8b (diff)
tosco-parser supports importing the other service with
topology template As a tosca-parser developer; I want to implement the function of substitution_mapping; So that must support the import topology template firstly Change-Id: Ie26aab712e7870e1ec345ad654460bb84014f207 JIRA: PARSER-48 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/imports.py')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/imports.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/imports.py b/tosca2heat/tosca-parser/toscaparser/imports.py
index 5149382..62748bd 100644
--- a/tosca2heat/tosca-parser/toscaparser/imports.py
+++ b/tosca2heat/tosca-parser/toscaparser/imports.py
@@ -36,6 +36,7 @@ class ImportsLoader(object):
tpl=None):
self.importslist = importslist
self.custom_defs = {}
+ self.nested_topo_tpls = []
if not path and not tpl:
msg = _('Input tosca template is not provided.')
log.warning(msg)
@@ -55,6 +56,9 @@ class ImportsLoader(object):
def get_custom_defs(self):
return self.custom_defs
+ def get_nested_topo_tpls(self):
+ return self.nested_topo_tpls
+
def _validate_and_load_imports(self):
imports_names = set()
@@ -76,8 +80,8 @@ class ImportsLoader(object):
ValidationError(message=msg))
imports_names.add(import_name)
- custom_type = self._load_import_template(import_name,
- import_uri)
+ full_file_name, custom_type = self._load_import_template(
+ import_name, import_uri)
namespace_prefix = None
if isinstance(import_uri, dict):
namespace_prefix = import_uri.get(
@@ -86,13 +90,15 @@ class ImportsLoader(object):
TypeValidation(custom_type, import_def)
self._update_custom_def(custom_type, namespace_prefix)
else: # old style of imports
- custom_type = self._load_import_template(None,
- import_def)
+ full_file_name, custom_type = self._load_import_template(
+ None, import_def)
if custom_type:
TypeValidation(
custom_type, import_def)
self._update_custom_def(custom_type, None)
+ self._update_nested_topo_tpls(full_file_name, custom_type)
+
def _update_custom_def(self, custom_type, namespace_prefix):
outer_custom_types = {}
for type_def in self.type_definition_list:
@@ -112,6 +118,11 @@ class ImportsLoader(object):
else:
self.custom_defs.update(outer_custom_types)
+ def _update_nested_topo_tpls(self, full_file_name, custom_tpl):
+ if full_file_name and custom_tpl:
+ topo_tpl = {full_file_name: custom_tpl}
+ self.nested_topo_tpls.append(topo_tpl)
+
def _validate_import_keys(self, import_name, import_uri_def):
if self.FILE not in import_uri_def.keys():
log.warning(_('Missing keyname "file" in import "%(name)s".')
@@ -170,7 +181,7 @@ class ImportsLoader(object):
return
if toscaparser.utils.urlutils.UrlUtils.validate_url(file_name):
- return YAML_LOADER(file_name, False)
+ return file_name, YAML_LOADER(file_name, False)
elif not repository:
import_template = None
if self.path:
@@ -234,7 +245,7 @@ class ImportsLoader(object):
ImportError(_('Import "%s" is not valid.') %
import_uri_def))
return
- return YAML_LOADER(import_template, a_file)
+ return import_template, YAML_LOADER(import_template, a_file)
if short_import_notation:
log.error(_('Import "%(name)s" is not valid.') % import_uri_def)
@@ -261,7 +272,7 @@ class ImportsLoader(object):
return
if toscaparser.utils.urlutils.UrlUtils.validate_url(full_url):
- return YAML_LOADER(full_url, False)
+ return full_url, YAML_LOADER(full_url, False)
else:
msg = (_('repository url "%(n_uri)s" is not valid in import '
'definition "%(tpl)s".')