Exemplo n.º 1
0
    def run_job(self, id, action_id):

        # To prevent duplication
        old = self.db2.query(Job).filter( and_(
                Job.user_id == self.current_user.id,
                Job.target_type == JOB_TARGET['INSTANCE'],
                Job.target_id == id,
                Job.action == action_id,
                Job.status == settings.JOB_S_INITIATED ) ).all()

        if old: return (None,  _("Can not run duplication job!"))

        # TODO: when a job is running, can not rerun also !

        # Create new job
        job = Job( user = self.current_user,
                   target_type = JOB_TARGET['INSTANCE'],
                   target_id = id,
                   action = action_id )

        self.db2.add(job)
        self.db2.commit()
        try:
            self._job_notify( job.id )
        except Exception, e:
            #[Errno 113] No route to host
            # TODO: should be a config value
            job.status = settings.JOB_S_FAILED
            self.db2.commit()
            return (None, _("Connect to control server error: %s") % e)
Exemplo n.º 2
0
    def run_job(self, I, action_id):

        if I.lastjob and (not I.lastjob.completed):
            if not ( action_id == JOB_ACTION['STOP_INSTANCE'] and
                 I.lastjob.canstop ):
                # TODO: status = 100, timeout > 60s
                timeout = I.lastjob.created + relativedelta.relativedelta(seconds=+60)
                if timeout > datetime.now():
                    return self.trans(_("Previous task is not finished !"))


        # Create new job
        job = Job( user = self.current_user,
                   target_type = JOB_TARGET['INSTANCE'],
                   target_id = I.id,
                   action = action_id )

        self.db2.add(job)
        self.db2.commit()
        
        I.lastjob = job

        try:
            self._job_notify( job.id )
        except Exception, e:
            #[Errno 113] No route to host
            # TODO: should be a config value
            job.status = settings.JOB_S_FAILED
            return self.trans(_("Connect to control server failed: %s")) % e
Exemplo n.º 3
0
    def run_job(self, I, action_id):

        lastjob = self.get_instance_lastjob(I)

        if lastjob:

            timeout = lastjob.created + relativedelta.relativedelta(seconds=+60)

            if not lastjob.completed:
                if not (action_id == JOB_ACTION["STOP_INSTANCE"] and lastjob.canstop):
                    # TODO: status = 100, timeout > 60s
                    if timeout > datetime.datetime.now():
                        return self.trans(_("Previous task is not finished !"))

            if lastjob.status == settings.JOB_S_FAILED:
                if timeout > datetime.datetime.now():
                    return self.trans(_("Previous task was failed, wait a moment please."))

        # Create new job
        job = Job(user=self.current_user, target_type=JOB_TARGET["INSTANCE"], target_id=I.id, action=action_id)

        self.db.add(job)
        self.db.commit()

        try:
            self._job_notify(job.id)
        except Exception, e:
            # [Errno 113] No route to host
            # TODO: should be a config value
            job.status = settings.JOB_S_FAILED
            self.db.commit()
            return _("Connect to control server failed: %s") % e
Exemplo n.º 4
0
    def run_job(self, I, action_id):

        if I.lastjob and (not I.lastjob.completed):
            if not (action_id == JOB_ACTION['STOP_INSTANCE']
                    and I.lastjob.canstop):
                # TODO: status = 100, timeout > 60s
                timeout = I.lastjob.created + relativedelta.relativedelta(
                    seconds=+60)
                if timeout > datetime.now():
                    return self.trans(_("Previous task is not finished !"))

        # Create new job
        job = Job(user=self.current_user,
                  target_type=JOB_TARGET['INSTANCE'],
                  target_id=I.id,
                  action=action_id)

        self.db2.add(job)
        self.db2.commit()

        I.lastjob = job

        try:
            self._job_notify(job.id)
        except Exception, e:
            #[Errno 113] No route to host
            # TODO: should be a config value
            job.status = settings.JOB_S_FAILED
            return self.trans(_("Connect to control server failed: %s")) % e
Exemplo n.º 5
0
    def run_job(self, id, action_id):

        # To prevent duplication
        old = self.db2.query(Job).filter( and_(
                Job.user_id == self.current_user.id,
                Job.target_type == JOB_TARGET['INSTANCE'],
                Job.target_id == id,
                Job.action == action_id,
                Job.status == settings.JOB_S_INITIATED ) ).all()

        if old: return (None,  _("Can not run duplication job!"))

        # TODO: when a job is running, can not rerun also !

        # Create new job
        job = Job( user = self.current_user,
                   target_type = JOB_TARGET['INSTANCE'],
                   target_id = id,
                   action = action_id )

        self.db2.add(job)
        self.db2.commit()
        try:
            self._job_notify( job.id )
        except Exception, e:
            #[Errno 113] No route to host
            # TODO: should be a config value
            job.status = settings.JOB_S_FAILED
            self.db2.commit()
            return (None, _("Connect to control server error: %s") % e)