This file is indexed.

/usr/lib/python3/dist-packages/provisioningserver/rackdservices/networks_monitoring_service.py is in python3-maas-provisioningserver 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.

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
# Copyright 2016 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Networks monitoring service for rack controllers."""

__all__ = [
    "RackNetworksMonitoringService",
]

from provisioningserver.logger import get_maas_logger
from provisioningserver.rpc.exceptions import NoConnectionsAvailable
from provisioningserver.rpc.region import (
    GetDiscoveryState,
    ReportMDNSEntries,
    ReportNeighbours,
    RequestRackRefresh,
    UpdateInterfaces,
)
from provisioningserver.utils.services import NetworksMonitoringService
from provisioningserver.utils.twisted import pause
from twisted.internet.defer import inlineCallbacks


maaslog = get_maas_logger("networks.monitor")


class RackNetworksMonitoringService(NetworksMonitoringService):
    """Rack service to monitor network interfaces for configuration changes."""

    def __init__(self, clientService, *args, **kwargs):
        super(RackNetworksMonitoringService, self).__init__(*args, **kwargs)
        self.clientService = clientService

    def getDiscoveryState(self):
        """Get the discovery state from the region."""
        if self._recorded is None:
            # Wait until the rack has refreshed.
            return {}
        else:
            def getState(client):
                d = client(
                    GetDiscoveryState, system_id=client.localIdent)
                d.addCallback(lambda args: args['interfaces'])
                return d

            d = self.clientService.getClientNow()
            d.addCallback(getState)
            return d

    @inlineCallbacks
    def recordInterfaces(self, interfaces, hints=None):
        """Record the interfaces information to the region."""
        while self.running:
            try:
                client = yield self.clientService.getClientNow()
            except NoConnectionsAvailable:
                yield pause(1.0)
                continue
            if self._recorded is None:
                yield client(RequestRackRefresh, system_id=client.localIdent)
            yield client(
                UpdateInterfaces, system_id=client.localIdent,
                interfaces=interfaces, topology_hints=hints)
            break

    def reportNeighbours(self, neighbours):
        """Report neighbour information to the region."""
        d = self.clientService.getClientNow()
        d.addCallback(lambda client: client(
            ReportNeighbours, system_id=client.localIdent,
            neighbours=neighbours))
        return d

    def reportMDNSEntries(self, mdns):
        """Report mDNS entries to the region."""
        d = self.clientService.getClientNow()
        d.addCallback(lambda client: client(
            ReportMDNSEntries, system_id=client.localIdent, mdns=mdns))
        return d