本文整理汇总了Golang中github.com/juju/juju/storage.NewConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConfig函数的具体用法?Golang NewConfig怎么用?Golang NewConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestVolumeSource
func (s *loopSuite) TestVolumeSource(c *gc.C) {
p := s.loopProvider(c)
cfg, err := storage.NewConfig("name", provider.LoopProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
_, err = p.VolumeSource(cfg)
c.Assert(err, gc.ErrorMatches, "storage directory not specified")
cfg, err = storage.NewConfig("name", provider.LoopProviderType, map[string]interface{}{
"storage-dir": c.MkDir(),
})
c.Assert(err, jc.ErrorIsNil)
_, err = p.VolumeSource(cfg)
c.Assert(err, jc.ErrorIsNil)
}
示例2: TestFilesystemSource
func (s *tmpfsSuite) TestFilesystemSource(c *gc.C) {
p := s.tmpfsProvider(c)
cfg, err := storage.NewConfig("name", provider.TmpfsProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
_, err = p.FilesystemSource(nil, cfg)
c.Assert(err, gc.ErrorMatches, "storage directory not specified")
cfg, err = storage.NewConfig("name", provider.TmpfsProviderType, map[string]interface{}{
"storage-dir": c.MkDir(),
})
c.Assert(err, jc.ErrorIsNil)
_, err = p.FilesystemSource(nil, cfg)
c.Assert(err, jc.ErrorIsNil)
}
示例3: mustStorageConfig
func mustStorageConfig(name string, provider storage.ProviderType, attrs map[string]interface{}) *storage.Config {
cfg, err := storage.NewConfig(name, provider, attrs)
if err != nil {
panic(err)
}
return cfg
}
示例4: constructPoolManager
func (s *baseStorageSuite) constructPoolManager(c *gc.C) *mockPoolManager {
return &mockPoolManager{
getPool: func(name string) (*jujustorage.Config, error) {
if one, ok := s.pools[name]; ok {
return one, nil
}
return nil, errors.NotFoundf("mock pool manager: get pool %v", name)
},
createPool: func(name string, providerType jujustorage.ProviderType, attrs map[string]interface{}) (*jujustorage.Config, error) {
pool, err := jujustorage.NewConfig(name, providerType, attrs)
s.pools[name] = pool
return pool, err
},
deletePool: func(name string) error {
delete(s.pools, name)
return nil
},
listPools: func() ([]*jujustorage.Config, error) {
result := make([]*jujustorage.Config, len(s.pools))
i := 0
for _, v := range s.pools {
result[i] = v
i++
}
return result, nil
},
}
}
示例5: Create
// Create is defined on PoolManager interface.
func (pm *poolManager) Create(name string, providerType storage.ProviderType, attrs map[string]interface{}) (*storage.Config, error) {
if name == "" {
return nil, MissingNameError
}
if providerType == "" {
return nil, MissingTypeError
}
cfg, err := storage.NewConfig(name, providerType, attrs)
if err != nil {
return nil, errors.Trace(err)
}
p, err := registry.StorageProvider(providerType)
if err != nil {
return nil, errors.Trace(err)
}
if err := provider.ValidateConfig(p, cfg); err != nil {
return nil, errors.Annotate(err, "validating storage provider config")
}
poolAttrs := cfg.Attrs()
poolAttrs[Name] = name
poolAttrs[Type] = string(providerType)
if err := pm.settings.CreateSettings(globalKey(name), poolAttrs); err != nil {
return nil, errors.Annotatef(err, "creating pool %q", name)
}
return cfg, nil
}
示例6: TestFilesystemSource
func (s *storageSuite) TestFilesystemSource(c *gc.C) {
storageConfig, err := storage.NewConfig("azure", "azure", nil)
c.Assert(err, jc.ErrorIsNil)
_, err = s.provider.FilesystemSource(storageConfig)
c.Assert(err, gc.ErrorMatches, "filesystems not supported")
c.Assert(err, jc.Satisfies, errors.IsNotSupported)
}
示例7: TestValidateConfigUnknownConfig
func (*storageSuite) TestValidateConfigUnknownConfig(c *gc.C) {
p := ec2.EBSProvider()
cfg, err := storage.NewConfig("foo", ec2.EBS_ProviderType, map[string]interface{}{
"unknown": "config",
})
c.Assert(err, jc.ErrorIsNil)
err = p.ValidateConfig(cfg)
c.Assert(err, jc.ErrorIsNil) // unknown attrs ignored
}
示例8: init
func init() {
ebsssdPool, _ := storage.NewConfig("ebs-ssd", EBS_ProviderType, map[string]interface{}{
EBS_VolumeType: volumeTypeSsd,
})
defaultPools := []*storage.Config{
ebsssdPool,
}
poolmanager.RegisterDefaultStoragePools(defaultPools)
}
示例9: TestDefaultStoragePools
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())
}
}
示例10: TestValidateConfig
func (s *tmpfsSuite) TestValidateConfig(c *gc.C) {
p := s.tmpfsProvider(c)
cfg, err := storage.NewConfig("name", provider.TmpfsProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
err = p.ValidateConfig(cfg)
// The tmpfs provider does not have any user
// configuration, so an empty map will pass.
c.Assert(err, jc.ErrorIsNil)
}
示例11: createPools
func (s *poolSuite) createPools(c *gc.C, num int) {
var err error
for i := 0; i < num; i++ {
poolName := fmt.Sprintf("%v%v", tstName, i)
s.baseStorageSuite.pools[poolName], err =
storage.NewConfig(poolName, provider.LoopProviderType, nil)
c.Assert(err, jc.ErrorIsNil)
}
}
示例12: TestValidateConfigUnknownAttribute
func (*storageProviderSuite) TestValidateConfigUnknownAttribute(c *gc.C) {
p := maasStorageProvider{}
cfg, err := storage.NewConfig("foo", maasStorageProviderType, map[string]interface{}{
"unknown": "config",
})
c.Assert(err, jc.ErrorIsNil)
err = p.ValidateConfig(cfg)
c.Assert(err, jc.ErrorIsNil) // unknown attributes are ignored
}
示例13: TestValidateConfigInvalidConfig
func (*storageProviderSuite) TestValidateConfigInvalidConfig(c *gc.C) {
p := maasStorageProvider{}
cfg, err := storage.NewConfig("foo", maasStorageProviderType, map[string]interface{}{
"tags": "white space",
})
c.Assert(err, jc.ErrorIsNil)
err = p.ValidateConfig(cfg)
c.Assert(err, gc.ErrorMatches, `tags may not contain whitespace: "white space"`)
}
示例14: TestDefaultStoragePools
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"},
})
}
示例15: TestListByTypesOr
func (s *poolSuite) TestListByTypesOr(c *gc.C) {
s.createPools(c, 2)
s.registerProviders(c)
tstType := string(provider.TmpfsProviderType)
poolName := "rayofsunshine"
var err error
s.baseStorageSuite.pools[poolName], err =
storage.NewConfig(poolName, provider.TmpfsProviderType, nil)
c.Assert(err, jc.ErrorIsNil)
pools, err := s.api.ListPools(params.StoragePoolFilter{
Providers: []string{tstType, string(provider.LoopProviderType)}})
c.Assert(err, jc.ErrorIsNil)
assertPoolNames(c, pools.Results, "testpool0", "testpool1", "rayofsunshine", "loop", "tmpfs")
}