コード例 #1
0
ファイル: artifact_api.py プロジェクト: i-newton/glare
    def list(self,
             context,
             filters,
             marker,
             limit,
             sort,
             latest,
             list_all_artifacts=False):
        """List artifacts from db

        :param context: user request context
        :param filters: filter conditions from url
        :param marker: id of first artifact where we need to start
        artifact lookup
        :param limit: max number of items in list
        :param sort: sort conditions
        :param latest: flag that indicates, that only artifacts with highest
        versions should be returned in output
        :param list_all_artifacts: flag that indicate, if the list should
        return artifact from all realms (True),
        or from the specific realm (False)
        :return: list of artifacts. Each artifact is represented as dict of
        values.
        """
        session = api.get_session()
        return api.get_all(context=context,
                           session=session,
                           filters=filters,
                           marker=marker,
                           limit=limit,
                           sort=sort,
                           latest=latest,
                           list_all_artifacts=list_all_artifacts)
コード例 #2
0
ファイル: artifact_api.py プロジェクト: i-newton/glare
    def delete(self, context, artifact_id):
        """Delete artifacts from db

        :param context: user context
        :param artifact_id: id of artifact that needs to be deleted
        """
        session = api.get_session()
        api.delete(context, artifact_id, session)
コード例 #3
0
ファイル: artifact_api.py プロジェクト: Fedosin/glare
 def list(self, context, filters, marker, limit, sort):
     session = api.get_session()
     filters.append(('type_name', None, 'eq', None, self.type))
     return api.get_all(context=context,
                        session=session,
                        filters=filters,
                        marker=marker,
                        limit=limit,
                        sort=sort)
コード例 #4
0
ファイル: quota.py プロジェクト: i-newton/glare
def verify_uploaded_data_amount(context, type_name, data_amount=None):
    """Verify if user can upload data based on his quota limits.

    :param context: user context
    :param type_name: name of artifact type
    :param data_amount: number of bytes user wants to upload. Value None means
     that user hasn't specified data amount. In this case don't raise an
     exception, but just return the amount of data he is able to upload.
    :return: number of bytes user can upload if data_amount isn't specified
    """
    global_limit = CONF.max_uploaded_data
    type_limit = getattr(CONF, 'artifact_type:' + type_name).max_uploaded_data

    # update limits if they were reassigned for project
    project_id = context.project_id
    quotas = list_quotas(project_id).get(project_id, {})
    if 'max_uploaded_data' in quotas:
        global_limit = quotas['max_uploaded_data']
    if 'max_uploaded_data:' + type_name in quotas:
        type_limit = quotas['max_uploaded_data:' + type_name]

    session = api.get_session()
    res = -1

    if global_limit != -1:
        # the whole amount of created artifacts
        whole_number = api.calculate_uploaded_data(context, session)
        if data_amount is None:
            res = global_limit - whole_number
        elif whole_number + data_amount > global_limit:
            msg = _("Can't upload %(data_amount)d byte(s) because of global "
                    "quota limit: %(global_limit)d. "
                    "You have %(whole_number)d bytes uploaded.") % {
                        'data_amount': data_amount,
                        'global_limit': global_limit,
                        'whole_number': whole_number
                    }
            raise exception.RequestEntityTooLarge(msg)

    if type_limit != -1:
        # the amount of artifacts for specific type
        type_number = api.calculate_uploaded_data(context, session, type_name)
        if data_amount is None:
            available = type_limit - type_number
            res = available if res == -1 else min(res, available)
        elif type_number + data_amount > type_limit:
            msg = _("Can't upload %(data_amount)d byte(s) because of "
                    "quota limit for artifact type '%(type_name)s': "
                    "%(type_limit)d. You have %(type_number)d bytes "
                    "uploaded for this type.") % {
                        'data_amount': data_amount,
                        'type_name': type_name,
                        'type_limit': type_limit,
                        'type_number': type_number
                    }
            raise exception.RequestEntityTooLarge(msg)
    return res
コード例 #5
0
ファイル: artifact_api.py プロジェクト: i-newton/glare
    def count_artifact_number(self, context, type_name=None):
        """Count the number of artifacts for the tenant.

        :param context: user context
        :param type_name: name of specific artifact type to count artifacts.
         If None count artifacts of all types.
        :return: number of artifacts for given tenant
        """
        session = api.get_session()
        return api.count_artifact_number(context, session, type_name)
コード例 #6
0
ファイル: artifact_api.py プロジェクト: i-newton/glare
    def calculate_uploaded_data(self, context, type_name=None):
        """Calculate the amount of uploaded data for tenant.

        :param context: user context
        :param type_name: name of specific artifact type to calculate data.
         If None calculate data of artifacts of all types.
        :return: amount of uploaded data for given user
        """
        session = api.get_session()
        return api.calculate_uploaded_data(context, session, type_name)
コード例 #7
0
ファイル: artifact_api.py プロジェクト: i-newton/glare
    def update_blob(self, context, artifact_id, values):
        """Create and update blob records in db

        :param artifact_id: id of artifact that needs to be updated
        :param context: user context
        :param values: blob values that needs to be updated
        :return: dict of updated artifact values
        """
        session = api.get_session()
        return api.create_or_update(context, artifact_id, {'blobs': values},
                                    session)
コード例 #8
0
 def run(self, event=None):
     while True:
         artifacts = db_api._get_all(
             context=self.context,
             session=db_api.get_session(),
             limit=CONF.scrubber.scrub_pool_size,
             sort=[],
             filters=[('status', None, 'eq', None, 'deleted', 'and')])
         if not artifacts:
             break
         self.pool.imap(self._scrub_artifact, artifacts)
コード例 #9
0
ファイル: artifact_api.py プロジェクト: i-newton/glare
    def save(self, context, artifact_id, values):
        """Save artifact values in database

        :param artifact_id: id of artifact that needs to be updated
        :param context: user context
        :param values: values that needs to be updated
        :return: dict of updated artifact values
        """
        session = api.get_session()
        return api.create_or_update(context, artifact_id,
                                    self._serialize_values(values), session)
コード例 #10
0
ファイル: artifact_api.py プロジェクト: i-newton/glare
    def get(self, context, type_name, artifact_id, get_any_artifact=False):
        """Return artifact values from database

        :param context: user context
        :param type_name: artifact type name or None for metatypes
        :param artifact_id: id of the artifact
        :param get_any_artifact: flag that indicate, if we want to enable
        to get artifact from other realm as well.
        :return: dict of artifact values
        """
        session = api.get_session()
        return api.get(context, type_name, artifact_id, session,
                       get_any_artifact)
コード例 #11
0
    def _scrub_artifact(af):
        LOG.info("Begin scrubbing of artifact %s", af.id)
        for blob in af.blobs:
            if not blob.external:
                try:
                    store_api.delete_blob(blob.url, context=context)
                except exception.NotFound:
                    # data has already been removed
                    pass
        LOG.info("Blobs successfully deleted for artifact %s", af.id)

        # delete artifact itself
        db_api.delete(context, af.id, db_api.get_session())

        LOG.info("Artifact %s was scrubbed", af.id)
コード例 #12
0
ファイル: quota.py プロジェクト: i-newton/glare
def verify_artifact_count(context, type_name):
    """Verify if user can upload data based on his quota limits.

    :param context: user context
    :param type_name: name of artifact type
    """
    global_limit = CONF.max_artifact_number
    type_limit = getattr(CONF,
                         'artifact_type:' + type_name).max_artifact_number

    # update limits if they were reassigned for project
    project_id = context.project_id
    quotas = list_quotas(project_id).get(project_id, {})
    if 'max_artifact_number' in quotas:
        global_limit = quotas['max_artifact_number']
    if 'max_artifact_number:' + type_name in quotas:
        type_limit = quotas['max_artifact_number:' + type_name]

    session = api.get_session()

    if global_limit != -1:
        # the whole amount of created artifacts
        whole_number = api.count_artifact_number(context, session)

        if whole_number >= global_limit:
            msg = _("Can't create artifact because of global quota "
                    "limit is %(global_limit)d artifacts. "
                    "You have %(whole_number)d artifact(s).") % {
                        'global_limit': global_limit,
                        'whole_number': whole_number
                    }
            raise exception.Forbidden(msg)

    if type_limit != -1:
        # the amount of artifacts for specific type
        type_number = api.count_artifact_number(context, session, type_name)

        if type_number >= type_limit:
            msg = _("Can't create artifact because of quota limit for "
                    "artifact type '%(type_name)s' is %(type_limit)d "
                    "artifacts. You have %(type_number)d artifact(s) "
                    "of this type.") % {
                        'type_name': type_name,
                        'type_limit': type_limit,
                        'type_number': type_number
                    }
            raise exception.Forbidden(msg)
コード例 #13
0
ファイル: quota.py プロジェクト: i-newton/glare
def list_quotas(project_id=None):
    session = api.get_session()
    return api.get_all_quotas(session, project_id)
コード例 #14
0
 def delete_lock(self, context, lock_id):
     session = api.get_session()
     api.delete_lock(context, lock_id, session)
コード例 #15
0
ファイル: models.py プロジェクト: Fedosin/glare
    def save(self, session=None):
        from glare.db.sqlalchemy import api as db_api

        super(ArtifactBase, self).save(session or db_api.get_session())
コード例 #16
0
ファイル: quota.py プロジェクト: i-newton/glare
def set_quotas(values):
    session = api.get_session()
    api.set_quotas(values, session)
コード例 #17
0
 def get(self, context, artifact_id):
     session = api.get_session()
     return api.get(context, artifact_id, session)
コード例 #18
0
 def add_to_backend(self, blob_id, data, context, verifier=None):
     session = db_api.get_session()
     return db_api.save_blob_data(context, blob_id, data, session)
コード例 #19
0
 def delete(self, context, artifact_id):
     session = api.get_session()
     return api.delete(context, artifact_id, session)
コード例 #20
0
 def update(self, context, artifact_id, values):
     session = api.get_session()
     return api.update(context, artifact_id, self._serialize_values(values),
                       session)
コード例 #21
0
 def create(self, context, values):
     values = self._serialize_values(values)
     values['type_name'] = self.type
     session = api.get_session()
     return api.create(context, values, session)
コード例 #22
0
 def add_to_backend_batch(self, blobs, context, verifier=None):
     session = db_api.get_session()
     return db_api.save_blob_data_batch(context, blobs, session)
コード例 #23
0
 def delete_from_store(self, uri, context):
     session = db_api.get_session()
     return db_api.delete_blob_data(context, uri, session)
コード例 #24
0
    def save(self, session=None):
        from glare.db.sqlalchemy import api as db_api

        super(ArtifactBase, self).save(session or db_api.get_session())
コード例 #25
0
 def create_lock(self, context, lock_key):
     session = api.get_session()
     return api.create_lock(context, lock_key, session)