~fwereade/pyjuju/go-unit-commands

« back to all changes in this revision

Viewing changes to environs/ec2/cloudinit.go

  • Committer: Roger Peppe
  • Date: 2012-02-15 15:21:33 UTC
  • mfrom: (60.1.4 go-ec2-config)
  • Revision ID: roger.peppe@canonical.com-20120215152133-uhd7jydaznssyawr
environs/ec2: add authorized keys support to config

Also change ZookeeperAddrs to state.Info.

R=fwereade, niemeyer
CC=
https://codereview.appspot.com/5656062

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import (
4
4
        "fmt"
5
5
        "launchpad.net/juju/go/cloudinit"
 
6
        "launchpad.net/juju/go/state"
6
7
        "os/exec"
7
8
        "strings"
8
9
)
20
21
        // instanceIdAccessor holds bash code that evaluates to the current instance id.
21
22
        instanceIdAccessor string
22
23
 
23
 
        // adminSecret holds a secret that will be used to authenticate to zookeeper.
24
 
        adminSecret string
25
 
 
26
24
        // providerType identifies the provider type so the host
27
25
        // knows which kind of provider to use.
28
26
        providerType string
29
27
 
30
 
        // zookeeperHosts lists the names of hosts running zookeeper.
31
 
        // Unless the new machine is running zookeeper (Zookeeper is set),
32
 
        // there must be at least one host name supplied.
33
 
        zookeeperHosts []string
 
28
        // stateInfo holds the means for the new instance to communicate with the
 
29
        // juju state. Unless the new machine is running zookeeper (Zookeeper is
 
30
        // set), there must be at least one zookeeper address supplied.
 
31
        stateInfo *state.Info
34
32
 
35
33
        // origin states what version of juju should be run on the instance.
36
34
        // If it is zero, a suitable default is chosen by examining the local environment.
39
37
        // machineId identifies the new machine. It must be non-empty.
40
38
        machineId string
41
39
 
42
 
        // sshKeys specifies the keys that are allowed to
43
 
        // connect to the machine. If no keys are
44
 
        // supplied, there can be no ssh access to the node.
 
40
        // authorizedKeys specifies the keys that are allowed to
 
41
        // connect to the machine (see cloudinit.SSHAddAuthorizedKeys)
 
42
        // If no keys are supplied, there can be no ssh access to the node.
45
43
        // On a bootstrap machine, that is fatal. On other
46
44
        // machines it will mean that the ssh, scp and debug-hooks
47
45
        // commands cannot work.
48
 
        sshKeys []string
 
46
        authorizedKeys string
49
47
}
50
48
 
51
49
type originKind int
85
83
                origin = defaultOrigin()
86
84
        }
87
85
 
88
 
        for _, k := range cfg.sshKeys {
89
 
                c.AddSSHAuthorizedKey(k)
90
 
        }
 
86
        c.AddSSHAuthorizedKeys(cfg.authorizedKeys)
91
87
        pkgs := []string{
92
88
                "bzr",
93
89
                "byobu",
157
153
                )
158
154
        }
159
155
 
160
 
        // machine data
161
 
        c.SetAttr("machine-data",
162
 
                map[string]interface{}{
163
 
                        "machine-id":           cfg.machineId,
164
 
                        "juju-provider-type":   cfg.providerType,
165
 
                        "juju-zookeeper-hosts": zookeeperHosts,
166
 
                })
167
 
 
168
156
        // general options
169
157
        c.SetAptUpgrade(true)
170
158
        c.SetAptUpdate(true)
173
161
}
174
162
 
175
163
func (cfg *machineConfig) zookeeperHostAddrs() string {
176
 
        hosts := append([]string{}, cfg.zookeeperHosts...)
 
164
        var hosts []string
177
165
        if cfg.zookeeper {
178
 
                hosts = append(hosts, "localhost")
 
166
                hosts = append(hosts, "localhost"+zkPortSuffix)
179
167
        }
180
 
        for i := range hosts {
181
 
                hosts[i] += ":2181"
 
168
        if cfg.stateInfo != nil {
 
169
                hosts = append(hosts, cfg.stateInfo.Addrs...)
182
170
        }
183
171
        return strings.Join(hosts, ",")
184
172
}
201
189
                if cfg.instanceIdAccessor == "" {
202
190
                        return requiresError("instance id accessor")
203
191
                }
204
 
                if cfg.adminSecret == "" {
205
 
                        return requiresError("admin secret")
206
 
                }
207
192
        } else {
208
 
                if len(cfg.zookeeperHosts) == 0 {
 
193
                if cfg.stateInfo == nil || len(cfg.stateInfo.Addrs) == 0 {
209
194
                        return requiresError("zookeeper hosts")
210
195
                }
211
196
        }