~cmars/juju-core/1.18-resolve-cs-series

« back to all changes in this revision

Viewing changes to state/megawatcher.go

[r=wallyworld],[bug=1301464] Ensure unit addresses populated

Change the internals of the megawatcher to ensure
that machine addresses are correct and that the
public and private addresses for untis come from
the assigned machine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
                Life:                     params.Life(m.Life.String()),
33
33
                Series:                   m.Series,
34
34
                Jobs:                     paramsJobsFromJobs(m.Jobs),
35
 
                Addresses:                addressesToInstanceAddresses(m.Addresses),
 
35
                Addresses:                mergedAddresses(m.MachineAddresses, m.Addresses),
36
36
                SupportedContainers:      m.SupportedContainers,
37
37
                SupportedContainersKnown: m.SupportedContainersKnown,
38
38
        }
87
87
 
88
88
func (u *backingUnit) updated(st *State, store *multiwatcher.Store, id interface{}) error {
89
89
        info := &params.UnitInfo{
90
 
                Name:           u.Name,
91
 
                Service:        u.Service,
92
 
                Series:         u.Series,
93
 
                PublicAddress:  u.PublicAddress,
94
 
                PrivateAddress: u.PrivateAddress,
95
 
                MachineId:      u.MachineId,
96
 
                Ports:          u.Ports,
 
90
                Name:      u.Name,
 
91
                Service:   u.Service,
 
92
                Series:    u.Series,
 
93
                MachineId: u.MachineId,
 
94
                Ports:     u.Ports,
97
95
        }
98
96
        if u.CharmURL != nil {
99
97
                info.CharmURL = u.CharmURL.String()
114
112
                info.Status = oldInfo.Status
115
113
                info.StatusInfo = oldInfo.StatusInfo
116
114
        }
 
115
        publicAddress, privateAddress, err := getUnitAddresses(st, u.Name)
 
116
        if err != nil {
 
117
                return err
 
118
        }
 
119
        info.PublicAddress = publicAddress
 
120
        info.PrivateAddress = privateAddress
117
121
        store.Update(info)
118
122
        return nil
119
123
}
120
124
 
 
125
// getUnitAddresses returns the public and private addresses on a given unit.
 
126
// As of 1.18, the addresses are stored on the assigned machine but we retain
 
127
// this approach for backwards compatibility.
 
128
func getUnitAddresses(st *State, unitName string) (publicAddress, privateAddress string, err error) {
 
129
        u, err := st.Unit(unitName)
 
130
        if err != nil {
 
131
                return "", "", err
 
132
        }
 
133
        publicAddress, _ = u.PublicAddress()
 
134
        privateAddress, _ = u.PrivateAddress()
 
135
        return publicAddress, privateAddress, nil
 
136
}
 
137
 
121
138
func (svc *backingUnit) removed(st *State, store *multiwatcher.Store, id interface{}) error {
122
139
        store.Remove(params.EntityId{
123
140
                Kind: "unit",