~sinzui/ubuntu/vivid/juju-core/vivid-1.24.6

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/proxyupdater/proxyupdater.go

  • Committer: Curtis Hovey
  • Date: 2015-09-30 14:14:54 UTC
  • mfrom: (1.1.34)
  • Revision ID: curtis@hovey.name-20150930141454-o3ldf23dzyjio6c0
Backport of 1.24.6 from wily. (LP: #1500916)

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
        "github.com/juju/loggo"
12
12
        "github.com/juju/utils"
13
 
        "github.com/juju/utils/apt"
14
13
        "github.com/juju/utils/exec"
 
14
        "github.com/juju/utils/packaging/commands"
 
15
        "github.com/juju/utils/packaging/config"
15
16
        proxyutils "github.com/juju/utils/proxy"
16
17
 
17
18
        "github.com/juju/juju/api/environment"
158
159
        }
159
160
}
160
161
 
161
 
func (w *proxyWorker) handleAptProxyValues(aptSettings proxyutils.Settings) {
 
162
// getPackageCommander is a helper function which returns the
 
163
// package commands implementation for the current system.
 
164
func getPackageCommander() (commands.PackageCommander, error) {
 
165
        return commands.NewPackageCommander(version.Current.Series)
 
166
}
 
167
 
 
168
func (w *proxyWorker) handleAptProxyValues(aptSettings proxyutils.Settings) error {
162
169
        if w.writeSystemFiles && (aptSettings != w.aptProxy || w.first) {
163
170
                logger.Debugf("new apt proxy settings %#v", aptSettings)
 
171
                paccmder, err := getPackageCommander()
 
172
                if err != nil {
 
173
                        return err
 
174
                }
164
175
                w.aptProxy = aptSettings
 
176
 
165
177
                // Always finish with a new line.
166
 
                content := apt.ProxyContent(w.aptProxy) + "\n"
167
 
                err := ioutil.WriteFile(apt.ConfFile, []byte(content), 0644)
 
178
                content := paccmder.ProxyConfigContents(w.aptProxy) + "\n"
 
179
                err = ioutil.WriteFile(config.AptProxyConfigFile, []byte(content), 0644)
168
180
                if err != nil {
169
181
                        // It isn't really fatal, but we should record it.
170
182
                        logger.Errorf("error writing apt proxy config file: %v", err)
171
183
                }
172
184
        }
 
185
        return nil
173
186
}
174
187
 
175
188
func (w *proxyWorker) onChange() error {
178
191
                return err
179
192
        }
180
193
        w.handleProxyValues(env.ProxySettings())
181
 
        w.handleAptProxyValues(env.AptProxySettings())
 
194
        err = w.handleAptProxyValues(env.AptProxySettings())
 
195
        if err != nil {
 
196
                return err
 
197
        }
182
198
        return nil
183
199
}
184
200
 
196
212
}
197
213
 
198
214
// Handle is defined on the worker.NotifyWatchHandler interface.
199
 
func (w *proxyWorker) Handle() error {
 
215
func (w *proxyWorker) Handle(_ <-chan struct{}) error {
200
216
        return w.onChange()
201
217
}
202
218