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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/jujuclient/jujuclienttesting/mem.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "github.com/juju/errors"
 
8
        "github.com/juju/utils/set"
8
9
 
9
10
        "github.com/juju/juju/cloud"
10
11
        "github.com/juju/juju/jujuclient"
13
14
// MemStore is an in-memory implementation of jujuclient.ClientStore,
14
15
// intended for testing.
15
16
type MemStore struct {
16
 
        Controllers map[string]jujuclient.ControllerDetails
17
 
        Models      map[string]jujuclient.ControllerAccountModels
18
 
        Accounts    map[string]*jujuclient.ControllerAccounts
19
 
        Credentials map[string]cloud.CloudCredential
 
17
        Controllers     map[string]jujuclient.ControllerDetails
 
18
        Models          map[string]jujuclient.ControllerAccountModels
 
19
        Accounts        map[string]*jujuclient.ControllerAccounts
 
20
        Credentials     map[string]cloud.CloudCredential
 
21
        BootstrapConfig map[string]jujuclient.BootstrapConfig
20
22
}
21
23
 
22
24
func NewMemStore() *MemStore {
25
27
                make(map[string]jujuclient.ControllerAccountModels),
26
28
                make(map[string]*jujuclient.ControllerAccounts),
27
29
                make(map[string]cloud.CloudCredential),
 
30
                make(map[string]jujuclient.BootstrapConfig),
28
31
        }
29
32
}
30
33
 
61
64
        if err := jujuclient.ValidateControllerName(name); err != nil {
62
65
                return err
63
66
        }
64
 
        delete(c.Controllers, name)
 
67
        names := set.NewStrings(name)
 
68
        if namedControllerDetails, ok := c.Controllers[name]; ok {
 
69
                for name, details := range c.Controllers {
 
70
                        if details.ControllerUUID == namedControllerDetails.ControllerUUID {
 
71
                                names.Add(name)
 
72
                        }
 
73
                }
 
74
        }
 
75
        for _, name := range names.Values() {
 
76
                delete(c.Models, name)
 
77
                delete(c.Accounts, name)
 
78
                delete(c.BootstrapConfig, name)
 
79
                delete(c.Controllers, name)
 
80
        }
65
81
        return nil
66
82
}
67
83
 
352
368
        }
353
369
        return result, nil
354
370
}
 
371
 
 
372
// UpdateBootstrapConfig implements BootstrapConfigUpdater.
 
373
func (c *MemStore) UpdateBootstrapConfig(controllerName string, cfg jujuclient.BootstrapConfig) error {
 
374
        if err := jujuclient.ValidateControllerName(controllerName); err != nil {
 
375
                return err
 
376
        }
 
377
        if err := jujuclient.ValidateBootstrapConfig(cfg); err != nil {
 
378
                return err
 
379
        }
 
380
        c.BootstrapConfig[controllerName] = cfg
 
381
        return nil
 
382
 
 
383
}
 
384
 
 
385
// BootstrapConfigForController implements BootstrapConfigGetter.
 
386
func (c *MemStore) BootstrapConfigForController(controllerName string) (*jujuclient.BootstrapConfig, error) {
 
387
        if cfg, ok := c.BootstrapConfig[controllerName]; ok {
 
388
                return &cfg, nil
 
389
        }
 
390
        return nil, errors.NotFoundf("bootstrap config for controller %s", controllerName)
 
391
 
 
392
}