Пример #1
0
    def download(self, request, *args, **kwargs):
        """
        Download the volume data.
        """
        volume = self.get_object()

        # Check whether project is corresponding to the user
        user = request.user
        if not check_member_in_project(volume.project, user):
            raise PermissionDenied(
                detail="User {} is not in project {}.".format(
                    user.username, volume.project.name))

        logger.info("User {} download the data of volume {}-{}.".format(
            request.user.username, volume.project.name, volume.name))

        # Copy file to local first
        volume_dir = get_volume_direction_on_nfs(volume)
        filename = get_upload_volume_filename(volume, request.user)
        client = NFSLocalClient()
        client.tar_and_copy_to_local(volume_dir, filename)

        response = StreamingHttpResponse(big_file_iterator(filename))
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="{}"'.format(
            os.path.basename(filename))

        return response
Пример #2
0
    def download(self, request, *args, **kwargs):
        """
        Download the volume data.
        """
        volume = self.get_object()

        # Check whether project is corresponding to the user
        user = request.user
        if not check_member_in_project(volume.project, user):
            raise PermissionDenied(detail="User {} is not in project {}."
                .format(user.username, volume.project.name))

        logger.info("User {} download the data of volume {}-{}.".format(
            request.user.username, volume.project.name, volume.name))

        # Copy file to local first
        volume_dir = get_volume_direction_on_nfs(volume)
        filename = get_upload_volume_filename(volume, request.user)
        client = NFSLocalClient()
        client.tar_and_copy_to_local(volume_dir, filename)

        response = StreamingHttpResponse(big_file_iterator(filename))
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="{}"'.format(
            os.path.basename(filename))

        return response
Пример #3
0
def upload_volume(request, *args, **kwargs):
    """
    User upload volume data, delete the original data first.
    """
    if not (request.user and request.user.is_authenticated()):
        raise PermissionDenied()

    user = request.user

    assert 'pid' in kwargs
    pid = kwargs['pid']

    assert 'pk' in kwargs
    id = kwargs['pk']
    volume = Volume.objects.get(project__id=pid, id=id)

    # Check whether the user is the member of this project
    if not check_member_in_project(volume.project, user):
        raise PermissionDenied(detail="User {} is not in project {}.".format(
            user.username, volume.project.name))

    if not request.FILES.get('file'):
        raise ParseError(detail="There is no upload file.")

    logger.info("User {} upload files to volume {}-{}.".format(
        user.username, volume.project.name, volume.name))

    filename = get_upload_volume_filename(volume, user)
    save_upload_file_to_disk(request.FILES['file'], filename)

    client = NFSLocalClient()
    volume_dir = get_volume_direction_on_nfs(volume)
    # Clear the dir first
    client.removedir(volume_dir)
    client.makedir(volume_dir)

    client.copy_file_to_remote_and_untar(filename, volume_dir)
    remove_file_from_disk(filename)

    return JsonResponse({"detail": "success"})
Пример #4
0
def upload_volume(request, *args, **kwargs):
    """
    User upload volume data, delete the original data first.
    """
    if not (request.user and request.user.is_authenticated()):
        raise PermissionDenied()

    user = request.user

    assert 'pid' in kwargs
    pid = kwargs['pid']

    assert 'pk' in kwargs
    id = kwargs['pk']
    volume = Volume.objects.get(project__id=pid, id=id)

    # Check whether the user is the member of this project
    if not check_member_in_project(volume.project, user):
        raise PermissionDenied(detail="User {} is not in project {}."
            .format(user.username, volume.project.name))

    if not request.FILES.get('file'):
        raise ParseError(detail="There is no upload file.")

    logger.info("User {} upload files to volume {}-{}.".format(
        user.username, volume.project.name, volume.name))

    filename = get_upload_volume_filename(volume, user)
    save_upload_file_to_disk(request.FILES['file'], filename)

    client = NFSLocalClient()
    volume_dir = get_volume_direction_on_nfs(volume)
    # Clear the dir first
    client.removedir(volume_dir)
    client.makedir(volume_dir)

    client.copy_file_to_remote_and_untar(filename, volume_dir)
    remove_file_from_disk(filename)

    return JsonResponse({"detail": "success"})