func (st *State) createDefaultStoragePoolsOps(registry storage.ProviderRegistry) ([]txn.Op, error) { m := poolmanager.MemSettings{make(map[string]map[string]interface{})} pm := poolmanager.New(m, registry) providerTypes, err := registry.StorageProviderTypes() if err != nil { return nil, errors.Trace(err) } for _, providerType := range providerTypes { p, err := registry.StorageProvider(providerType) if err != nil { return nil, errors.Trace(err) } if err := poolmanager.AddDefaultStoragePools(p, pm); err != nil { return nil, errors.Annotatef( err, "adding default storage pools for %q", providerType, ) } } var ops []txn.Op for key, settings := range m.Settings { ops = append(ops, createSettingsOp(settingsC, key, settings)) } return ops, nil }
func (s *defaultStoragePoolsSuite) TestDefaultStoragePools(c *gc.C) { p1, err := storage.NewConfig("pool1", storage.ProviderType("loop"), map[string]interface{}{"1": "2"}) p2, err := storage.NewConfig("pool2", storage.ProviderType("tmpfs"), map[string]interface{}{"3": "4"}) c.Assert(err, jc.ErrorIsNil) defaultPools := []*storage.Config{p1, p2} poolmanager.RegisterDefaultStoragePools(defaultPools) settings := state.NewStateSettings(s.State) err = poolmanager.AddDefaultStoragePools(settings) c.Assert(err, jc.ErrorIsNil) pm := poolmanager.New(settings) for _, pool := range defaultPools { p, err := pm.Get(pool.Name()) c.Assert(err, jc.ErrorIsNil) c.Assert(p.Provider(), gc.Equals, pool.Provider()) c.Assert(p.Attrs(), gc.DeepEquals, pool.Attrs()) } }
func (s *defaultStoragePoolsSuite) TestDefaultStoragePools(c *gc.C) { p1, err := storage.NewConfig("pool1", storage.ProviderType("whatever"), map[string]interface{}{"1": "2"}) c.Assert(err, jc.ErrorIsNil) p2, err := storage.NewConfig("pool2", storage.ProviderType("whatever"), map[string]interface{}{"3": "4"}) c.Assert(err, jc.ErrorIsNil) provider := &dummystorage.StorageProvider{ DefaultPools_: []*storage.Config{p1, p2}, } settings := poolmanager.MemSettings{make(map[string]map[string]interface{})} pm := poolmanager.New(settings, storage.StaticProviderRegistry{ map[storage.ProviderType]storage.Provider{"whatever": provider}, }) err = poolmanager.AddDefaultStoragePools(provider, pm) c.Assert(err, jc.ErrorIsNil) c.Assert(settings.Settings, jc.DeepEquals, map[string]map[string]interface{}{ "pool#pool1": map[string]interface{}{"1": "2", "name": "pool1", "type": "whatever"}, "pool#pool2": map[string]interface{}{"3": "4", "name": "pool2", "type": "whatever"}, }) }
// populateDefaultStoragePools creates the default storage pools. func (c *BootstrapCommand) populateDefaultStoragePools(st *state.State) error { settings := state.NewStateSettings(st) return poolmanager.AddDefaultStoragePools(settings) }
func addDefaultStoragePools(st *state.State) error { settings := state.NewStateSettings(st) return poolmanager.AddDefaultStoragePools(settings) }