Пример #1
0
    def _create_device_pre(self, context, device):
        LOG.debug(_('device %s'), device)
        tenant_id = self._get_tenant_id_for_create(context, device)
        template_id = device['template_id']
        name = device.get('name')
        device_id = device.get('id') or str(uuid.uuid4())
        attributes = device.get('attributes', {})
        vim_id = device.get('vim_id')
        placement_attr = device.get('placement_attr', {})
        with context.session.begin(subtransactions=True):
            template_db = self._get_resource(context, DeviceTemplate,
                                             template_id)
            device_db = Device(id=device_id,
                               tenant_id=tenant_id,
                               name=name,
                               description=template_db.description,
                               instance_id=None,
                               template_id=template_id,
                               vim_id=vim_id,
                               placement_attr=placement_attr,
                               status=constants.PENDING_CREATE,
                               error_reason=None)
            context.session.add(device_db)
            for key, value in attributes.items():
                arg = DeviceAttribute(id=str(uuid.uuid4()),
                                      device_id=device_id,
                                      key=key,
                                      value=value)
                context.session.add(arg)

        return self._make_device_dict(device_db)
Пример #2
0
    def _create_device_pre(self, context, device):
        device = device["device"]
        LOG.debug(_("device %s"), device)
        tenant_id = self._get_tenant_id_for_create(context, device)
        template_id = device["template_id"]
        name = device.get("name")
        device_id = device.get("id") or str(uuid.uuid4())
        attributes = device.get("attributes", {})
        with context.session.begin(subtransactions=True):
            template_db = self._get_resource(context, DeviceTemplate, template_id)
            device_db = Device(
                id=device_id,
                tenant_id=tenant_id,
                name=name,
                description=template_db.description,
                instance_id=None,
                template_id=template_id,
                status=constants.PENDING_CREATE,
            )
            context.session.add(device_db)
            for key, value in attributes.items():
                arg = DeviceAttribute(id=str(uuid.uuid4()), device_id=device_id, key=key, value=value)
                context.session.add(arg)

        return self._make_device_dict(device_db)
Пример #3
0
    def _create_device_pre(self, context, device):
        LOG.debug(_('device %s'), device)
        tenant_id = self._get_tenant_id_for_create(context, device)
        template_id = device['template_id']
        name = device.get('name')
        device_id = device.get('id') or str(uuid.uuid4())
        attributes = device.get('attributes', {})
        vim_id = device.get('vim_id')
        placement_attr = device.get('placement_attr', {})
        with context.session.begin(subtransactions=True):
            template_db = self._get_resource(context, DeviceTemplate,
                                             template_id)
            device_db = Device(id=device_id,
                               tenant_id=tenant_id,
                               name=name,
                               description=template_db.description,
                               instance_id=None,
                               template_id=template_id,
                               vim_id=vim_id,
                               placement_attr=placement_attr,
                               status=constants.PENDING_CREATE,
                               error_reason=None)
            context.session.add(device_db)
            for key, value in attributes.items():
                    arg = DeviceAttribute(
                        id=str(uuid.uuid4()), device_id=device_id,
                        key=key, value=value)
                    context.session.add(arg)

        return self._make_device_dict(device_db)
Пример #4
0
    def _create_vnf_pre(self, context, vnf):
        LOG.debug(_('vnf %s'), vnf)
        tenant_id = self._get_tenant_id_for_create(context, vnf)
        vnfd_id = vnf['vnfd_id']
        name = vnf.get('name')
        vnf_id = str(uuid.uuid4())
        attributes = vnf.get('attributes', {})
        vim_id = vnf.get('vim_id')
        placement_attr = vnf.get('placement_attr', {})

        try:
            with context.session.begin(subtransactions=True):
                vnfd_db = self._get_resource(context, VNFD, vnfd_id)
                vnf_db = VNF(id=vnf_id,
                             tenant_id=tenant_id,
                             name=name,
                             description=vnfd_db.description,
                             instance_id=None,
                             vnfd_id=vnfd_id,
                             vim_id=vim_id,
                             placement_attr=placement_attr,
                             status=constants.PENDING_CREATE,
                             error_reason=None,
                             server_id=cfg.CONF.uuid)
                context.session.add(vnf_db)
                for key, value in attributes.items():
                    arg = VNFAttribute(id=str(uuid.uuid4()),
                                       vnf_id=vnf_id,
                                       key=key,
                                       value=value)
                    context.session.add(arg)
        except DBDuplicateEntry as e:
            raise exceptions.DuplicateEntity(_type="vnf", entry=e.columns)

        evt_details = "VNF UUID assigned."
        self._cos_db_plg.create_event(
            context,
            res_id=vnf_id,
            res_type=constants.RES_TYPE_VNF,
            res_state=constants.PENDING_CREATE,
            evt_type=constants.RES_EVT_CREATE,
            tstamp=vnf_db[constants.RES_EVT_CREATED_FLD],
            details=evt_details)
        return self._make_vnf_dict(vnf_db)
Пример #5
0
    def _create_device_pre(self, context, device):
        device = device['device']
        LOG.debug(_('device %s'), device)
        tenant_id = self._get_tenant_id_for_create(context, device)
        template_id = device['template_id']
        name = device.get('name')
        device_id = device.get('id') or str(uuid.uuid4())
        attributes = device.get('attributes', {})
        service_context = device.get('service_context', [])
        with context.session.begin(subtransactions=True):
            template_db = self._get_resource(context, DeviceTemplate,
                                             template_id)
            device_db = Device(id=device_id,
                               tenant_id=tenant_id,
                               name=name,
                               description=template_db.description,
                               instance_id=None,
                               template_id=template_id,
                               status=constants.PENDING_CREATE)
            context.session.add(device_db)
            for key, value in attributes.items():
                arg = DeviceAttribute(
                    id=str(uuid.uuid4()), device_id=device_id,
                    key=key, value=value)
                context.session.add(arg)

            LOG.debug(_('service_context %s'), service_context)
            for sc_entry in service_context:
                LOG.debug(_('sc_entry %s'), sc_entry)
                network_id = sc_entry.get('network_id')
                subnet_id = sc_entry.get('subnet_id')
                port_id = sc_entry.get('port_id')
                router_id = sc_entry.get('router_id')
                role = sc_entry.get('role')
                index = sc_entry.get('index')
                network_binding = DeviceServiceContext(
                    id=str(uuid.uuid4()), device_id=device_id,
                    network_id=network_id, subnet_id=subnet_id,
                    port_id=port_id, router_id=router_id, role=role,
                    index=index)
                context.session.add(network_binding)

        return self._make_device_dict(device_db)
Пример #6
0
 def _create_vnf_pre(self, context, vnf):
     LOG.debug('vnf %s', vnf)
     tenant_id = self._get_tenant_id_for_create(context, vnf)
     vnfd_id = vnf['vnfd_id']
     name = vnf.get('name')
     vnf_id = uuidutils.generate_uuid()
     attributes = vnf.get('attributes', {})
     vim_id = vnf.get('vim_id')
     placement_attr = vnf.get('placement_attr', {})
     try:
         with context.session.begin(subtransactions=True):
             vnfd_db = self._get_resource(context, VNFD,
                                          vnfd_id)
             vnf_db = VNF(id=vnf_id,
                          tenant_id=tenant_id,
                          name=name,
                          description=vnfd_db.description,
                          instance_id=None,
                          vnfd_id=vnfd_id,
                          vim_id=vim_id,
                          placement_attr=placement_attr,
                          status=constants.PENDING_CREATE,
                          error_reason=None,
                          deleted_at=datetime.min)
             context.session.add(vnf_db)
             for key, value in attributes.items():
                     arg = VNFAttribute(
                         id=uuidutils.generate_uuid(), vnf_id=vnf_id,
                         key=key, value=value)
                     context.session.add(arg)
     except DBDuplicateEntry as e:
         raise exceptions.DuplicateEntity(
             _type="vnf",
             entry=e.columns)
     evt_details = "VNF UUID assigned."
     self._cos_db_plg.create_event(
         context, res_id=vnf_id,
         res_type=constants.RES_TYPE_VNF,
         res_state=constants.PENDING_CREATE,
         evt_type=constants.RES_EVT_CREATE,
         tstamp=vnf_db[constants.RES_EVT_CREATED_FLD],
         details=evt_details)
     return self._make_vnf_dict(vnf_db)
Пример #7
0
 def _create_vnf_pre(self, context, vnf):
     LOG.debug(_('vnf %s'), vnf)
     tenant_id = self._get_tenant_id_for_create(context, vnf)
     vnfd_id = vnf['vnfd_id']
     name = vnf.get('name')
     vnf_id = str(uuid.uuid4())
     attributes = vnf.get('attributes', {})
     vim_id = vnf.get('vim_id')
     placement_attr = vnf.get('placement_attr', {})
     with context.session.begin(subtransactions=True):
         vnfd_db = self._get_resource(context, VNFD,
                                      vnfd_id)
         vnf_db = VNF(id=vnf_id,
                      tenant_id=tenant_id,
                      name=name,
                      description=vnfd_db.description,
                      instance_id=None,
                      vnfd_id=vnfd_id,
                      vim_id=vim_id,
                      placement_attr=placement_attr,
                      status=constants.PENDING_CREATE,
                      error_reason=None)
         context.session.add(vnf_db)
         for key, value in attributes.items():
                 arg = VNFAttribute(
                     id=str(uuid.uuid4()), vnf_id=vnf_id,
                     key=key, value=value)
                 context.session.add(arg)
     evt_details = "VNF UUID assigned."
     self._cos_db_plg.create_event(
         context, res_id=vnf_id,
         res_type=constants.RES_TYPE_VNF,
         res_state=constants.PENDING_CREATE,
         evt_type=constants.RES_EVT_CREATE,
         tstamp=vnf_db[constants.RES_EVT_CREATED_FLD],
         details=evt_details)
     return self._make_vnf_dict(vnf_db)
Пример #8
0
 def _create_vnf_pre(self, context, vnf):
     LOG.debug(_('vnf %s'), vnf)
     tenant_id = self._get_tenant_id_for_create(context, vnf)
     vnfd_id = vnf['vnfd_id']
     name = vnf.get('name')
     vnf_id = str(uuid.uuid4())
     attributes = vnf.get('attributes', {})
     vim_id = vnf.get('vim_id')
     placement_attr = vnf.get('placement_attr', {})
     with context.session.begin(subtransactions=True):
         vnfd_db = self._get_resource(context, VNFD, vnfd_id)
         vnf_db = VNF(id=vnf_id,
                      tenant_id=tenant_id,
                      name=name,
                      description=vnfd_db.description,
                      instance_id=None,
                      vnfd_id=vnfd_id,
                      vim_id=vim_id,
                      placement_attr=placement_attr,
                      status=constants.PENDING_CREATE,
                      error_reason=None)
         context.session.add(vnf_db)
         for key, value in attributes.items():
             arg = VNFAttribute(id=str(uuid.uuid4()),
                                vnf_id=vnf_id,
                                key=key,
                                value=value)
             context.session.add(arg)
     self._cos_db_plg.create_event(context,
                                   res_id=vnf_id,
                                   res_type=constants.RES_TYPE_VNF,
                                   res_state=constants.PENDING_CREATE,
                                   evt_type=constants.RES_EVT_CREATE,
                                   tstamp=timeutils.utcnow(),
                                   details="VNF UUID assigned")
     return self._make_vnf_dict(vnf_db)