Exemplo n.º 1
0
    def create_job(self, **kwargs):
        '''
        Create a new job based on this job.
        '''
        eager_fields = kwargs.pop('_eager_fields', None)

        job_class = self.__class__
        fields = self._get_job_field_names()
        unallowed_fields = set(kwargs.keys()) - set(fields)
        if unallowed_fields:
            logger.warn('Fields {} are not allowed as overrides.'.format(
                unallowed_fields))
            map(kwargs.pop, unallowed_fields)

        job = copy_model_by_class(self, job_class, fields, kwargs)

        if eager_fields:
            for fd, val in eager_fields.items():
                setattr(job, fd, val)

        # Set the job back-link on the job
        parent_field_name = job_class._get_parent_field_name()
        setattr(job, parent_field_name, self)

        job.save()

        from cyborgbackup.main.signals import disable_activity_stream
        with disable_activity_stream():
            copy_m2m_relationships(self, job, fields, kwargs=kwargs)

        job.create_config_from_prompts(kwargs)

        return job
Exemplo n.º 2
0
    def create_prepare_repository(self, **kwargs):
        '''
        Create a new prepare job for this repository.
        '''
        eager_fields = kwargs.pop('_eager_fields', None)

        job_class = self._get_job_class()
        fields = ('extra_vars', 'job_type')
        unallowed_fields = set(kwargs.keys()) - set(fields)
        if unallowed_fields:
            logger.warn('Fields {} are not allowed as overrides.'.format(
                unallowed_fields))
            map(kwargs.pop, unallowed_fields)

        job = copy_model_by_class(self, job_class, fields, kwargs)

        if eager_fields:
            for fd, val in eager_fields.items():
                setattr(job, fd, val)

        # Set the job back-link on the job
        job.repository_id = self.pk
        job.name = "Prepare Repository {}".format(self.name)
        job.description = "Repository {} Borg Preparation".format(self.name)
        job.save()

        from cyborgbackup.main.signals import disable_activity_stream
        fields = ()
        with disable_activity_stream():
            copy_m2m_relationships(self, job, fields, kwargs=kwargs)

        return job
Exemplo n.º 3
0
    def copy_job(self, limit=None):
        '''
        Returns saved object, including related fields.
        Create a copy of this unified job for the purpose of relaunch
        '''
        job_class = self.__class__
        parent_field_name = 'job'
        fields = job_class._get_job_field_names() | set([parent_field_name])

        create_data = {"launch_type": "relaunch"}
        if limit:
            create_data["limit"] = limit

        copy_job = copy_model_by_class(self, job_class, fields, {})
        for fd, val in create_data.items():
            setattr(copy_job, fd, val)
        copy_job.old_pk = self.pk
        copy_job.save()

        # Labels coppied here
        copy_m2m_relationships(self, copy_job, fields)
        return copy_job