1

2 6
import logging
3

4 6
from django.db import models
5

6 6
from cyborgbackup.api.versioning import reverse
7 6
from cyborgbackup.main.models.base import PrimordialModel
8 6
from cyborgbackup.main.utils.common import copy_model_by_class, copy_m2m_relationships
9

10 6
logger = logging.getLogger('cyborgbackup.models.Repository')
11

12 6
__all__ = ['Repository']
13

14

15 6
class Repository(PrimordialModel):
16

17 6
    name = models.CharField(
18
        max_length=1024,
19
    )
20

21 6
    path = models.CharField(
22
        max_length=1024,
23
    )
24

25 6
    enabled = models.BooleanField(
26
        default=True
27
    )
28

29 6
    repository_key = models.CharField(
30
        max_length=1024,
31
    )
32

33 6
    ready = models.BooleanField(
34
        default=False
35
    )
36

37 6
    original_size = models.BigIntegerField(
38
        default=0
39
    )
40

41 6
    compressed_size = models.BigIntegerField(
42
        default=0
43
    )
44

45 6
    deduplicated_size = models.BigIntegerField(
46
        default=0
47
    )
48

49 6
    latest_prepare = models.DateTimeField(
50
        null=True,
51
        default=None,
52
        editable=False,
53
    )
54

55 6
    def get_absolute_url(self, request=None):
56 6
        return reverse('api:repository_detail', kwargs={'pk': self.pk}, request=request)
57

58 6
    def get_ui_url(self):
59 0
        return "/#/repositories/{}".format(self.pk)
60

61 6
    @classmethod
62
    def get_cache_key(self, key):
63 0
        return key
64

65 6
    @classmethod
66
    def get_cache_id_key(self, key):
67 0
        return '{}_ID'.format(key)
68

69 6
    @classmethod
70
    def _get_job_class(cls):
71 0
        from cyborgbackup.main.models.jobs import Job
72 0
        return Job
73

74 6
    def create_prepare_repository(self, **kwargs):
75
        '''
76
        Create a new prepare job for this repository.
77
        '''
78 0
        eager_fields = kwargs.pop('_eager_fields', None)
79

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

87 0
        job = copy_model_by_class(self, job_class, fields, kwargs)
88

89 0
        if eager_fields:
90 0
            for fd, val in eager_fields.items():
91 0
                setattr(job, fd, val)
92

93
        # Set the job back-link on the job
94 0
        job.repository_id = self.pk
95 0
        job.name = "Prepare Repository {}".format(self.name)
96 0
        job.description = "Repository {} Borg Preparation".format(self.name)
97 0
        job.save()
98

99 0
        from cyborgbackup.main.signals import disable_activity_stream
100 0
        fields = ()
101 0
        with disable_activity_stream():
102 0
            copy_m2m_relationships(self, job, fields, kwargs=kwargs)
103

104 0
        return job

Read our documentation on viewing source code .

Loading