This file is indexed.

/usr/lib/python2.7/dist-packages/maasserver/models/downloadprogress.py is in python-django-maas 1.5.4+bzr2294-0ubuntu1.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright 2013 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Model to record progress of boot-image downloads."""

from __future__ import (
    absolute_import,
    print_function,
    unicode_literals,
    )

str = None

__metaclass__ = type
__all__ = [
    'DownloadProgress',
    ]


from django.core.exceptions import ValidationError
from django.db.models import (
    CharField,
    ForeignKey,
    IntegerField,
    Manager,
    )
from maasserver import DefaultMeta
from maasserver.models.cleansave import CleanSave
from maasserver.models.timestampedmodel import TimestampedModel


class DownloadProgressManager(Manager):
    """Manager for `DownloadProgress`.

    Don't import or instantiate this directly; access as `<Class>.objects` on
    the model class it manages.
    """

    def get_latest_download(self, nodegroup, filename):
        """Return the latest `DownloadProgress` for a download, or None."""
        reports = self.filter(nodegroup=nodegroup, filename=filename)
        latest = reports.order_by('-id')[:1]
        if len(latest) > 0:
            return latest[0]
        else:
            return None


def validate_nonnegative_if_given(value):
    """Django validator: `value` must be either `None`, zero, or positive."""
    if value is not None and value < 0:
        raise ValidationError("Number must not be negative (got %s)." % value)


class DownloadProgress(CleanSave, TimestampedModel):
    """Progress report from a cluster for one of its boot-image downloads.

    Each download on each cluster controller gets its own record.  The
    `bytes_downloaded` and last-change timestamp are updated with each progress
    report for that download.  The creation timestamp reflects the time of the
    download's first progress report.

    A cluster may download a file of the same name as a file it has downloaded
    once already.  The new download will have a new record.

    The download is complete when `bytes_downloaded` equals `size`, provided
    there is no error.  A download with a non-blank error is considered to have
    failed.

    :ivar nodegroup: The cluster whose controller is doing this download.
    :ivar filename: Name of the file being downloaded.
    :ivar size: Size of the file, in bytes.  This may not be known in advance,
        but must be set at some point for any successful download.
    :ivar bytes_downloaded: Number of bytes that have been downloaded.
    :ivar error: Failure message.
    """

    class Meta(DefaultMeta):
        """Needed for South to recognize this model."""

    objects = DownloadProgressManager()

    nodegroup = ForeignKey('maasserver.NodeGroup', editable=False)

    filename = CharField(max_length=255, editable=False)

    size = IntegerField(
        blank=True, null=True, validators=[validate_nonnegative_if_given])

    bytes_downloaded = IntegerField(
        blank=True, null=True, validators=[validate_nonnegative_if_given])

    error = CharField(max_length=1000, blank=True)

    def clean(self):
        if self.bytes_downloaded is not None and self.size is not None:
            if self.bytes_downloaded > self.size:
                raise ValidationError(
                    "Downloaded more bytes than the file is supposed to have.")