~juju-qa/ubuntu/yakkety/juju/2.0-beta12

« 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-07-18 18:41:24 UTC
  • mfrom: (1.4.5)
  • Revision ID: nicholas.skaggs@canonical.com-20160718184124-76sg7nr3zf2o6o63
* New upstream release 2.0-beta12
* Update debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
265
265
}
266
266
 
267
267
var (
268
 
        environsPrepare            = environs.Prepare
 
268
        bootstrapPrepare           = bootstrap.Prepare
269
269
        environsDestroy            = environs.Destroy
270
270
        waitForAgentInitialisation = common.WaitForAgentInitialisation
271
271
)
426
426
                *credential = cred
427
427
        }
428
428
 
429
 
        // Create an environment config from the cloud and credentials.
430
 
        configAttrs := map[string]interface{}{
 
429
        // Create a model config, and split out any controller
 
430
        // and bootstrap config attributes.
 
431
        modelConfigAttrs := map[string]interface{}{
431
432
                "type":         cloud.Type,
432
 
                "name":         environs.ControllerModelName,
 
433
                "name":         bootstrap.ControllerModelName,
433
434
                config.UUIDKey: controllerUUID.String(),
434
435
        }
435
436
        for k, v := range cloud.Config {
436
 
                configAttrs[k] = v
 
437
                modelConfigAttrs[k] = v
437
438
        }
438
439
        userConfigAttrs, err := c.config.ReadAttrs(ctx)
439
440
        if err != nil {
440
441
                return errors.Trace(err)
441
442
        }
442
443
        for k, v := range userConfigAttrs {
443
 
                configAttrs[k] = v
444
 
        }
445
 
        logger.Debugf("preparing controller with config: %v", configAttrs)
 
444
                modelConfigAttrs[k] = v
 
445
        }
 
446
        bootstrapConfigAttrs := make(map[string]interface{})
 
447
        controllerConfigAttrs := make(map[string]interface{})
 
448
        for k, v := range modelConfigAttrs {
 
449
                switch {
 
450
                case bootstrap.IsBootstrapAttribute(k):
 
451
                        bootstrapConfigAttrs[k] = v
 
452
                        delete(modelConfigAttrs, k)
 
453
                case controller.ControllerOnlyAttribute(k):
 
454
                        controllerConfigAttrs[k] = v
 
455
                        delete(modelConfigAttrs, k)
 
456
                }
 
457
        }
 
458
        bootstrapConfig, err := bootstrap.NewConfig(controllerUUID.String(), bootstrapConfigAttrs)
 
459
        if err != nil {
 
460
                return errors.Annotate(err, "constructing bootstrap config")
 
461
        }
 
462
        controllerConfig, err := controller.NewConfig(
 
463
                controllerUUID.String(), bootstrapConfig.CACert, controllerConfigAttrs,
 
464
        )
 
465
        if err != nil {
 
466
                return errors.Annotate(err, "constructing controller config")
 
467
        }
 
468
        if err := common.FinalizeAuthorizedKeys(ctx, modelConfigAttrs); err != nil {
 
469
                return errors.Annotate(err, "finalizing authorized-keys")
 
470
        }
 
471
        logger.Debugf("preparing controller with config: %v", modelConfigAttrs)
446
472
 
447
473
        // Read existing current controller so we can clean up on error.
448
474
        var oldCurrentController string
473
499
                }
474
500
        }()
475
501
 
476
 
        // TODO(wallyworld) - we need to separate controller and model schemas
477
 
        // Extract any controller attributes from the bucket of config options
478
 
        // the user may have specified.
479
 
        controllerConfig := controller.Config{
480
 
                controller.ControllerUUIDKey: controllerUUID.String(),
481
 
        }
482
 
        for attr, cfgValue := range configAttrs {
483
 
                if !controller.ControllerOnlyAttribute(attr) {
484
 
                        continue
485
 
                }
486
 
                controllerConfig[attr] = cfgValue
487
 
        }
488
 
 
489
 
        environ, err := environsPrepare(
 
502
        environ, err := bootstrapPrepare(
490
503
                modelcmd.BootstrapContext(ctx), store,
491
 
                environs.PrepareParams{
492
 
                        BaseConfig:           configAttrs,
 
504
                bootstrap.PrepareParams{
 
505
                        BaseConfig:           modelConfigAttrs,
493
506
                        ControllerConfig:     controllerConfig,
494
507
                        ControllerName:       c.controllerName,
495
508
                        CloudName:            c.Cloud,
498
511
                        CloudStorageEndpoint: region.StorageEndpoint,
499
512
                        Credential:           *credential,
500
513
                        CredentialName:       credentialName,
 
514
                        AdminSecret:          bootstrapConfig.AdminSecret,
501
515
                },
502
516
        )
503
517
        if err != nil {
505
519
        }
506
520
 
507
521
        // Set the current model to the initial hosted model.
508
 
        accountName, err := store.CurrentAccount(c.controllerName)
509
 
        if err != nil {
510
 
                return errors.Trace(err)
511
 
        }
512
 
        if err := store.UpdateModel(c.controllerName, accountName, c.hostedModelName, jujuclient.ModelDetails{
 
522
        if err := store.UpdateModel(c.controllerName, c.hostedModelName, jujuclient.ModelDetails{
513
523
                hostedModelUUID.String(),
514
524
        }); err != nil {
515
525
                return errors.Trace(err)
516
526
        }
517
 
        if err := store.SetCurrentModel(c.controllerName, accountName, c.hostedModelName); err != nil {
 
527
        if err := store.SetCurrentModel(c.controllerName, c.hostedModelName); err != nil {
518
528
                return errors.Trace(err)
519
529
        }
520
530
 
601
611
        // model config. These attributes may be modified during bootstrap; by
602
612
        // removing them from this map, we ensure the modified values are
603
613
        // inherited.
604
 
        delete(hostedModelConfig, config.AuthKeysConfig)
 
614
        delete(hostedModelConfig, config.AuthorizedKeysKey)
605
615
        delete(hostedModelConfig, config.AgentVersionKey)
606
616
 
607
617
        // Based on the attribute names in clouds.yaml, create
646
656
                ControllerInheritedConfig: inheritedControllerAttrs,
647
657
                HostedModelConfig:         hostedModelConfig,
648
658
                GUIDataSourceBaseURL:      guiDataSourceBaseURL,
 
659
                AdminSecret:               bootstrapConfig.AdminSecret,
 
660
                CAPrivateKey:              bootstrapConfig.CAPrivateKey,
 
661
                DialOpts: environs.BootstrapDialOpts{
 
662
                        Timeout:        bootstrapConfig.BootstrapTimeout,
 
663
                        RetryDelay:     bootstrapConfig.BootstrapRetryDelay,
 
664
                        AddressesDelay: bootstrapConfig.BootstrapAddressesDelay,
 
665
                },
649
666
        })
650
667
        if err != nil {
651
668
                return errors.Annotate(err, "failed to bootstrap model")