426
426
*credential = cred
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(),
435
436
for k, v := range cloud.Config {
437
modelConfigAttrs[k] = v
438
439
userConfigAttrs, err := c.config.ReadAttrs(ctx)
440
441
return errors.Trace(err)
442
443
for k, v := range userConfigAttrs {
445
logger.Debugf("preparing controller with config: %v", configAttrs)
444
modelConfigAttrs[k] = v
446
bootstrapConfigAttrs := make(map[string]interface{})
447
controllerConfigAttrs := make(map[string]interface{})
448
for k, v := range modelConfigAttrs {
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)
458
bootstrapConfig, err := bootstrap.NewConfig(controllerUUID.String(), bootstrapConfigAttrs)
460
return errors.Annotate(err, "constructing bootstrap config")
462
controllerConfig, err := controller.NewConfig(
463
controllerUUID.String(), bootstrapConfig.CACert, controllerConfigAttrs,
466
return errors.Annotate(err, "constructing controller config")
468
if err := common.FinalizeAuthorizedKeys(ctx, modelConfigAttrs); err != nil {
469
return errors.Annotate(err, "finalizing authorized-keys")
471
logger.Debugf("preparing controller with config: %v", modelConfigAttrs)
447
473
// Read existing current controller so we can clean up on error.
448
474
var oldCurrentController string
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(),
482
for attr, cfgValue := range configAttrs {
483
if !controller.ControllerOnlyAttribute(attr) {
486
controllerConfig[attr] = cfgValue
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,
507
521
// Set the current model to the initial hosted model.
508
accountName, err := store.CurrentAccount(c.controllerName)
510
return errors.Trace(err)
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(),
515
525
return errors.Trace(err)
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)
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
604
delete(hostedModelConfig, config.AuthKeysConfig)
614
delete(hostedModelConfig, config.AuthorizedKeysKey)
605
615
delete(hostedModelConfig, config.AgentVersionKey)
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,
651
668
return errors.Annotate(err, "failed to bootstrap model")