Example #1
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
Example #2
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)