Example #1
0
    def get_by_uuid(self, uuid):
        with self.new_session() as s:
            source = s.query(Source).filter(Source.uuid == uuid).first()

            if not source:
                raise NoSuchSource(uuid)

            return self._from_db_format(source)
Example #2
0
    def get(self, backend, source_uuid, visible_tenants):
        filter_ = self._multi_tenant_filter(backend, source_uuid, visible_tenants)
        with self.new_session() as s:
            source = s.query(Source).filter(filter_).first()

            if not source:
                raise NoSuchSource(source_uuid)

            return self._from_db_format(source)
Example #3
0
    def delete(self, backend, source_uuid, visible_tenants):
        filter_ = self._multi_tenant_filter(backend, source_uuid,
                                            visible_tenants)
        with self.new_session() as s:
            nb_deleted = s.query(Source).filter(filter_).delete(
                synchronize_session=False)

        if not nb_deleted:
            raise NoSuchSource(source_uuid)
Example #4
0
    def edit(self, backend, source_uuid, visible_tenants, body):
        filter_ = self._multi_tenant_filter(backend, source_uuid, visible_tenants)
        with self.new_session() as s:
            source = s.query(Source).filter(filter_).first()

            if not source:
                raise NoSuchSource(source_uuid)

            self._update_to_db_format(source, **body)
            try:
                s.flush()
            except exc.IntegrityError as e:
                if e.orig.pgcode == self._UNIQUE_CONSTRAINT_CODE:
                    raise DuplicatedSourceException(body['name'])
                raise