OLD | NEW |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package manual | 4 package manual |
5 | 5 |
6 import ( | 6 import ( |
7 "errors" | 7 "errors" |
8 "fmt" | 8 "fmt" |
9 | 9 |
10 "launchpad.net/juju-core/agent" | 10 "launchpad.net/juju-core/agent" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // LocalStorageEnviron is an Environ where the bootstrap node | 23 // LocalStorageEnviron is an Environ where the bootstrap node |
24 // manages its own local storage. | 24 // manages its own local storage. |
25 type LocalStorageEnviron interface { | 25 type LocalStorageEnviron interface { |
26 environs.Environ | 26 environs.Environ |
27 environs.BootstrapStorager | 27 environs.BootstrapStorager |
28 localstorage.LocalStorageConfig | 28 localstorage.LocalStorageConfig |
29 } | 29 } |
30 | 30 |
31 type BootstrapArgs struct { | 31 type BootstrapArgs struct { |
32 Host string | 32 Host string |
| 33 DataDir string |
33 Environ LocalStorageEnviron | 34 Environ LocalStorageEnviron |
34 MachineId string | 35 MachineId string |
35 PossibleTools tools.List | 36 PossibleTools tools.List |
36 } | 37 } |
37 | 38 |
38 // TODO(axw) make this configurable? | |
39 const dataDir = "/var/lib/juju" | |
40 | |
41 func errMachineIdInvalid(machineId string) error { | 39 func errMachineIdInvalid(machineId string) error { |
42 return fmt.Errorf("%q is not a valid machine ID", machineId) | 40 return fmt.Errorf("%q is not a valid machine ID", machineId) |
43 } | 41 } |
44 | 42 |
45 // NewManualBootstrapEnviron wraps a LocalStorageEnviron with another which | 43 // NewManualBootstrapEnviron wraps a LocalStorageEnviron with another which |
46 // overrides the Bootstrap method; when Bootstrap is invoked, the specified | 44 // overrides the Bootstrap method; when Bootstrap is invoked, the specified |
47 // host will be manually bootstrapped. | 45 // host will be manually bootstrapped. |
48 func Bootstrap(args BootstrapArgs) (err error) { | 46 func Bootstrap(args BootstrapArgs) (err error) { |
49 if args.Host == "" { | 47 if args.Host == "" { |
50 return errors.New("host argument is empty") | 48 return errors.New("host argument is empty") |
51 } | 49 } |
52 if args.Environ == nil { | 50 if args.Environ == nil { |
53 return errors.New("environ argument is nil") | 51 return errors.New("environ argument is nil") |
54 } | 52 } |
| 53 if args.DataDir == "" { |
| 54 return errors.New("data-dir argument is empty") |
| 55 } |
55 if !names.IsMachine(args.MachineId) { | 56 if !names.IsMachine(args.MachineId) { |
56 return errMachineIdInvalid(args.MachineId) | 57 return errMachineIdInvalid(args.MachineId) |
57 } | 58 } |
58 | 59 |
59 provisioned, err := checkProvisioned(args.Host) | 60 provisioned, err := checkProvisioned(args.Host) |
60 if err != nil { | 61 if err != nil { |
61 return fmt.Errorf("failed to check provisioned status: %v", err) | 62 return fmt.Errorf("failed to check provisioned status: %v", err) |
62 } | 63 } |
63 if provisioned { | 64 if provisioned { |
64 return ErrProvisioned | 65 return ErrProvisioned |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if err != nil { | 97 if err != nil { |
97 return err | 98 return err |
98 } | 99 } |
99 defer func() { | 100 defer func() { |
100 if err != nil { | 101 if err != nil { |
101 logger.Errorf("bootstrapping failed, removing state file
: %v", err) | 102 logger.Errorf("bootstrapping failed, removing state file
: %v", err) |
102 bootstrapStorage.Remove(provider.StateFile) | 103 bootstrapStorage.Remove(provider.StateFile) |
103 } | 104 } |
104 }() | 105 }() |
105 | 106 |
| 107 // Set the new tools prefix so StorageName returns the right thing. |
| 108 restore := envtools.SetToolPrefix(envtools.NewToolPrefix) |
| 109 defer restore() |
| 110 |
106 // Get a file:// scheme tools URL for the tools, which will have been | 111 // Get a file:// scheme tools URL for the tools, which will have been |
107 // copied to the remote machine's storage directory. | 112 // copied to the remote machine's storage directory. |
108 tools := *possibleTools[0] | 113 tools := *possibleTools[0] |
109 storageDir := args.Environ.StorageDir() | 114 storageDir := args.Environ.StorageDir() |
110 toolsStorageName := envtools.StorageName(tools.Version) | 115 toolsStorageName := envtools.StorageName(tools.Version) |
111 tools.URL = fmt.Sprintf("file://%s/%s", storageDir, toolsStorageName) | 116 tools.URL = fmt.Sprintf("file://%s/%s", storageDir, toolsStorageName) |
112 | 117 |
113 // Add the local storage configuration. | 118 // Add the local storage configuration. |
114 agentEnv := map[string]string{ | 119 agentEnv := map[string]string{ |
115 agent.StorageAddr: args.Environ.StorageAddr(), | 120 agent.StorageAddr: args.Environ.StorageAddr(), |
116 agent.StorageDir: storageDir, | 121 agent.StorageDir: storageDir, |
117 agent.SharedStorageAddr: args.Environ.SharedStorageAddr(), | 122 agent.SharedStorageAddr: args.Environ.SharedStorageAddr(), |
118 agent.SharedStorageDir: args.Environ.SharedStorageDir(), | 123 agent.SharedStorageDir: args.Environ.SharedStorageDir(), |
119 } | 124 } |
120 | 125 |
121 // Finally, provision the machine agent. | 126 // Finally, provision the machine agent. |
122 stateFileURL := fmt.Sprintf("file://%s/%s", storageDir, provider.StateFi
le) | 127 stateFileURL := fmt.Sprintf("file://%s/%s", storageDir, provider.StateFi
le) |
123 err = provisionMachineAgent(provisionMachineAgentArgs{ | 128 err = provisionMachineAgent(provisionMachineAgentArgs{ |
124 host: args.Host, | 129 host: args.Host, |
125 » » dataDir: dataDir, | 130 » » dataDir: args.DataDir, |
126 environConfig: args.Environ.Config(), | 131 environConfig: args.Environ.Config(), |
127 stateFileURL: stateFileURL, | 132 stateFileURL: stateFileURL, |
128 machineId: args.MachineId, | 133 machineId: args.MachineId, |
129 bootstrap: true, | 134 bootstrap: true, |
130 nonce: state.BootstrapNonce, | 135 nonce: state.BootstrapNonce, |
131 tools: &tools, | 136 tools: &tools, |
132 agentEnv: agentEnv, | 137 agentEnv: agentEnv, |
133 }) | 138 }) |
134 return err | 139 return err |
135 } | 140 } |
OLD | NEW |