Beispiel #1
0
    def check_job_status(self):
        # preventing circular import
        from ganeti_webmgr.jobs.models import Job

        if not self.last_job_id:
            return {}

        ct = ContentType.objects.get_for_model(self)
        qs = Job.objects.filter(content_type=ct, object_id=self.pk)
        jobs = qs.order_by("job_id")

        updates = {}
        status = 'unknown'
        op = None

        for job in jobs:
            try:
                data = self.rapi.GetJobStatus(job.job_id)

                if Job.valid_job(data):
                    op = Job.parse_op(data)
                    status = data['status']

            except GanetiApiError:
                pass

            if status in ('success', 'error'):
                for k, v in Job.parse_persistent_info(data).items():
                    setattr(job, k, v)

            if status == 'unknown':
                job.status = "unknown"
                job.ignore_cache = False

            if status in ('success', 'error', 'unknown'):
                _updates = self._complete_job(self.cluster_id, self.hostname,
                                              op, status)
                # XXX if the delete flag is set in updates then delete this
                # model this happens here because _complete_job cannot delete
                # this model
                if _updates:
                    if 'deleted' in _updates:
                        # Delete ourselves. Also delete the job that caused us
                        # to delete ourselves; see #8439 for "fun" details.
                        # Order matters; the job's deletion cascades over us.
                        # Revisit that when we finally nuke all this caching
                        # bullshit.
                        self.delete()
                        job.delete()
                    else:
                        updates.update(_updates)

        # we only care about the very last job for resetting the cache flags
        if not jobs or status in ('success', 'error', 'unknown'):
            updates['ignore_cache'] = False
            updates['last_job'] = None

        return updates
Beispiel #2
0
    def check_job_status(self):
        # preventing circular import
        from ganeti_webmgr.jobs.models import Job

        if not self.last_job_id:
            return {}

        ct = ContentType.objects.get_for_model(self)
        qs = Job.objects.filter(content_type=ct, object_id=self.pk)
        jobs = qs.order_by("job_id")

        updates = {}
        status = 'unknown'
        op = None

        for job in jobs:
            try:
                data = self.rapi.GetJobStatus(job.job_id)

                if Job.valid_job(data):
                    op = Job.parse_op(data)
                    status = data['status']

            except GanetiApiError:
                pass

            if status in ('success', 'error'):
                for k, v in Job.parse_persistent_info(data).items():
                    setattr(job, k, v)

            if status == 'unknown':
                job.status = "unknown"
                job.ignore_cache = False

            if status in ('success', 'error', 'unknown'):
                _updates = self._complete_job(self.cluster_id,
                                              self.hostname, op, status)
                # XXX if the delete flag is set in updates then delete this
                # model this happens here because _complete_job cannot delete
                # this model
                if _updates:
                    if 'deleted' in _updates:
                        # Delete ourselves. Also delete the job that caused us
                        # to delete ourselves; see #8439 for "fun" details.
                        # Order matters; the job's deletion cascades over us.
                        # Revisit that when we finally nuke all this caching
                        # bullshit.
                        self.delete()
                        job.delete()
                    else:
                        updates.update(_updates)

        # we only care about the very last job for resetting the cache flags
        if not jobs or status in ('success', 'error', 'unknown'):
            updates['ignore_cache'] = False
            updates['last_job'] = None

        return updates