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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/modelcmd/base.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:
360
360
 
361
361
// NewGetBootstrapConfigParamsFunc returns a function that, given a controller name,
362
362
// returns the params needed to bootstrap a fresh copy of that controller in the given client store.
363
 
func NewGetBootstrapConfigParamsFunc(store jujuclient.ClientStore) func(string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error) {
364
 
        return bootstrapConfigGetter{store}.getBootstrapConfigParams
 
363
func NewGetBootstrapConfigParamsFunc(ctx *cmd.Context, store jujuclient.ClientStore) func(string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error) {
 
364
        return bootstrapConfigGetter{ctx, store}.getBootstrapConfigParams
365
365
}
366
366
 
367
367
type bootstrapConfigGetter struct {
368
 
        jujuclient.ClientStore
 
368
        ctx   *cmd.Context
 
369
        store jujuclient.ClientStore
369
370
}
370
371
 
371
372
func (g bootstrapConfigGetter) getBootstrapConfig(controllerName string) (*config.Config, error) {
381
382
}
382
383
 
383
384
func (g bootstrapConfigGetter) getBootstrapConfigParams(controllerName string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error) {
384
 
        if _, err := g.ClientStore.ControllerByName(controllerName); err != nil {
 
385
        if _, err := g.store.ControllerByName(controllerName); err != nil {
385
386
                return nil, nil, errors.Annotate(err, "resolving controller name")
386
387
        }
387
 
        bootstrapConfig, err := g.BootstrapConfigForController(controllerName)
 
388
        bootstrapConfig, err := g.store.BootstrapConfigForController(controllerName)
388
389
        if err != nil {
389
390
                return nil, nil, errors.Annotate(err, "getting bootstrap config")
390
391
        }
391
392
 
392
393
        var credential *cloud.Credential
393
394
        if bootstrapConfig.Credential != "" {
 
395
                bootstrapCloud := cloud.Cloud{
 
396
                        Type:             bootstrapConfig.CloudType,
 
397
                        Endpoint:         bootstrapConfig.CloudEndpoint,
 
398
                        IdentityEndpoint: bootstrapConfig.CloudIdentityEndpoint,
 
399
                }
 
400
                if bootstrapConfig.CloudRegion != "" {
 
401
                        bootstrapCloud.Regions = []cloud.Region{{
 
402
                                Name:             bootstrapConfig.CloudRegion,
 
403
                                Endpoint:         bootstrapConfig.CloudEndpoint,
 
404
                                IdentityEndpoint: bootstrapConfig.CloudIdentityEndpoint,
 
405
                        }}
 
406
                }
394
407
                credential, _, _, err = GetCredentials(
395
 
                        g.ClientStore,
396
 
                        bootstrapConfig.CloudRegion,
397
 
                        bootstrapConfig.Credential,
398
 
                        bootstrapConfig.Cloud,
399
 
                        bootstrapConfig.CloudType,
 
408
                        g.ctx, g.store,
 
409
                        GetCredentialsParams{
 
410
                                Cloud:          bootstrapCloud,
 
411
                                CloudName:      bootstrapConfig.Cloud,
 
412
                                CloudRegion:    bootstrapConfig.CloudRegion,
 
413
                                CredentialName: bootstrapConfig.Credential,
 
414
                        },
400
415
                )
401
416
                if err != nil {
402
417
                        return nil, nil, errors.Trace(err)
418
433
        }
419
434
 
420
435
        // Add attributes from the controller details.
421
 
        controllerDetails, err := g.ControllerByName(controllerName)
 
436
        controllerDetails, err := g.store.ControllerByName(controllerName)
422
437
        if err != nil {
423
438
                return nil, nil, errors.Trace(err)
424
439
        }