~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to worker/addressupdater/updater.go

[r=rogpeppe] worker/addressupdater: wire up

It could do with some more comprehensive
testing, but it might be OK to land anyway.

https://codereview.appspot.com/14306043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
1
4
package addressupdater
2
5
 
3
6
import (
19
22
        shortPoll = 500 * time.Millisecond
20
23
)
21
24
 
22
 
//func NewAddressPublisher() worker.Worker {
23
 
//      p := &updater{
24
 
//              st:
25
 
//      }
26
 
//      // wait for environment
27
 
//      go func() {
28
 
//              defer p.tomb.Done()
29
 
//              p.tomb.Kill(p.loop())
30
 
//      }()
31
 
//}
32
 
 
33
 
//type updater struct {
34
 
//      st   *state.State
35
 
//      tomb tomb.Tomb
36
 
//
37
 
//      mu      sync.Mutex
38
 
//      environ environs.Environ
39
 
//}
40
 
 
41
25
type machine interface {
42
26
        Id() string
43
27
        Addresses() []instance.Address
44
28
        InstanceId() (instance.Id, error)
45
29
        SetAddresses([]instance.Address) error
46
 
        Jobs() []state.MachineJob
47
30
        String() string
48
31
        Refresh() error
49
32
        Life() state.Life
199
182
// on the machine if they've changed.
200
183
func checkMachineAddresses(context machineContext, m machine) error {
201
184
        instId, err := m.InstanceId()
202
 
        if err != nil {
 
185
        if err != nil && !state.IsNotProvisionedError(err) {
203
186
                return fmt.Errorf("cannot get machine's instance id: %v", err)
204
187
        }
205
 
        newAddrs, err := context.addresses(instId)
206
 
        if err != nil {
207
 
                logger.Warningf("cannot get addresses for instance %q: %v", instId, err)
208
 
                return nil
 
188
        var newAddrs []instance.Address
 
189
        if err == nil {
 
190
                newAddrs, err = context.addresses(instId)
 
191
                if err != nil {
 
192
                        logger.Warningf("cannot get addresses for instance %q: %v", instId, err)
 
193
                        return nil
 
194
                }
209
195
        }
210
196
        if addressesEqual(m.Addresses(), newAddrs) {
211
197
                return nil