當前位置: 首頁>>代碼示例>>Golang>>正文


Golang storage.NewConfig函數代碼示例

本文整理匯總了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)
}
開發者ID:bac,項目名稱:juju,代碼行數:13,代碼來源:loop_test.go

示例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)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:13,代碼來源:tmpfs_test.go

示例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
}
開發者ID:kat-co,項目名稱:juju,代碼行數:7,代碼來源:storage_test.go

示例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
		},
	}
}
開發者ID:mhilton,項目名稱:juju,代碼行數:28,代碼來源:package_test.go

示例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
}
開發者ID:imoapps,項目名稱:juju,代碼行數:29,代碼來源:poolmanager.go

示例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)
}
開發者ID:bac,項目名稱:juju,代碼行數:8,代碼來源:storage_test.go

示例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
}
開發者ID:kakamessi99,項目名稱:juju,代碼行數:9,代碼來源:ebs_test.go

示例8: init

func init() {
	ebsssdPool, _ := storage.NewConfig("ebs-ssd", EBS_ProviderType, map[string]interface{}{
		EBS_VolumeType: volumeTypeSsd,
	})
	defaultPools := []*storage.Config{
		ebsssdPool,
	}
	poolmanager.RegisterDefaultStoragePools(defaultPools)
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:9,代碼來源:ebs.go

示例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())
	}
}
開發者ID:imoapps,項目名稱:juju,代碼行數:18,代碼來源:defaultpool_test.go

示例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)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:9,代碼來源:tmpfs_test.go

示例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)
	}
}
開發者ID:kat-co,項目名稱:juju,代碼行數:9,代碼來源:poollist_test.go

示例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
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:9,代碼來源:volumes_test.go

示例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"`)
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:9,代碼來源:volumes_test.go

示例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"},
	})
}
開發者ID:bac,項目名稱:juju,代碼行數:22,代碼來源:defaultpool_test.go

示例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")
}
開發者ID:Pankov404,項目名稱:juju,代碼行數:14,代碼來源:poollist_test.go


注:本文中的github.com/juju/juju/storage.NewConfig函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。