~mvo/snappy/15.04-network-config

« back to all changes in this revision

Viewing changes to coreconfig/config.go

  • Committer: Michael Vogt
  • Date: 2015-09-08 14:36:11 UTC
  • Revision ID: michael.vogt@ubuntu.com-20150908143611-isr4d5ni8qd3hphc
add ubuntu-core.modprobe yaml to write modprobe files

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        autopilotTimerDisabled string = "disabled"
41
41
)
42
42
 
 
43
var (
 
44
        modprobePath string = "/etc/modprobe.d/ubuntu-core.conf"
 
45
)
 
46
 
43
47
// ErrInvalidUnitStatus signals that a unit is not returning a status
44
48
// of "enabled" or "disabled".
45
49
var ErrInvalidUnitStatus = errors.New("invalid unit status")
48
52
        Autopilot *bool   `yaml:"autopilot,omitempty"`
49
53
        Timezone  *string `yaml:"timezone,omitempty"`
50
54
        Hostname  *string `yaml:"hostname,omitempty"`
 
55
        Modprobe  *string `yaml:"modprobe,omitempty"`
51
56
}
52
57
 
53
58
type coreConfig struct {
73
78
        if err != nil {
74
79
                return nil, err
75
80
        }
 
81
        modprobe, err := getModprobe()
 
82
        if err != nil {
 
83
                return nil, err
 
84
        }
76
85
 
77
86
        config := &systemConfig{
78
87
                Autopilot: &autopilot,
79
88
                Timezone:  &tz,
80
89
                Hostname:  &hostname,
 
90
                Modprobe:  &modprobe,
81
91
        }
82
92
 
83
93
        return config, nil
151
161
                        if err := setHostname(*newConfig.Hostname); err != nil {
152
162
                                return "", err
153
163
                        }
 
164
                case "Modprobe":
 
165
                        if *oldConfig.Modprobe == *newConfig.Modprobe {
 
166
                                continue
 
167
                        }
 
168
 
 
169
                        if err := setModprobe(*newConfig.Modprobe); err != nil {
 
170
                                return "", err
 
171
                        }
154
172
                }
155
173
        }
156
174
 
184
202
        return ioutil.WriteFile(tzFile(), []byte(timezone), 0644)
185
203
}
186
204
 
 
205
// getModprobe returns the current modprobe config
 
206
var getModprobe = func() (string, error) {
 
207
        modprobe, err := ioutil.ReadFile(modprobePath)
 
208
        if err != nil && !os.IsNotExist(err) {
 
209
                return "", err
 
210
        }
 
211
 
 
212
        return string(modprobe), nil
 
213
}
 
214
 
 
215
// setModprobe sets the specified modprobe config
 
216
var setModprobe = func(modprobe string) error {
 
217
        return ioutil.WriteFile(modprobePath, []byte(modprobe), 0644)
 
218
}
 
219
 
187
220
// for testing purposes
188
221
var (
189
222
        cmdAutopilotEnabled = []string{"is-enabled", autopilotTimer}