Beispiel #1
0
    def post(self, request, pid, command=None):
        pool = self._validate_pool(pid, request)
        if command is not None and command != "status":
            e_msg = "Unknown scrub command: ({}).".format(command)
            handle_exception(Exception(e_msg), request)

        with self._handle_exception(request):
            ps = self._scrub_status(pool)
            if command == "status":
                return Response(PoolScrubSerializer(ps).data)
            force = request.data.get("force", False)
            if PoolScrub.objects.filter(
                    pool=pool, status__regex=r"(started|running)").exists():
                if force:
                    p = PoolScrub.objects.filter(
                        pool=pool,
                        status__regex=r"(started|running)").order_by("-id")[0]
                    p.status = "terminated"
                    p.save()
                else:
                    e_msg = ("A Scrub process is already running for "
                             "pool ({}). If you really want to kill it "
                             "and start a new scrub, use the force "
                             "option.").format(pool.name)
                    handle_exception(Exception(e_msg), request)

            scrub_pid = scrub_start(pool, force=force)
            ps = PoolScrub(pool=pool, pid=scrub_pid)
            ps.save()
            return Response(PoolScrubSerializer(ps).data)
Beispiel #2
0
    def post(self, request, pid, command=None):
        pool = self._validate_pool(pid, request)
        if (command is not None and command != 'status'):
            e_msg = 'Unknown scrub command: ({}).'.format(command)
            handle_exception(Exception(e_msg), request)

        with self._handle_exception(request):
            ps = self._scrub_status(pool)
            if (command == 'status'):
                return Response(PoolScrubSerializer(ps).data)
            force = request.data.get('force', False)
            if ((PoolScrub.objects.filter(pool=pool,
                                          status__regex=r'(started|running)')
                 .exists())):
                if (force):
                    p = PoolScrub.objects.filter(
                        pool=pool,
                        status__regex=r'(started|running)').order_by('-id')[0]
                    p.status = 'terminated'
                    p.save()
                else:
                    e_msg = ('A Scrub process is already running for '
                             'pool ({}). If you really want to kill it '
                             'and start a new scrub, use the force '
                             'option.').format(pool.name)
                    handle_exception(Exception(e_msg), request)

            scrub_pid = scrub_start(pool, force=force)
            ps = PoolScrub(pool=pool, pid=scrub_pid)
            ps.save()
            return Response(PoolScrubSerializer(ps).data)
Beispiel #3
0
    def post(self, request, pname, command=None):
        pool = self._validate_pool(pname, request)
        if (command is not None and command != 'status'):
            e_msg = ('Unknown scrub command: %s' % command)
            handle_exception(Exception(e_msg), request)

        with self._handle_exception(request):
            ps = self._scrub_status(pool)
            if (command == 'status'):
                return Response(PoolScrubSerializer(ps).data)
            force = request.data.get('force', False)
            if ((PoolScrub.objects.filter(pool=pool,
                                          status__regex=r'(started|running)')
                 .exists())):
                if (force):
                    p = PoolScrub.objects.filter(
                        pool=pool,
                        status__regex=r'(started|running)').order_by('-id')[0]
                    p.status = 'terminated'
                    p.save()
                else:
                    e_msg = ('A Scrub process is already running for '
                             'pool(%s). If you really want to kill it '
                             'and start a new scrub, use force option' % pname)
                    handle_exception(Exception(e_msg), request)

            scrub_pid = scrub_start(pool, force=force)
            ps = PoolScrub(pool=pool, pid=scrub_pid)
            ps.save()
            return Response(PoolScrubSerializer(ps).data)
Beispiel #4
0
    def post(self, request, pname, command=None):
        pool = self._validate_pool(pname, request)
        if (command is not None and command != 'status'):
            e_msg = ('Unknown scrub command: %s' % command)
            handle_exception(Exception(e_msg), request)

        try:
            disk = Disk.objects.filter(pool=pool)[0]
            if (command == 'status'):
                try:
                    ps = PoolScrub.objects.filter(pool=pool).order_by('-id')[0]
                except:
                    return Response()
                if (ps.status == 'started' or ps.status == 'running'):
                    cur_status = scrub_status(pname, disk.name)
                    ps.status = cur_status['status']
                    if (cur_status['status'] == 'finished'):
                        duration = int(cur_status['duration'])
                        ps.end_time = (ps.start_time +
                                       timedelta(seconds=duration))
                        ps.kb_scrubbed = cur_status['kb_scrubbed']
                        ps.errors = cur_status['errors']
                        ps.save()
                return Response(PoolScrubSerializer(ps).data)

            if ((PoolScrub.objects.filter(pool=pool,
                                          status__regex=r'(started|running)')
                 .exists())):
                e_msg = ('Active scrub exists for the pool: %s' % pname)
                handle_exception(Exception(e_msg), request)

            scrub_pid = scrub_start(pname, disk.name)
            ps = PoolScrub(pool=pool, pid=scrub_pid)
            ps.save()
            return Response(PoolScrubSerializer(ps).data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)