コード例 #1
0
    def validate_tosca(self, template):
        if "tosca_definitions_version" not in template:
            raise meo.ToscaParserFailed(
                error_msg_details='tosca_definitions_version missing in '
                'template')

        LOG.debug('template yaml: %s', template)

        toscautils.updateimports(template)

        try:
            tosca_template.ToscaTemplate(a_file=False, yaml_dict_tpl=template)
        except Exception as e:
            LOG.exception("tosca-parser error: %s", str(e))
            raise meo.ToscaParserFailed(error_msg_details=str(e))
コード例 #2
0
    def _parse_template_input(self, context, mesd):
        mesd_dict = mesd['mesd']
        mesd_yaml = mesd_dict['attributes'].get('mesd')
        inner_mesd_dict = yaml.safe_load(mesd_yaml)
        mesd['meads'] = dict()
        LOG.debug('mesd_dict: %s', inner_mesd_dict)
        # From import we can deploy both NS and MEC Application
        nsd_imports = inner_mesd_dict['imports'].get('nsds')
        vnffg_imports = inner_mesd_dict['imports'].get('vnffgds')
        if nsd_imports:
            mesd_dict['attributes']['nsds'] = nsd_imports
        if vnffg_imports:
            mesd_dict['attributes']['vnffgds'] = vnffg_imports

        # Deploy MEC applications
        mem_plugin = manager.ApmecManager.get_service_plugins()['MEM']
        mead_imports = inner_mesd_dict['imports']['meads']
        inner_mesd_dict['imports'] = []
        new_files = []
        for mead_name in mead_imports:
            mead = mem_plugin.get_mead(context, mead_name)
            # Copy MEA types and MEA names
            sm_dict = yaml.safe_load(
                mead['attributes']
                ['mead'])['topology_template']['substitution_mappings']
            mesd['meads'][sm_dict['node_type']] = mead['name']
            # Ugly Hack to validate the child templates
            # TODO(tbh): add support in tosca-parser to pass child
            # templates as dict
            fd, temp_path = mkstemp()
            with open(temp_path, 'w') as fp:
                fp.write(mead['attributes']['mead'])
            os.close(fd)
            new_files.append(temp_path)
            inner_mesd_dict['imports'].append(temp_path)
        # Prepend the apmec_defs.yaml import file with the full
        # path to the file
        toscautils.updateimports(inner_mesd_dict)

        try:
            ToscaTemplate(a_file=False, yaml_dict_tpl=inner_mesd_dict)
        except Exception as e:
            LOG.exception("tosca-parser error: %s", str(e))
            raise meo.ToscaParserFailed(error_msg_details=str(e))
        finally:
            for file_path in new_files:
                os.remove(file_path)
            inner_mesd_dict['imports'] = mead_imports

        if ('description' not in mesd_dict or mesd_dict['description'] == ''):
            mesd_dict['description'] = inner_mesd_dict.get('description', '')
        if (('name' not in mesd_dict or not len(mesd_dict['name']))
                and 'metadata' in inner_mesd_dict):
            mesd_dict['name'] = inner_mesd_dict['metadata'].get(
                'template_name', '')

        LOG.debug('mesd %s', mesd)