~ubuntu-branches/ubuntu/trusty/juju-core/trusty-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/environs/cloudinit/cloudinit.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-29 11:40:20 UTC
  • mfrom: (23.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140129114020-ejieitm8smtt5vln
Tags: 1.17.1-0ubuntu2
d/tests/local-provider: Don't fail tests if ~/.juju is present as its
created by the juju version command. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
        "launchpad.net/juju-core/constraints"
19
19
        "launchpad.net/juju-core/environs/config"
20
20
        "launchpad.net/juju-core/instance"
 
21
        "launchpad.net/juju-core/juju/osenv"
21
22
        "launchpad.net/juju-core/log/syslog"
22
23
        "launchpad.net/juju-core/names"
23
24
        "launchpad.net/juju-core/state"
33
34
// is bootstrapping.
34
35
const BootstrapStateURLFile = "/tmp/provider-state-url"
35
36
 
 
37
// SystemIdentity is the name of the file where the environment SSH key is kept.
 
38
const SystemIdentity = "system-identity"
 
39
 
36
40
// fileSchemePrefix is the prefix for file:// URLs.
37
41
const fileSchemePrefix = "file://"
38
42
 
106
110
        // the machine agent config.
107
111
        AgentEnvironment map[string]string
108
112
 
 
113
        // WARNING: this is only set if the machine being configured is
 
114
        // a state server node.
 
115
        //
109
116
        // Config holds the initial environment configuration.
110
117
        Config *config.Config
111
118
 
118
125
        // DisableSSLHostnameVerification can be set to true to tell cloud-init
119
126
        // that it shouldn't verify SSL certificates
120
127
        DisableSSLHostnameVerification bool
 
128
 
 
129
        // SystemPrivateSSHKey is created at bootstrap time and recorded on every
 
130
        // node that has an API server. At this stage, that is any machine where
 
131
        // StateServer (member above) is set to true.
 
132
        SystemPrivateSSHKey string
 
133
 
 
134
        // ProxySettings define normal http, https and ftp proxies.
 
135
        ProxySettings osenv.ProxySettings
 
136
 
 
137
        // AptProxySettings define the http, https and ftp proxy settings to use
 
138
        // for apt, which may or may not be the same as the normal ProxySettings.
 
139
        AptProxySettings osenv.ProxySettings
121
140
}
122
141
 
123
142
func base64yaml(m *config.Config) string {
158
177
// but adds to the running time of initialisation due to lack of activity
159
178
// between image bringup and start of agent installation.
160
179
func ConfigureBasic(cfg *MachineConfig, c *cloudinit.Config) error {
 
180
        c.AddScripts(
 
181
                "set -xe", // ensure we run all the scripts or abort.
 
182
        )
161
183
        c.AddSSHAuthorizedKeys(cfg.AuthorizedKeys)
162
184
        c.SetOutput(cloudinit.OutAll, "| tee -a "+cloudInitOutputLog, "")
163
185
        // Create a file in a well-defined location containing the machine's
198
220
                c.AddBootCmd(cloudinit.LogProgressCmd("Logging to %s on remote host", cloudInitOutputLog))
199
221
        }
200
222
 
 
223
        // Write out the apt proxy settings
 
224
        if (cfg.AptProxySettings != osenv.ProxySettings{}) {
 
225
                filename := "/etc/apt/apt.conf.d/42-juju-proxy-settings"
 
226
                c.AddBootCmd(fmt.Sprintf(
 
227
                        `[ -f %s ] || (printf '%%s\n' %s > %s)`,
 
228
                        filename,
 
229
                        shquote(utils.AptProxyContent(cfg.AptProxySettings)),
 
230
                        filename))
 
231
        }
 
232
 
201
233
        // Bring packages up-to-date.
202
234
        c.SetAptUpdate(true)
203
235
        c.SetAptUpgrade(true)
206
238
        c.AddPackage("git")
207
239
        c.AddPackage("cpu-checker")
208
240
 
209
 
        c.AddScripts(
210
 
                "set -xe", // ensure we run all the scripts or abort.
 
241
        // Write out the normal proxy settings so that the settings are
 
242
        // sourced by bash, and ssh through that.
 
243
        c.AddScripts(
 
244
                // We look to see if the proxy line is there already as
 
245
                // the manual provider may have had it aleady.
 
246
                `grep -q '.juju-proxy' /home/ubuntu/.profile || printf '\n# Added by juju\n[ -f "$HOME/.juju-proxy" ] && . "$HOME/.juju-proxy"\n' >> /home/ubuntu/.profile`)
 
247
        if (cfg.ProxySettings != osenv.ProxySettings{}) {
 
248
                c.AddScripts(
 
249
                        fmt.Sprintf(
 
250
                                `printf '%%s\n' %s > /home/ubuntu/.juju-proxy && chown ubuntu:ubuntu /home/ubuntu/.juju-proxy`,
 
251
                                shquote(cfg.ProxySettings.AsEnvironmentValues())))
 
252
        }
 
253
 
 
254
        c.AddScripts(
211
255
                fmt.Sprintf("mkdir -p %s", cfg.DataDir),
212
256
                "mkdir -p /var/log/juju")
213
257
 
255
299
        if err != nil {
256
300
                return err
257
301
        }
258
 
        c.AddScripts(
259
 
                // We specifically make the symlink here to the machine's current
260
 
                // tools, not to the specific version tool directory (from
261
 
                // cfg.jujuTools()), as we want the jujud that is linked to in
262
 
                // /usr/local/bin to also upgrade when the machine agent upgrades its
263
 
                // tools and changes the tools directory that it is using.
264
 
                fmt.Sprintf("ln -s %s/tools/%s/jujud /usr/local/bin/juju-run", cfg.DataDir, machineTag),
265
 
        )
266
302
 
267
303
        // Add the cloud archive cloud-tools pocket to apt sources
268
304
        // for series that need it. This gives us up-to-date LXC,
270
306
        cfg.MaybeAddCloudArchiveCloudTools(c)
271
307
 
272
308
        if cfg.StateServer {
 
309
                identityFile := cfg.dataFile(SystemIdentity)
 
310
                c.AddFile(identityFile, cfg.SystemPrivateSSHKey, 0600)
273
311
                // Disable the default mongodb installed by the mongodb-server package.
274
312
                // Only do this if the file doesn't exist already, so users can run
275
313
                // their own mongodb server if they wish to.
607
645
                if cfg.APIPort == 0 {
608
646
                        return fmt.Errorf("missing API port")
609
647
                }
 
648
                if cfg.SystemPrivateSSHKey == "" {
 
649
                        return fmt.Errorf("missing system ssh identity")
 
650
                }
610
651
        } else {
611
652
                if len(cfg.StateInfo.Addrs) == 0 {
612
653
                        return fmt.Errorf("missing state hosts")