Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(468)

Delta Between Two Patch Sets: environs/cloudinit/cloudinit.go

Issue 8661043: environs/cloudinit: fail properly in cloudinit
Left Patch Set: Created 10 years, 11 months ago
Right Patch Set: environs/cloudinit: fail properly in cloudinit Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « [revision details] ('k') | environs/cloudinit/cloudinit_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package cloudinit 1 package cloudinit
2 2
3 import ( 3 import (
4 "encoding/base64" 4 "encoding/base64"
5 "fmt" 5 "fmt"
6 "launchpad.net/goyaml" 6 "launchpad.net/goyaml"
7 "launchpad.net/juju-core/cloudinit" 7 "launchpad.net/juju-core/cloudinit"
8 "launchpad.net/juju-core/constraints" 8 "launchpad.net/juju-core/constraints"
9 "launchpad.net/juju-core/environs/agent" 9 "launchpad.net/juju-core/environs/agent"
10 "launchpad.net/juju-core/environs/config" 10 "launchpad.net/juju-core/environs/config"
11 "launchpad.net/juju-core/log" 11 "launchpad.net/juju-core/log"
12 "launchpad.net/juju-core/log/syslog" 12 "launchpad.net/juju-core/log/syslog"
13 "launchpad.net/juju-core/state" 13 "launchpad.net/juju-core/state"
14 "launchpad.net/juju-core/state/api" 14 "launchpad.net/juju-core/state/api"
15 "launchpad.net/juju-core/trivial"
16 "launchpad.net/juju-core/upstart" 15 "launchpad.net/juju-core/upstart"
16 "launchpad.net/juju-core/utils"
17 "path" 17 "path"
18 ) 18 )
19 19
20 // MachineConfig represents initialization information for a new juju machine. 20 // MachineConfig represents initialization information for a new juju machine.
21 type MachineConfig struct { 21 type MachineConfig struct {
22 // StateServer specifies whether the new machine will run the 22 // StateServer specifies whether the new machine will run the
23 // mongo and API servers. 23 // mongo and API servers.
24 StateServer bool 24 StateServer bool
25 25
26 // StateServerCert and StateServerKey hold the state server 26 // StateServerCert and StateServerKey hold the state server
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 func base64yaml(m *config.Config) string { 91 func base64yaml(m *config.Config) string {
92 data, err := goyaml.Marshal(m.AllAttrs()) 92 data, err := goyaml.Marshal(m.AllAttrs())
93 if err != nil { 93 if err != nil {
94 // can't happen, these values have been validated a number of ti mes 94 // can't happen, these values have been validated a number of ti mes
95 panic(err) 95 panic(err)
96 } 96 }
97 return base64.StdEncoding.EncodeToString(data) 97 return base64.StdEncoding.EncodeToString(data)
98 } 98 }
99 99
100 func New(cfg *MachineConfig) (*cloudinit.Config, error) { 100 func New(cfg *MachineConfig) (*cloudinit.Config, error) {
101 c := cloudinit.New()
102 return Configure(cfg, c)
103 }
104
105 func Configure(cfg *MachineConfig, c *cloudinit.Config) (*cloudinit.Config, erro r) {
101 if err := verifyConfig(cfg); err != nil { 106 if err := verifyConfig(cfg); err != nil {
102 return nil, err 107 return nil, err
103 } 108 }
104 c := cloudinit.New()
105
106 c.AddSSHAuthorizedKeys(cfg.AuthorizedKeys) 109 c.AddSSHAuthorizedKeys(cfg.AuthorizedKeys)
107 c.AddPackage("git") 110 c.AddPackage("git")
108 111
109 addScripts(c, 112 addScripts(c,
110 "set -xe", // ensure we run all the scripts or abort. 113 "set -xe", // ensure we run all the scripts or abort.
111 fmt.Sprintf("mkdir -p %s", cfg.DataDir), 114 fmt.Sprintf("mkdir -p %s", cfg.DataDir),
112 "mkdir -p /var/log/juju") 115 "mkdir -p /var/log/juju")
113 116
114 // Make a directory for the tools to live in, then fetch the 117 // Make a directory for the tools to live in, then fetch the
115 // tools and unarchive them into it. 118 // tools and unarchive them into it.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 339 }
337 340
338 func (cfg *MachineConfig) NeedMongoPPA() bool { 341 func (cfg *MachineConfig) NeedMongoPPA() bool {
339 series := cfg.Tools.Series 342 series := cfg.Tools.Series
340 // 11.10 and earlier are not supported. 343 // 11.10 and earlier are not supported.
341 // 13.04 and later ship a compatible version in the archive. 344 // 13.04 and later ship a compatible version in the archive.
342 return series == "precise" || series == "quantal" 345 return series == "precise" || series == "quantal"
343 } 346 }
344 347
345 func shquote(p string) string { 348 func shquote(p string) string {
346 » return trivial.ShQuote(p) 349 » return utils.ShQuote(p)
347 } 350 }
348 351
349 type requiresError string 352 type requiresError string
350 353
351 func (e requiresError) Error() string { 354 func (e requiresError) Error() string {
352 return "invalid machine configuration: missing " + string(e) 355 return "invalid machine configuration: missing " + string(e)
353 } 356 }
354 357
355 func verifyConfig(cfg *MachineConfig) (err error) { 358 func verifyConfig(cfg *MachineConfig) (err error) {
356 » defer trivial.ErrorContextf(&err, "invalid machine configuration") 359 » defer utils.ErrorContextf(&err, "invalid machine configuration")
357 if !state.IsMachineId(cfg.MachineId) { 360 if !state.IsMachineId(cfg.MachineId) {
358 return fmt.Errorf("invalid machine id") 361 return fmt.Errorf("invalid machine id")
359 } 362 }
360 if cfg.DataDir == "" { 363 if cfg.DataDir == "" {
361 return fmt.Errorf("missing var directory") 364 return fmt.Errorf("missing var directory")
362 } 365 }
363 if cfg.Tools == nil { 366 if cfg.Tools == nil {
364 return fmt.Errorf("missing tools") 367 return fmt.Errorf("missing tools")
365 } 368 }
366 if cfg.Tools.URL == "" { 369 if cfg.Tools.URL == "" {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 415 }
413 if cfg.APIInfo.Tag != state.MachineTag(cfg.MachineId) { 416 if cfg.APIInfo.Tag != state.MachineTag(cfg.MachineId) {
414 return fmt.Errorf("entity tag must match started machine ") 417 return fmt.Errorf("entity tag must match started machine ")
415 } 418 }
416 } 419 }
417 if cfg.MachineNonce == "" { 420 if cfg.MachineNonce == "" {
418 return fmt.Errorf("missing machine nonce") 421 return fmt.Errorf("missing machine nonce")
419 } 422 }
420 return nil 423 return nil
421 } 424 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b