def _parse_template_input(self, vnfd):
        vnfd_dict = vnfd['vnfd']
        vnfd_yaml = vnfd_dict['attributes'].get('vnfd')
        if vnfd_yaml is None:
            return

        inner_vnfd_dict = yaml.load(vnfd_yaml)
        LOG.debug(_('vnfd_dict: %s'), inner_vnfd_dict)

        # Prepend the tacker_defs.yaml import file with the full
        # path to the file
        toscautils.updateimports(inner_vnfd_dict)

        try:
            tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=inner_vnfd_dict)
        except Exception as e:
            LOG.exception(_("tosca-parser error: %s"), str(e))
            raise vnfm.ToscaParserFailed(error_msg_details=str(e))

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

        vnfd_dict['mgmt_driver'] = toscautils.get_mgmt_driver(tosca)
        LOG.debug(_('vnfd %s'), vnfd)
Пример #2
0
    def _parse_template_input(self, vnfd):
        vnfd_dict = vnfd['vnfd']
        vnfd_yaml = vnfd_dict['attributes'].get('vnfd')
        if vnfd_yaml is None:
            return

        inner_vnfd_dict = yaml.load(vnfd_yaml)
        LOG.debug(_('vnfd_dict: %s'), inner_vnfd_dict)

        if 'tosca_definitions_version' in inner_vnfd_dict:
            # Prepend the tacker_defs.yaml import file with the full
            # path to the file
            toscautils.updateimports(inner_vnfd_dict)

            try:
                tosca = ToscaTemplate(a_file=False,
                                      yaml_dict_tpl=inner_vnfd_dict)
            except Exception as e:
                LOG.exception(_("tosca-parser error: %s"), str(e))
                raise vnfm.ToscaParserFailed(error_msg_details=str(e))

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

            vnfd_dict['mgmt_driver'] = toscautils.get_mgmt_driver(
                tosca)
        else:
            KEY_LIST = (('name', 'template_name'),
                        ('description', 'description'))

            vnfd_dict.update(
                dict((key, inner_vnfd_dict[vnfd_key]) for (key, vnfd_key)
                     in KEY_LIST
                     if ((key not in vnfd_dict or
                          vnfd_dict[key] == '') and
                         vnfd_key in inner_vnfd_dict and
                         inner_vnfd_dict[vnfd_key] != '')))

            service_types = inner_vnfd_dict.get(
                'service_properties', {}).get('type', [])
            if service_types:
                vnfd_dict.setdefault('service_types', []).extend(
                    [{'service_type': service_type}
                    for service_type in service_types])
            # TODO(anyone)  - this code assumes one mgmt_driver per VNFD???
            for vdu in inner_vnfd_dict.get('vdus', {}).values():
                mgmt_driver = vdu.get('mgmt_driver')
                if mgmt_driver:
                    vnfd_dict['mgmt_driver'] = mgmt_driver
        LOG.debug(_('vnfd %s'), vnfd)
Пример #3
0
    def _parse_template_input(self, vnfd):
        vnfd_dict = vnfd['vnfd']
        vnfd_yaml = vnfd_dict['attributes'].get('vnfd')
        if vnfd_yaml is None:
            return

        inner_vnfd_dict = yaml.load(vnfd_yaml)
        LOG.debug(_('vnfd_dict: %s'), inner_vnfd_dict)

        if 'tosca_definitions_version' in inner_vnfd_dict:
            # Prepend the tacker_defs.yaml import file with the full
            # path to the file
            toscautils.updateimports(inner_vnfd_dict)

            try:
                tosca = ToscaTemplate(a_file=False,
                                      yaml_dict_tpl=inner_vnfd_dict)
            except Exception as e:
                LOG.exception(_("tosca-parser error: %s"), str(e))
                raise vnfm.ToscaParserFailed(error_msg_details=str(e))

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

            vnfd_dict['mgmt_driver'] = toscautils.get_mgmt_driver(
                tosca)
        else:
            KEY_LIST = (('name', 'template_name'),
                        ('description', 'description'))

            vnfd_dict.update(
                dict((key, inner_vnfd_dict[vnfd_key]) for (key, vnfd_key)
                     in KEY_LIST
                     if ((key not in vnfd_dict or
                          vnfd_dict[key] == '') and
                         vnfd_key in inner_vnfd_dict and
                         inner_vnfd_dict[vnfd_key] != '')))

            service_types = inner_vnfd_dict.get(
                'service_properties', {}).get('type', [])
            if service_types:
                vnfd_dict.setdefault('service_types', []).extend(
                    [{'service_type': service_type}
                    for service_type in service_types])
            # TODO(anyone)  - this code assumes one mgmt_driver per VNFD???
            for vdu in inner_vnfd_dict.get('vdus', {}).values():
                mgmt_driver = vdu.get('mgmt_driver')
                if mgmt_driver:
                    vnfd_dict['mgmt_driver'] = mgmt_driver
        LOG.debug(_('vnfd %s'), vnfd)
Пример #4
0
    def _parse_template_input(self, vnfd):
        vnfd_dict = vnfd["vnfd"]
        vnfd_yaml = vnfd_dict["attributes"].get("vnfd")
        if vnfd_yaml is None:
            return

        inner_vnfd_dict = yaml.load(vnfd_yaml)
        LOG.debug(_("vnfd_dict: %s"), inner_vnfd_dict)

        if "tosca_definitions_version" in inner_vnfd_dict:
            # Prepend the tacker_defs.yaml import file with the full
            # path to the file
            toscautils.updateimports(inner_vnfd_dict)

            try:
                tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=inner_vnfd_dict)
            except Exception as e:
                LOG.exception(_("tosca-parser error: %s"), str(e))
                raise vnfm.ToscaParserFailed(error_msg_details=str(e))

            if "description" not in vnfd_dict or vnfd_dict["description"] == "":
                vnfd_dict["description"] = inner_vnfd_dict.get("description", "")
            if ("name" not in vnfd_dict or not len(vnfd_dict["name"])) and "metadata" in inner_vnfd_dict:
                vnfd_dict["name"] = inner_vnfd_dict["metadata"].get("template_name", "")

            vnfd_dict["mgmt_driver"] = toscautils.get_mgmt_driver(tosca)
        else:
            KEY_LIST = (("name", "template_name"), ("description", "description"))

            vnfd_dict.update(
                dict(
                    (key, inner_vnfd_dict[vnfd_key])
                    for (key, vnfd_key) in KEY_LIST
                    if (
                        (key not in vnfd_dict or vnfd_dict[key] == "")
                        and vnfd_key in inner_vnfd_dict
                        and inner_vnfd_dict[vnfd_key] != ""
                    )
                )
            )

            service_types = inner_vnfd_dict.get("service_properties", {}).get("type", [])
            if service_types:
                vnfd_dict.setdefault("service_types", []).extend(
                    [{"service_type": service_type} for service_type in service_types]
                )
            # TODO(anyone)  - this code assumes one mgmt_driver per VNFD???
            for vdu in inner_vnfd_dict.get("vdus", {}).values():
                mgmt_driver = vdu.get("mgmt_driver")
                if mgmt_driver:
                    vnfd_dict["mgmt_driver"] = mgmt_driver
        LOG.debug(_("vnfd %s"), vnfd)
Пример #5
0
 def test_get_mgmt_driver(self):
     expected_mgmt_driver = 'openwrt'
     mgmt_driver = toscautils.get_mgmt_driver(self.tosca)
     self.assertEqual(expected_mgmt_driver, mgmt_driver)
Пример #6
0
 def test_get_mgmt_driver(self):
     expected_mgmt_driver = 'openwrt'
     mgmt_driver = toscautils.get_mgmt_driver(self.tosca)
     self.assertEqual(expected_mgmt_driver, mgmt_driver)