Пример #1
0
    def create_device_template(self, context, device_template):
        template = device_template['device_template']
        LOG.debug(_('template %s'), template)

        infra_driver = template.get('infra_driver')
        if not attributes.is_attr_set(infra_driver):
            LOG.debug(_('hosting device driver must be specified'))
            raise vnfm.InfraDriverNotSpecified()
        if infra_driver not in self._device_manager:
            LOG.debug(
                _('unknown hosting device driver '
                  '%(infra_driver)s in %(drivers)s'), {
                      'infra_driver': infra_driver,
                      'drivers': cfg.CONF.tacker.infra_driver
                  })
            raise vnfm.InvalidInfraDriver(infra_driver=infra_driver)

        service_types = template.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug(_('service type must be specified'))
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass

        self._device_manager.invoke(infra_driver,
                                    'create_device_template_pre',
                                    plugin=self,
                                    context=context,
                                    device_template=device_template)

        return super(VNFMPlugin,
                     self).create_device_template(context, device_template)
Пример #2
0
    def create_device_template(self, context, device_template):
        template = device_template['device_template']
        LOG.debug(_('template %s'), template)

        infra_driver = template.get('infra_driver')
        if not attributes.is_attr_set(infra_driver):
            LOG.debug(_('hosting device driver must be specified'))
            raise vnfm.InfraDriverNotSpecified()
        if infra_driver not in self._device_manager:
            LOG.debug(_('unknown hosting device driver '
                        '%(infra_driver)s in %(drivers)s'),
                      {'infra_driver': infra_driver,
                       'drivers': cfg.CONF.tacker.infra_driver})
            raise vnfm.InvalidInfraDriver(infra_driver=infra_driver)

        service_types = template.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug(_('service type must be specified'))
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass

        self._device_manager.invoke(
            infra_driver, 'create_device_template_pre', plugin=self,
            context=context, device_template=device_template)

        return super(VNFMPlugin, self).create_device_template(
            context, device_template)
Пример #3
0
    def test_is_attr_set(self):
        data = attributes.ATTR_NOT_SPECIFIED
        self.assertIs(attributes.is_attr_set(data), False)

        data = None
        self.assertIs(attributes.is_attr_set(data), False)

        data = "I'm set"
        self.assertIs(attributes.is_attr_set(data), True)
Пример #4
0
    def test_is_attr_set(self):
        data = attributes.ATTR_NOT_SPECIFIED
        self.assertIs(attributes.is_attr_set(data), False)

        data = None
        self.assertIs(attributes.is_attr_set(data), False)

        data = "I'm set"
        self.assertIs(attributes.is_attr_set(data), True)
Пример #5
0
    def create_vnfd(self, context, vnfd):
        vnfd = vnfd['vnfd']
        LOG.debug(_('vnfd %s'), vnfd)
        tenant_id = self._get_tenant_id_for_create(context, vnfd)
        infra_driver = vnfd.get('infra_driver')
        mgmt_driver = vnfd.get('mgmt_driver')
        service_types = vnfd.get('service_types')

        if (not attributes.is_attr_set(infra_driver)):
            LOG.debug(_('hosting vnf driver unspecified'))
            raise vnfm.InfraDriverNotSpecified()
        if (not attributes.is_attr_set(mgmt_driver)):
            LOG.debug(_('mgmt driver unspecified'))
            raise vnfm.MGMTDriverNotSpecified()
        if (not attributes.is_attr_set(service_types)):
            LOG.debug(_('service types unspecified'))
            raise vnfm.ServiceTypesNotSpecified()

        with context.session.begin(subtransactions=True):
            vnfd_id = str(uuid.uuid4())
            vnfd_db = VNFD(id=vnfd_id,
                           tenant_id=tenant_id,
                           name=vnfd.get('name'),
                           description=vnfd.get('description'),
                           infra_driver=infra_driver,
                           mgmt_driver=mgmt_driver)
            context.session.add(vnfd_db)
            for (key, value) in vnfd.get('attributes', {}).items():
                attribute_db = VNFDAttribute(id=str(uuid.uuid4()),
                                             vnfd_id=vnfd_id,
                                             key=key,
                                             value=value)
                context.session.add(attribute_db)
            for service_type in (item['service_type']
                                 for item in vnfd['service_types']):
                service_type_db = ServiceType(id=str(uuid.uuid4()),
                                              tenant_id=tenant_id,
                                              vnfd_id=vnfd_id,
                                              service_type=service_type)
                context.session.add(service_type_db)

        LOG.debug(_('vnfd_db %(vnfd_db)s %(attributes)s '), {
            'vnfd_db': vnfd_db,
            'attributes': vnfd_db.attributes
        })
        vnfd_dict = self._make_vnfd_dict(vnfd_db)
        LOG.debug(_('vnfd_dict %s'), vnfd_dict)
        self._cos_db_plg.create_event(
            context,
            res_id=vnfd_dict['id'],
            res_type=constants.RES_TYPE_VNFD,
            res_state=constants.RES_EVT_VNFD_NA_STATE,
            evt_type=constants.RES_EVT_CREATE,
            tstamp=vnfd_dict[constants.RES_EVT_CREATED_FLD])
        return vnfd_dict
Пример #6
0
    def create_device_template(self, context, device_template):
        template = device_template['device_template']
        LOG.debug(_('template %s'), template)
        tenant_id = self._get_tenant_id_for_create(context, template)
        device_driver = template.get('device_driver')
        mgmt_driver = template.get('mgmt_driver')
        service_types = template.get('service_types')

        if (not attributes.is_attr_set(device_driver)):
            LOG.debug(_('hosting device driver unspecified'))
            raise servicevm.DeviceDriverNotSpecified()
        if (not attributes.is_attr_set(mgmt_driver)):
            LOG.debug(_('mgmt driver unspecified'))
            raise servicevm.MGMTDriverNotSpecified()
        if (not attributes.is_attr_set(service_types)):
            LOG.debug(_('service types unspecified'))
            raise servicevm.SeviceTypesNotSpecified()

        with context.session.begin(subtransactions=True):
            template_id = str(uuid.uuid4())
            template_db = DeviceTemplate(
                id=template_id,
                tenant_id=tenant_id,
                name=template.get('name'),
                description=template.get('description'),
                device_driver=device_driver,
                mgmt_driver=mgmt_driver)
            context.session.add(template_db)
            for (key, value) in template.get('attributes', {}).items():
                attribute_db = DeviceTemplateAttribute(
                    id=str(uuid.uuid4()),
                    template_id=template_id,
                    key=key,
                    value=value)
                context.session.add(attribute_db)
            for service_type in (item['service_type']
                                 for item in template['service_types']):
                service_type_db = ServiceType(
                    id=str(uuid.uuid4()),
                    tenant_id=tenant_id,
                    template_id=template_id,
                    service_type=service_type)
                context.session.add(service_type_db)

        LOG.debug(_('template_db %(template_db)s %(attributes)s '
                    '%(service_types)s'),
                  {'template_db': template_db,
                   'attributes': template_db.attributes,
                   'service_types': template_db.service_types})
        return self._make_template_dict(template_db)
Пример #7
0
    def create_device_template(self, context, device_template):
        template = device_template['device_template']
        LOG.debug(_('template %s'), template)
        tenant_id = self._get_tenant_id_for_create(context, template)
        infra_driver = template.get('infra_driver')
        mgmt_driver = template.get('mgmt_driver')
        service_types = template.get('service_types')

        if (not attributes.is_attr_set(infra_driver)):
            LOG.debug(_('hosting device driver unspecified'))
            raise vnfm.InfraDriverNotSpecified()
        if (not attributes.is_attr_set(mgmt_driver)):
            LOG.debug(_('mgmt driver unspecified'))
            raise vnfm.MGMTDriverNotSpecified()
        if (not attributes.is_attr_set(service_types)):
            LOG.debug(_('service types unspecified'))
            raise vnfm.ServiceTypesNotSpecified()

        with context.session.begin(subtransactions=True):
            template_id = str(uuid.uuid4())
            template_db = DeviceTemplate(
                id=template_id,
                tenant_id=tenant_id,
                name=template.get('name'),
                description=template.get('description'),
                infra_driver=infra_driver,
                mgmt_driver=mgmt_driver)
            context.session.add(template_db)
            for (key, value) in template.get('attributes', {}).items():
                attribute_db = DeviceTemplateAttribute(
                    id=str(uuid.uuid4()),
                    template_id=template_id,
                    key=key,
                    value=value)
                context.session.add(attribute_db)
            for service_type in (item['service_type']
                                 for item in template['service_types']):
                service_type_db = ServiceType(
                    id=str(uuid.uuid4()),
                    tenant_id=tenant_id,
                    template_id=template_id,
                    service_type=service_type)
                context.session.add(service_type_db)

        LOG.debug(_('template_db %(template_db)s %(attributes)s '),
                  {'template_db': template_db,
                   'attributes': template_db.attributes})
        return self._make_template_dict(template_db)
Пример #8
0
    def create_vnfd(self, context, vnfd):
        vnfd_data = vnfd['vnfd']
        template = vnfd_data['attributes'].get('vnfd')
        if isinstance(template, dict):
            # TODO(sripriya) remove this yaml dump once db supports storing
            # json format of yaml files in a separate column instead of
            # key value string pairs in vnf attributes table
            vnfd_data['attributes']['vnfd'] = yaml.safe_dump(
                template)
        elif isinstance(template, str):
            self._report_deprecated_yaml_str()
        if "tosca_definitions_version" not in template:
            raise exceptions.Invalid('Not a valid template: '
                                     'tosca_definitions_version is missing.')

        LOG.debug('vnfd %s', vnfd_data)

        service_types = vnfd_data.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug('service type must be specified')
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass
        if 'template_source' in vnfd_data:
            template_source = vnfd_data.get('template_source')
        else:
            template_source = 'onboarded'
        vnfd['vnfd']['template_source'] = template_source

        self._parse_template_input(vnfd)
        return super(VNFMPlugin, self).create_vnfd(
            context, vnfd)
Пример #9
0
    def create_vnfd(self, context, vnfd):
        vnfd_data = vnfd['vnfd']
        template = vnfd_data['attributes'].get('vnfd')
        if isinstance(template, dict):
            # TODO(sripriya) remove this yaml dump once db supports storing
            # json format of yaml files in a separate column instead of
            # key value string pairs in vnf attributes table
            vnfd_data['attributes']['vnfd'] = yaml.safe_dump(
                template)
        else:
            raise vnfm.InvalidAPIAttributeType(atype=type(template))
        if "tosca_definitions_version" not in template:
            raise exceptions.Invalid('Not a valid template: '
                                     'tosca_definitions_version is missing.')

        LOG.debug('vnfd %s', vnfd_data)

        service_types = vnfd_data.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug('service type must be specified')
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass
        if 'template_source' in vnfd_data:
            template_source = vnfd_data.get('template_source')
        else:
            template_source = 'onboarded'
        vnfd['vnfd']['template_source'] = template_source

        self._parse_template_input(vnfd)
        return super(VNFMPlugin, self).create_vnfd(
            context, vnfd)
Пример #10
0
    def create_device_template(self, context, device_template):
        template = device_template["device_template"]
        LOG.debug(_("template %s"), template)
        tenant_id = self._get_tenant_id_for_create(context, template)
        infra_driver = template.get("infra_driver")
        mgmt_driver = template.get("mgmt_driver")
        service_types = template.get("service_types")

        if not attributes.is_attr_set(infra_driver):
            LOG.debug(_("hosting device driver unspecified"))
            raise vnfm.InfraDriverNotSpecified()
        if not attributes.is_attr_set(mgmt_driver):
            LOG.debug(_("mgmt driver unspecified"))
            raise vnfm.MGMTDriverNotSpecified()
        if not attributes.is_attr_set(service_types):
            LOG.debug(_("service types unspecified"))
            raise vnfm.ServiceTypesNotSpecified()

        with context.session.begin(subtransactions=True):
            template_id = str(uuid.uuid4())
            template_db = DeviceTemplate(
                id=template_id,
                tenant_id=tenant_id,
                name=template.get("name"),
                description=template.get("description"),
                infra_driver=infra_driver,
                mgmt_driver=mgmt_driver,
            )
            context.session.add(template_db)
            for (key, value) in template.get("attributes", {}).items():
                attribute_db = DeviceTemplateAttribute(
                    id=str(uuid.uuid4()), template_id=template_id, key=key, value=value
                )
                context.session.add(attribute_db)
            for service_type in (item["service_type"] for item in template["service_types"]):
                service_type_db = ServiceType(
                    id=str(uuid.uuid4()), tenant_id=tenant_id, template_id=template_id, service_type=service_type
                )
                context.session.add(service_type_db)

        LOG.debug(
            _("template_db %(template_db)s %(attributes)s "),
            {"template_db": template_db, "attributes": template_db.attributes},
        )
        return self._make_template_dict(template_db)
Пример #11
0
    def create_vnfd(self, context, vnfd):
        vnfd_data = vnfd['vnfd']
        template = vnfd_data['attributes'].get('vnfd')
        if isinstance(template, dict):
            # TODO(sripriya) remove this yaml dump once db supports storing
            # json format of yaml files in a separate column instead of
            # key value string pairs in vnf attributes table
            vnfd_data['attributes']['vnfd'] = yaml.safe_dump(
                template)
        elif isinstance(template, str):
            self._report_deprecated_yaml_str()
        if "tosca_definitions_version" not in template:
            versionutils.report_deprecated_feature(LOG, 'VNFD legacy vnfds'
                ' are deprecated since Mitaka release and will be removed in'
                ' Ocata release. Please use NFV TOSCA vnfds.')

        LOG.debug(_('vnfd %s'), vnfd_data)

        infra_driver = vnfd_data.get('infra_driver')
        if not attributes.is_attr_set(infra_driver):
            LOG.debug(_('hosting vnf driver must be specified'))
            raise vnfm.InfraDriverNotSpecified()
        if infra_driver not in self._vnf_manager:
            LOG.debug(_('unknown hosting vnf driver '
                        '%(infra_driver)s in %(drivers)s'),
                      {'infra_driver': infra_driver,
                       'drivers': cfg.CONF.tacker.infra_driver})
            raise vnfm.InvalidInfraDriver(infra_driver=infra_driver)

        service_types = vnfd_data.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug(_('service type must be specified'))
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass

        self._vnf_manager.invoke(
            infra_driver, 'create_vnfd_pre', plugin=self,
            context=context, vnfd=vnfd)

        return super(VNFMPlugin, self).create_vnfd(
            context, vnfd)
Пример #12
0
    def create_vnfd(self, context, vnfd):
        vnfd = vnfd['vnfd']
        LOG.debug(_('vnfd %s'), vnfd)
        tenant_id = self._get_tenant_id_for_create(context, vnfd)
        service_types = vnfd.get('service_types')
        mgmt_driver = vnfd.get('mgmt_driver')
        template_source = vnfd.get("template_source")

        if (not attributes.is_attr_set(service_types)):
            LOG.debug(_('service types unspecified'))
            raise vnfm.ServiceTypesNotSpecified()

        try:
            with context.session.begin(subtransactions=True):
                vnfd_id = str(uuid.uuid4())
                vnfd_db = VNFD(
                    id=vnfd_id,
                    tenant_id=tenant_id,
                    name=vnfd.get('name'),
                    description=vnfd.get('description'),
                    mgmt_driver=mgmt_driver,
                    template_source=template_source,
                    deleted_at=None)
                context.session.add(vnfd_db)
                for (key, value) in vnfd.get('attributes', {}).items():
                    attribute_db = VNFDAttribute(
                        id=str(uuid.uuid4()),
                        vnfd_id=vnfd_id,
                        key=key,
                        value=value)
                    context.session.add(attribute_db)
                for service_type in (item['service_type']
                                     for item in vnfd['service_types']):
                    service_type_db = ServiceType(
                        id=str(uuid.uuid4()),
                        tenant_id=tenant_id,
                        vnfd_id=vnfd_id,
                        service_type=service_type)
                    context.session.add(service_type_db)
        except DBDuplicateEntry as e:
            raise exceptions.DuplicateEntity(
                _type="vnfd",
                entry=e.columns)
        LOG.debug(_('vnfd_db %(vnfd_db)s %(attributes)s '),
                  {'vnfd_db': vnfd_db,
                   'attributes': vnfd_db.attributes})
        vnfd_dict = self._make_vnfd_dict(vnfd_db)
        LOG.debug(_('vnfd_dict %s'), vnfd_dict)
        self._cos_db_plg.create_event(
            context, res_id=vnfd_dict['id'],
            res_type=constants.RES_TYPE_VNFD,
            res_state=constants.RES_EVT_ONBOARDED,
            evt_type=constants.RES_EVT_CREATE,
            tstamp=vnfd_dict[constants.RES_EVT_CREATED_FLD])
        return vnfd_dict
Пример #13
0
    def create_vnfd(self, context, vnfd):
        vnfd = vnfd['vnfd']
        LOG.debug('vnfd %s', vnfd)
        tenant_id = self._get_tenant_id_for_create(context, vnfd)
        service_types = vnfd.get('service_types')
        mgmt_driver = vnfd.get('mgmt_driver')
        template_source = vnfd.get("template_source")

        if (not attributes.is_attr_set(service_types)):
            LOG.debug('service types unspecified')
            raise vnfm.ServiceTypesNotSpecified()

        try:
            with context.session.begin(subtransactions=True):
                vnfd_id = uuidutils.generate_uuid()
                vnfd_db = VNFD(
                    id=vnfd_id,
                    tenant_id=tenant_id,
                    name=vnfd.get('name'),
                    description=vnfd.get('description'),
                    mgmt_driver=mgmt_driver,
                    template_source=template_source,
                    deleted_at=datetime.min)
                context.session.add(vnfd_db)
                for (key, value) in vnfd.get('attributes', {}).items():
                    attribute_db = VNFDAttribute(
                        id=uuidutils.generate_uuid(),
                        vnfd_id=vnfd_id,
                        key=key,
                        value=value)
                    context.session.add(attribute_db)
                for service_type in (item['service_type']
                                     for item in vnfd['service_types']):
                    service_type_db = ServiceType(
                        id=uuidutils.generate_uuid(),
                        tenant_id=tenant_id,
                        vnfd_id=vnfd_id,
                        service_type=service_type)
                    context.session.add(service_type_db)
        except DBDuplicateEntry as e:
            raise exceptions.DuplicateEntity(
                _type="vnfd",
                entry=e.columns)
        LOG.debug('vnfd_db %(vnfd_db)s %(attributes)s ',
                  {'vnfd_db': vnfd_db,
                   'attributes': vnfd_db.attributes})
        vnfd_dict = self._make_vnfd_dict(vnfd_db)
        LOG.debug('vnfd_dict %s', vnfd_dict)
        self._cos_db_plg.create_event(
            context, res_id=vnfd_dict['id'],
            res_type=constants.RES_TYPE_VNFD,
            res_state=constants.RES_EVT_ONBOARDED,
            evt_type=constants.RES_EVT_CREATE,
            tstamp=vnfd_dict[constants.RES_EVT_CREATED_FLD])
        return vnfd_dict
Пример #14
0
    def create_device_template(self, context, device_template):
        template = device_template['device_template']
        LOG.debug(_('template %s'), template)

        device_driver = template.get('device_driver')
        if not attributes.is_attr_set(device_driver):
            LOG.debug(_('hosting device driver must be specified'))
            raise servicevm.DeviceDriverNotSpecified()
        if device_driver not in self._device_manager:
            LOG.debug(
                _('unknown hosting device driver '
                  '%(device_driver)s in %(drivers)s'), {
                      'device_driver': device_driver,
                      'drivers': cfg.CONF.servicevm.device_driver
                  })
            raise servicevm.InvalidDeviceDriver(device_driver=device_driver)

        mgmt_driver = template.get('mgmt_driver')
        if not attributes.is_attr_set(mgmt_driver):
            LOG.debug(_('mgmt driver must be specified'))
            raise servicevm.MgmtDriverNotSpecified()
        if mgmt_driver not in self._mgmt_manager:
            LOG.debug(
                _('unknown mgmt driver %(mgmt_driver)s in %(drivers)s'), {
                    'mgmt_driver': mgmt_driver,
                    'drivers': cfg.CONF.servicevm.mgmt_driver
                })
            raise servicevm.InvalidMgmtDriver(mgmt_driver=mgmt_driver)

        service_types = template.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug(_('service type must be specified'))
            raise servicevm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass

        return super(ServiceVMPlugin,
                     self).create_device_template(context, device_template)
Пример #15
0
    def create_vnfd(self, context, vnfd):
        LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"))
        LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"))
        LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"))
        LOG.debug(_("create_vnfd vnfd : %s"), vnfd)
        LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"))
        LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"))
        LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"))
        vnfd_data = vnfd["vnfd"]
        template = vnfd_data["attributes"].get("vnfd")
        if isinstance(template, dict):
            # TODO(sripriya) remove this yaml dump once db supports storing
            # json format of yaml files in a separate column instead of
            # key value string pairs in vnf attributes table
            vnfd_data["attributes"]["vnfd"] = yaml.safe_dump(template)
        elif isinstance(template, str):
            self._report_deprecated_yaml_str()
        if "tosca_definitions_version" not in template:
            versionutils.report_deprecated_feature(
                LOG,
                "VNFD legacy vnfds"
                " are deprecated since Mitaka release and will be removed in"
                " Ocata release. Please use NFV TOSCA vnfds.",
            )

        LOG.debug(_("vnfd %s"), vnfd_data)

        if "infra_driver" in vnfd_data or "mgmt_driver" in vnfd_data:
            versionutils.report_deprecated_feature(
                LOG,
                "Deriving "
                "infra_driver and mgmt_driver from VNFD API is deprecated and"
                " will be removed in Ocata. infra_driver will be automatically"
                " derived from target vim type. mgmt_driver will be derived "
                "from TOSCA template values.",
            )
        name = vnfd_data["name"]
        if self._get_by_name(context, vnfm_db.VNFD, name):
            raise exceptions.DuplicateResourceName(resource="VNFD", name=name)

        service_types = vnfd_data.get("service_types")
        if not attributes.is_attr_set(service_types):
            LOG.debug(_("service type must be specified"))
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass

        self._parse_template_input(vnfd)
        return super(VNFMPlugin, self).create_vnfd(context, vnfd)
Пример #16
0
    def create_vnfd(self, context, vnfd):
        vnfd = vnfd['vnfd']
        LOG.debug(_('vnfd %s'), vnfd)
        tenant_id = self._get_tenant_id_for_create(context, vnfd)
        infra_driver = vnfd.get('infra_driver')
        mgmt_driver = vnfd.get('mgmt_driver')
        service_types = vnfd.get('service_types')

        if (not attributes.is_attr_set(service_types)):
            LOG.debug(_('service types unspecified'))
            raise vnfm.ServiceTypesNotSpecified()

        with context.session.begin(subtransactions=True):
            vnfd_id = str(uuid.uuid4())
            vnfd_db = VNFD(
                id=vnfd_id,
                tenant_id=tenant_id,
                name=vnfd.get('name'),
                description=vnfd.get('description'),
                infra_driver=infra_driver,
                mgmt_driver=mgmt_driver)
            context.session.add(vnfd_db)
            for (key, value) in vnfd.get('attributes', {}).items():
                attribute_db = VNFDAttribute(
                    id=str(uuid.uuid4()),
                    vnfd_id=vnfd_id,
                    key=key,
                    value=value)
                context.session.add(attribute_db)
            for service_type in (item['service_type']
                                 for item in vnfd['service_types']):
                service_type_db = ServiceType(
                    id=str(uuid.uuid4()),
                    tenant_id=tenant_id,
                    vnfd_id=vnfd_id,
                    service_type=service_type)
                context.session.add(service_type_db)

        LOG.debug(_('vnfd_db %(vnfd_db)s %(attributes)s '),
                  {'vnfd_db': vnfd_db,
                   'attributes': vnfd_db.attributes})
        vnfd_dict = self._make_vnfd_dict(vnfd_db)
        LOG.debug(_('vnfd_dict %s'), vnfd_dict)
        self._cos_db_plg.create_event(
            context, res_id=vnfd_dict['id'],
            res_type=constants.RES_TYPE_VNFD,
            res_state=constants.RES_EVT_VNFD_ONBOARDED,
            evt_type=constants.RES_EVT_CREATE,
            tstamp=vnfd_dict[constants.RES_EVT_CREATED_FLD])
        return vnfd_dict
Пример #17
0
    def create_device_template(self, context, device_template):
        template = device_template['device_template']
        if "tosca_definitions_version" not in template['attributes']['vnfd']:
            versionutils.report_deprecated_feature(LOG, 'VNFD legacy templates'
                ' are deprecated since Mitaka release and will be removed in'
                ' Ocata release. Please use NFV TOSCA templates.')

        LOG.debug(_('template %s'), template)

        infra_driver = template.get('infra_driver')
        if not attributes.is_attr_set(infra_driver):
            LOG.debug(_('hosting device driver must be specified'))
            raise vnfm.InfraDriverNotSpecified()
        if infra_driver not in self._device_manager:
            LOG.debug(_('unknown hosting device driver '
                        '%(infra_driver)s in %(drivers)s'),
                      {'infra_driver': infra_driver,
                       'drivers': cfg.CONF.tacker.infra_driver})
            raise vnfm.InvalidInfraDriver(infra_driver=infra_driver)

        service_types = template.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug(_('service type must be specified'))
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass

        self._device_manager.invoke(
            infra_driver, 'create_device_template_pre', plugin=self,
            context=context, device_template=device_template)

        return super(VNFMPlugin, self).create_device_template(
            context, device_template)
Пример #18
0
    def create_vnfd(self, context, vnfd):
        vnfd_data = vnfd['vnfd']
        template = vnfd_data['attributes'].get('vnfd')
        if isinstance(template, dict):
            # TODO(sripriya) remove this yaml dump once db supports storing
            # json format of yaml files in a separate column instead of
            # key value string pairs in vnf attributes table
            vnfd_data['attributes']['vnfd'] = yaml.safe_dump(
                template)
        elif isinstance(template, str):
            self._report_deprecated_yaml_str()
        if "tosca_definitions_version" not in template:
            versionutils.report_deprecated_feature(LOG, 'VNFD legacy vnfds'
                ' are deprecated since Mitaka release and will be removed in'
                ' Ocata release. Please use NFV TOSCA vnfds.')

        LOG.debug(_('vnfd %s'), vnfd_data)

        if 'infra_driver' in vnfd_data or 'mgmt_driver' in vnfd_data:
            versionutils.report_deprecated_feature(LOG, "Deriving "
                "infra_driver and mgmt_driver from VNFD API is deprecated and"
                " will be removed in Ocata. infra_driver will be automatically"
                " derived from target vim type. mgmt_driver will be derived "
                "from TOSCA template values.")
        name = vnfd_data['name']
        if self._get_by_name(context, vnfm_db.VNFD, name):
            raise exceptions.DuplicateResourceName(resource='VNFD', name=name)

        service_types = vnfd_data.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug(_('service type must be specified'))
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass

        self._parse_template_input(vnfd)
        return super(VNFMPlugin, self).create_vnfd(
            context, vnfd)