Exemple #1
0
def create_dir(bucket, key):
    try:
        response = minio_client.put_object(Bucket=bucket, Key=key)
    except ClientError as clientError:
        raise MinioCallException(f'An error occurred during creation of dir in Minio: '
                                 f'{clientError}')
    return response
Exemple #2
0
def list_models(namespace: str, id_token):
    if not tenant_exists(namespace, id_token):
        raise TenantDoesNotExistException(namespace)

    apps_api_client = get_k8s_apps_api_client(id_token)
    try:
        deployments = apps_api_client.list_namespaced_deployment(namespace)
    except ApiException as apiException:
        raise KubernetesGetException('deployment', apiException)

    try:
        bucket = minio_resource.Bucket(name=namespace)
    except ClientError as clientError:
        raise MinioCallException(
            f'An error occurred during bucket reading: {clientError}')

    models = []
    for object in bucket.objects.all():
        if object.size > 0:
            model_path = object.key.split('/')[0].rsplit('-', 1)
            model_name = model_path[0]
            model_version = model_path[-1]
            model_size = object.size
            deployment_count = len(
                endpoints_using_model(deployments, model_path))
            models.append(
                (model_name, model_version, model_size, deployment_count))

    if not models:
        return f"There are no models present in {namespace} tenant\n"
    else:
        return f'Models in {namespace} tenant ' \
               f'(model name, model version, model size, deployed count): {models}\n'
Exemple #3
0
def complete_upload(bucket: str, key: str, multipart_id: str, parts: list):
    try:
        minio_client.complete_multipart_upload(Bucket=bucket, Key=key, UploadId=multipart_id,
                                               MultipartUpload={'Parts': parts})
    except ClientError as clientError:
        raise MinioCallException(f'An error occurred during multipart upload finishing: '
                                 f'{clientError}')
Exemple #4
0
def upload_part(data: bytes, part_number: int, bucket: str, key: str, multipart_id: str):
    response = None
    try:
        response = minio_client.upload_part(Body=data, PartNumber=part_number,
                                            Bucket=bucket, Key=key, UploadId=multipart_id)
    except ClientError as clientError:
        raise MinioCallException(f'An error occurred during part uploading: {clientError}')
    return response['ETag']
Exemple #5
0
def create_upload(bucket: str, key: str):
    response = None
    try:
        response = minio_client.create_multipart_upload(Bucket=bucket, Key=key)
    except ClientError as clientError:
        raise MinioCallException(f'An error occurred during multipart upload starting: '
                                 f'{clientError}')
    return response['UploadId']
def create_bucket(name):
    try:
        response = minio_client.create_bucket(Bucket=name)
    except ClientError as clientError:
        raise MinioCallException(
            'An error occurred during bucket creation: {}'.format(clientError))

    logger.info('Bucket created: {}'.format(response))
    return response
Exemple #7
0
def abort_upload(bucket: str, key: str, multipart_id: str):
    try:
        minio_client.abort_multipart_upload(Bucket=bucket,
                                            Key=key,
                                            UploadId=multipart_id)
    except ClientError as clientError:
        raise MinioCallException(
            f'An error occurred during multipart upload abortion: '
            f'{clientError}')
def does_bucket_exist(bucket_name):
    try:
        minio_client.list_objects_v2(Bucket=bucket_name)
    except ClientError as clientError:
        error_code = clientError.response['Error']['Code']
        if error_code == NO_SUCH_BUCKET_EXCEPTION:
            return False
        raise MinioCallException(
            "Error accessing bucket: {}".format(clientError))
    return True
def delete_bucket(name):
    response = 'Bucket {} does not exist'.format(name)
    existed = True
    try:
        bucket = minio_resource.Bucket(name)
        bucket.objects.all().delete()
        response = bucket.delete()
    except ClientError as clientError:
        if clientError.response['Error']['Code'] != NO_SUCH_BUCKET_EXCEPTION:
            raise MinioCallException(
                "A error occurred during bucket deletion: {}".format(
                    clientError))
        existed = False
    if existed:
        logger.info('Bucket {} deleted'.format(name))
    else:
        logger.info('Bucket {} does not exist'.format(name))
    return response
def list_models(namespace: str, id_token):
    # TODO Add checking if model is used by endpoint
    if not tenant_exists(namespace, id_token):
        raise TenantDoesNotExistException(namespace)

    try:
        bucket = minio_resource.Bucket(name=namespace)
    except ClientError as clientError:
        raise MinioCallException(
            f'An error occurred during bucket reading: {clientError}')

    models = []
    for object in bucket.objects.all():
        if object.size > 0:
            model = dict()
            model_path = object.key.split('/', 2)
            model['path'] = object.key
            model['name'] = model_path[0]
            model['version'] = model_path[1]
            model['size'] = object.size
            models.append(model)

    logger.info(f'Models present in {namespace} tenant: {models}')
    return models