LEFT | RIGHT |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 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 main | 4 package main |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "io" | 8 "io" |
9 "os" | 9 "os" |
| 10 "path/filepath" |
10 "strings" | 11 "strings" |
11 | 12 |
12 "launchpad.net/gnuflag" | 13 "launchpad.net/gnuflag" |
13 | 14 |
14 "launchpad.net/juju-core/charm" | 15 "launchpad.net/juju-core/charm" |
15 "launchpad.net/juju-core/cmd" | 16 "launchpad.net/juju-core/cmd" |
16 "launchpad.net/juju-core/constraints" | 17 "launchpad.net/juju-core/constraints" |
17 "launchpad.net/juju-core/environs" | 18 "launchpad.net/juju-core/environs" |
18 "launchpad.net/juju-core/environs/bootstrap" | 19 "launchpad.net/juju-core/environs/bootstrap" |
19 "launchpad.net/juju-core/environs/config" | 20 "launchpad.net/juju-core/environs/config" |
20 "launchpad.net/juju-core/environs/configstore" | 21 "launchpad.net/juju-core/environs/configstore" |
21 "launchpad.net/juju-core/environs/imagemetadata" | 22 "launchpad.net/juju-core/environs/imagemetadata" |
22 "launchpad.net/juju-core/environs/sync" | 23 "launchpad.net/juju-core/environs/sync" |
23 "launchpad.net/juju-core/environs/tools" | 24 "launchpad.net/juju-core/environs/tools" |
24 "launchpad.net/juju-core/provider" | 25 "launchpad.net/juju-core/provider" |
| 26 "launchpad.net/juju-core/utils" |
25 "launchpad.net/juju-core/utils/set" | 27 "launchpad.net/juju-core/utils/set" |
26 "launchpad.net/juju-core/version" | 28 "launchpad.net/juju-core/version" |
27 ) | 29 ) |
28 | 30 |
29 const bootstrapDoc = ` | 31 const bootstrapDoc = ` |
30 bootstrap starts a new environment of the current type (it will return an error | 32 bootstrap starts a new environment of the current type (it will return an error |
31 if the environment has already been bootstrapped). Bootstrapping an environment | 33 if the environment has already been bootstrapped). Bootstrapping an environment |
32 will provision a new machine in the environment and run the juju state server on | 34 will provision a new machine in the environment and run the juju state server on |
33 that machine. | 35 that machine. |
34 | 36 |
35 If constraints are specified in the bootstrap command, they will apply to the· | 37 If constraints are specified in the bootstrap command, they will apply to the· |
36 machine provisioned for the juju state server. They will also be set as default | 38 machine provisioned for the juju state server. They will also be set as default |
37 constraints on the environment for all future machines, exactly as if the | 39 constraints on the environment for all future machines, exactly as if the |
38 constraints were set with juju set-constraints. | 40 constraints were set with juju set-constraints. |
39 | 41 |
40 Bootstrap initializes the cloud environment synchronously and displays informati
on | 42 Bootstrap initializes the cloud environment synchronously and displays informati
on |
41 about the current installation steps. The time for bootstrap to complete varies······· | 43 about the current installation steps. The time for bootstrap to complete varies······· |
42 across cloud providers from a few seconds to several minutes. Once bootstrap ha
s· | 44 across cloud providers from a few seconds to several minutes. Once bootstrap ha
s· |
43 completed, you can run other juju commands against your environment. You can cha
nge | 45 completed, you can run other juju commands against your environment. You can cha
nge |
44 the default timeout and retry delays used during the bootstrap by changing the | 46 the default timeout and retry delays used during the bootstrap by changing the |
45 following settings in your environments.yaml (all values represent number of sec
onds): | 47 following settings in your environments.yaml (all values represent number of sec
onds): |
46 | 48 |
47 # How long to wait for a SSH connection to the state server. | 49 # How long to wait for a connection to the state server. |
48 bootstrap-ssh-timeout: 600 # default: 10 minutes | 50 bootstrap-timeout: 600 # default: 10 minutes |
49 # How long to wait between connection attempts to a state server address. | 51 # How long to wait between connection attempts to a state server address. |
50 bootstrap-ssh-retry-delay: 5 # default: 5 seconds | 52 bootstrap-retry-delay: 5 # default: 5 seconds |
51 # How often to refresh state server addresses from the API server. | 53 # How often to refresh state server addresses from the API server. |
52 bootstrap-ssh-addresses-delay: 10 # default: 10 seconds | 54 bootstrap-addresses-delay: 10 # default: 10 seconds |
53 | 55 |
54 Private clouds may need to specify their own custom image metadata, and possibly
upload | 56 Private clouds may need to specify their own custom image metadata, and possibly
upload |
55 Juju tools to cloud storage if no outgoing Internet access is available. In this
case, | 57 Juju tools to cloud storage if no outgoing Internet access is available. In this
case, |
56 use the --metadata-source paramater to tell bootstrap a local directory from whi
ch to | 58 use the --metadata-source paramater to tell bootstrap a local directory from whi
ch to |
57 upload tools and/or image metadata. | 59 upload tools and/or image metadata. |
58 | 60 |
59 See Also: | 61 See Also: |
60 juju help switch | 62 juju help switch |
61 juju help constraints | 63 juju help constraints |
62 juju help set-constraints | 64 juju help set-constraints |
(...skipping 18 matching lines...) Expand all Loading... |
81 } | 83 } |
82 | 84 |
83 func (c *BootstrapCommand) SetFlags(f *gnuflag.FlagSet) { | 85 func (c *BootstrapCommand) SetFlags(f *gnuflag.FlagSet) { |
84 c.EnvCommandBase.SetFlags(f) | 86 c.EnvCommandBase.SetFlags(f) |
85 f.Var(constraints.ConstraintsValue{&c.Constraints}, "constraints", "set
environment constraints") | 87 f.Var(constraints.ConstraintsValue{&c.Constraints}, "constraints", "set
environment constraints") |
86 f.BoolVar(&c.UploadTools, "upload-tools", false, "upload local version o
f tools before bootstrapping") | 88 f.BoolVar(&c.UploadTools, "upload-tools", false, "upload local version o
f tools before bootstrapping") |
87 f.Var(seriesVar{&c.Series}, "series", "upload tools for supplied comma-s
eparated series list") | 89 f.Var(seriesVar{&c.Series}, "series", "upload tools for supplied comma-s
eparated series list") |
88 f.StringVar(&c.MetadataSource, "metadata-source", "", "local path to use
as tools and/or metadata source") | 90 f.StringVar(&c.MetadataSource, "metadata-source", "", "local path to use
as tools and/or metadata source") |
89 } | 91 } |
90 | 92 |
91 func (c *BootstrapCommand) Init(args []string) error { | 93 func (c *BootstrapCommand) Init(args []string) (err error) { |
92 if len(c.Series) > 0 && !c.UploadTools { | 94 if len(c.Series) > 0 && !c.UploadTools { |
93 return fmt.Errorf("--series requires --upload-tools") | 95 return fmt.Errorf("--series requires --upload-tools") |
| 96 } |
| 97 if c.MetadataSource != "" { |
| 98 c.MetadataSource, err = utils.NormalizePath(c.MetadataSource) |
| 99 if err != nil { |
| 100 return err |
| 101 } |
| 102 c.MetadataSource, err = filepath.Abs(c.MetadataSource) |
| 103 if err != nil { |
| 104 return err |
| 105 } |
94 } | 106 } |
95 return cmd.CheckEmpty(args) | 107 return cmd.CheckEmpty(args) |
96 } | 108 } |
97 | 109 |
98 type bootstrapContext struct { | 110 type bootstrapContext struct { |
99 *cmd.Context | 111 *cmd.Context |
100 } | 112 } |
101 | 113 |
102 func (c bootstrapContext) Stdin() io.Reader { | 114 func (c bootstrapContext) Stdin() io.Reader { |
103 return c.Context.Stdin | 115 return c.Context.Stdin |
(...skipping 27 matching lines...) Expand all Loading... |
131 return fmt.Errorf("failed to enable bootstrap storage: %
v", err) | 143 return fmt.Errorf("failed to enable bootstrap storage: %
v", err) |
132 } | 144 } |
133 } | 145 } |
134 if err := bootstrap.EnsureNotBootstrapped(environ); err != nil { | 146 if err := bootstrap.EnsureNotBootstrapped(environ); err != nil { |
135 return err | 147 return err |
136 } | 148 } |
137 // If --metadata-source is specified, override the default tools and ima
ge metadata sources. | 149 // If --metadata-source is specified, override the default tools and ima
ge metadata sources. |
138 if c.MetadataSource != "" { | 150 if c.MetadataSource != "" { |
139 logger.Infof("Setting default tools and image metadata sources:
%s", c.MetadataSource) | 151 logger.Infof("Setting default tools and image metadata sources:
%s", c.MetadataSource) |
140 tools.DefaultBaseURL = c.MetadataSource | 152 tools.DefaultBaseURL = c.MetadataSource |
141 imagemetadata.DefaultBaseURL = c.MetadataSource | |
142 if err := imagemetadata.UploadImageMetadata(environ.Storage(), c
.MetadataSource); err != nil { | 153 if err := imagemetadata.UploadImageMetadata(environ.Storage(), c
.MetadataSource); err != nil { |
143 // Do not error if image metadata directory doesn't exis
t. | 154 // Do not error if image metadata directory doesn't exis
t. |
144 if !os.IsNotExist(err) { | 155 if !os.IsNotExist(err) { |
145 return fmt.Errorf("uploading image metadata: %v"
, err) | 156 return fmt.Errorf("uploading image metadata: %v"
, err) |
146 } | 157 } |
147 } else { | 158 } else { |
148 logger.Infof("custom image metadata uploaded") | 159 logger.Infof("custom image metadata uploaded") |
149 } | 160 } |
150 } | 161 } |
151 // TODO (wallyworld): 2013-09-20 bug 1227931 | 162 // TODO (wallyworld): 2013-09-20 bug 1227931 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // probably upload, based on cfg. | 220 // probably upload, based on cfg. |
210 func getUploadSeries(cfg *config.Config, series []string) []string { | 221 func getUploadSeries(cfg *config.Config, series []string) []string { |
211 unique := set.NewStrings(series...) | 222 unique := set.NewStrings(series...) |
212 if unique.IsEmpty() { | 223 if unique.IsEmpty() { |
213 unique.Add(version.Current.Series) | 224 unique.Add(version.Current.Series) |
214 unique.Add(config.DefaultSeries) | 225 unique.Add(config.DefaultSeries) |
215 unique.Add(cfg.DefaultSeries()) | 226 unique.Add(cfg.DefaultSeries()) |
216 } | 227 } |
217 return unique.Values() | 228 return unique.Values() |
218 } | 229 } |
LEFT | RIGHT |