~wjh-fresh/maas/maas2.1_XSpowerType

« back to all changes in this revision

Viewing changes to src/provisioningserver/rackdservices/networks_monitoring_service.py

  • Committer: MAAS Lander
  • Author(s): Blake Rouse
  • Date: 2017-02-14 20:48:08 UTC
  • mfrom: (5584.1.1 rpc-client-now-2.1)
  • Revision ID: maas_lander-20170214204808-1eznwz38ol8u5ysl
[r=blake-rouse][bug=1626654][author=blake-rouse] Backport r5725: Add new getClientNow that ensures a connection to a region controller before returning a client. Use the new getClientNow across the rack controller getClient calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
    def getDiscoveryState(self):
32
32
        """Get the discovery state from the region."""
33
 
        client = self.clientService.getClient()
34
33
        if self._recorded is None:
35
34
            # Wait until the rack has refreshed.
36
35
            return {}
37
36
        else:
38
 
            d = client(
39
 
                GetDiscoveryState, system_id=client.localIdent)
40
 
            d.addCallback(lambda args: args['interfaces'])
 
37
            def getState(client):
 
38
                d = client(
 
39
                    GetDiscoveryState, system_id=client.localIdent)
 
40
                d.addCallback(lambda args: args['interfaces'])
 
41
                return d
 
42
 
 
43
            d = self.clientService.getClientNow()
 
44
            d.addCallback(getState)
41
45
            return d
42
46
 
43
47
    def recordInterfaces(self, interfaces):
44
48
        """Record the interfaces information to the region."""
45
 
        client = self.clientService.getClient()
46
 
        # On first run perform a refresh
47
 
        if self._recorded is None:
48
 
            return client(RequestRackRefresh, system_id=client.localIdent)
49
 
        else:
50
 
            return client(
51
 
                UpdateInterfaces, system_id=client.localIdent,
52
 
                interfaces=interfaces)
 
49
        def record(client):
 
50
            # On first run perform a refresh
 
51
            if self._recorded is None:
 
52
                return client(RequestRackRefresh, system_id=client.localIdent)
 
53
            else:
 
54
                return client(
 
55
                    UpdateInterfaces, system_id=client.localIdent,
 
56
                    interfaces=interfaces)
 
57
 
 
58
        d = self.clientService.getClientNow()
 
59
        d.addCallback(record)
 
60
        return d
53
61
 
54
62
    def reportNeighbours(self, neighbours):
55
63
        """Report neighbour information to the region."""
56
 
        client = self.clientService.getClient()
57
 
        return client(
 
64
        d = self.clientService.getClientNow()
 
65
        d.addCallback(lambda client: client(
58
66
            ReportNeighbours, system_id=client.localIdent,
59
 
            neighbours=neighbours)
 
67
            neighbours=neighbours))
 
68
        return d
60
69
 
61
70
    def reportMDNSEntries(self, mdns):
62
71
        """Report mDNS entries to the region."""
63
 
        client = self.clientService.getClient()
64
 
        return client(
65
 
            ReportMDNSEntries, system_id=client.localIdent, mdns=mdns)
 
72
        d = self.clientService.getClientNow()
 
73
        d.addCleanup(lambda client: client(
 
74
            ReportMDNSEntries, system_id=client.localIdent, mdns=mdns))
 
75
        return d