~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/commands/bootstrap.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
type bootstrapCommand struct {
124
124
        modelcmd.ModelCommandBase
125
125
 
126
 
        Constraints           constraints.Value
127
 
        BootstrapConstraints  constraints.Value
128
 
        BootstrapSeries       string
129
 
        BootstrapImage        string
130
 
        BuildAgent            bool
131
 
        MetadataSource        string
132
 
        Placement             string
133
 
        KeepBrokenEnvironment bool
134
 
        AutoUpgrade           bool
135
 
        AgentVersionParam     string
136
 
        AgentVersion          *version.Number
137
 
        config                common.ConfigFlag
 
126
        Constraints             constraints.Value
 
127
        ConstraintsStr          string
 
128
        BootstrapConstraints    constraints.Value
 
129
        BootstrapConstraintsStr string
 
130
        BootstrapSeries         string
 
131
        BootstrapImage          string
 
132
        BuildAgent              bool
 
133
        MetadataSource          string
 
134
        Placement               string
 
135
        KeepBrokenEnvironment   bool
 
136
        AutoUpgrade             bool
 
137
        AgentVersionParam       string
 
138
        AgentVersion            *version.Number
 
139
        config                  common.ConfigFlag
138
140
 
139
141
        showClouds          bool
140
142
        showRegionsForCloud string
158
160
 
159
161
func (c *bootstrapCommand) SetFlags(f *gnuflag.FlagSet) {
160
162
        c.ModelCommandBase.SetFlags(f)
161
 
        f.Var(constraints.ConstraintsValue{Target: &c.Constraints}, "constraints", "Set model constraints")
162
 
        f.Var(constraints.ConstraintsValue{Target: &c.BootstrapConstraints}, "bootstrap-constraints", "Specify bootstrap machine constraints")
 
163
        f.StringVar(&c.ConstraintsStr, "constraints", "", "Set model constraints")
 
164
        f.StringVar(&c.BootstrapConstraintsStr, "bootstrap-constraints", "", "Specify bootstrap machine constraints")
163
165
        f.StringVar(&c.BootstrapSeries, "bootstrap-series", "", "Specify the series of the bootstrap machine")
164
166
        if featureflag.Enabled(feature.ImageMetadata) {
165
167
                f.StringVar(&c.BootstrapImage, "bootstrap-image", "", "Specify the image of the bootstrap machine")
195
197
        if c.BootstrapSeries != "" && !charm.IsValidSeries(c.BootstrapSeries) {
196
198
                return errors.NotValidf("series %q", c.BootstrapSeries)
197
199
        }
198
 
        if c.BootstrapImage != "" {
199
 
                if c.BootstrapSeries == "" {
200
 
                        return errors.Errorf("--bootstrap-image must be used with --bootstrap-series")
201
 
                }
202
 
                cons, err := constraints.Merge(c.Constraints, c.BootstrapConstraints)
203
 
                if err != nil {
204
 
                        return errors.Trace(err)
205
 
                }
206
 
                if !cons.HasArch() {
207
 
                        return errors.Errorf("--bootstrap-image must be used with --bootstrap-constraints, specifying architecture")
208
 
                }
209
 
        }
210
200
 
211
201
        // Parse the placement directive. Bootstrap currently only
212
202
        // supports provider-specific placement directives.
290
280
specify a credential using the --credential argument`[1:],
291
281
)
292
282
 
 
283
func (c *bootstrapCommand) parseConstraints(ctx *cmd.Context) (err error) {
 
284
        allAliases := map[string]string{}
 
285
        defer common.WarnConstraintAliases(ctx, allAliases)
 
286
        if c.ConstraintsStr != "" {
 
287
                cons, aliases, err := constraints.ParseWithAliases(c.ConstraintsStr)
 
288
                for k, v := range aliases {
 
289
                        allAliases[k] = v
 
290
                }
 
291
                if err != nil {
 
292
                        return err
 
293
                }
 
294
                c.Constraints = cons
 
295
        }
 
296
        if c.BootstrapConstraintsStr != "" {
 
297
                cons, aliases, err := constraints.ParseWithAliases(c.BootstrapConstraintsStr)
 
298
                for k, v := range aliases {
 
299
                        allAliases[k] = v
 
300
                }
 
301
                if err != nil {
 
302
                        return err
 
303
                }
 
304
                c.BootstrapConstraints = cons
 
305
        }
 
306
        return nil
 
307
}
 
308
 
293
309
// Run connects to the environment specified on the command line and bootstraps
294
310
// a juju in that environment if none already exists. If there is as yet no environments.yaml file,
295
311
// the user is informed how to create one.
296
312
func (c *bootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
 
313
        if err := c.parseConstraints(ctx); err != nil {
 
314
                return err
 
315
        }
 
316
        if c.BootstrapImage != "" {
 
317
                if c.BootstrapSeries == "" {
 
318
                        return errors.Errorf("--bootstrap-image must be used with --bootstrap-series")
 
319
                }
 
320
                cons, err := constraints.Merge(c.Constraints, c.BootstrapConstraints)
 
321
                if err != nil {
 
322
                        return errors.Trace(err)
 
323
                }
 
324
                if !cons.HasArch() {
 
325
                        return errors.Errorf("--bootstrap-image must be used with --bootstrap-constraints, specifying architecture")
 
326
                }
 
327
        }
297
328
        if c.interactive {
298
329
                if err := c.runInteractive(ctx); err != nil {
299
330
                        return errors.Trace(err)
390
421
        store := c.ClientStore()
391
422
        var detectedCredentialName string
392
423
        credential, credentialName, regionName, err := modelcmd.GetCredentials(
393
 
                store, c.Region, c.CredentialName, c.Cloud, cloud.Type,
 
424
                ctx, store, modelcmd.GetCredentialsParams{
 
425
                        Cloud:          *cloud,
 
426
                        CloudName:      c.Cloud,
 
427
                        CloudRegion:    c.Region,
 
428
                        CredentialName: c.CredentialName,
 
429
                },
394
430
        )
395
431
        if errors.Cause(err) == modelcmd.ErrMultipleCredentials {
396
432
                return ambiguousCredentialError