本文整理汇总了Golang中github.com/juju/juju/storage/poolmanager.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createDefaultStoragePoolsOps
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
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:open.go
示例2: TestAddServiceDefaultPool
func (s *VolumeStateSuite) TestAddServiceDefaultPool(c *gc.C) {
// Register a default pool.
pm := poolmanager.New(state.NewStateSettings(s.State))
_, err := pm.Create("default-block", provider.LoopProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
err = s.State.UpdateEnvironConfig(map[string]interface{}{
"storage-default-block-source": "default-block",
}, nil, nil)
c.Assert(err, jc.ErrorIsNil)
ch := s.AddTestingCharm(c, "storage-block")
storage := map[string]state.StorageConstraints{
"data": makeStorageCons("", 1024, 1),
}
service := s.AddTestingServiceWithStorage(c, "storage-block", ch, storage)
cons, err := service.StorageConstraints()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cons, jc.DeepEquals, map[string]state.StorageConstraints{
"data": state.StorageConstraints{
Pool: "default-block",
Size: 1024,
Count: 1,
},
"allecto": state.StorageConstraints{
Pool: "loop",
Size: 1024,
Count: 0,
},
})
}
开发者ID:Pankov404,项目名称:juju,代码行数:30,代码来源:volume_test.go
示例3: poolStorageProvider
func poolStorageProvider(st *State, poolName string) (storage.ProviderType, storage.Provider, error) {
registry, err := st.storageProviderRegistry()
if err != nil {
return "", nil, errors.Annotate(err, "getting storage provider registry")
}
poolManager := poolmanager.New(NewStateSettings(st), registry)
pool, err := poolManager.Get(poolName)
if errors.IsNotFound(err) {
// If there's no pool called poolName, maybe a provider type
// has been specified directly.
providerType := storage.ProviderType(poolName)
provider, err1 := registry.StorageProvider(providerType)
if err1 != nil {
// The name can't be resolved as a storage provider type,
// so return the original "pool not found" error.
return "", nil, errors.Trace(err)
}
return providerType, provider, nil
} else if err != nil {
return "", nil, errors.Trace(err)
}
providerType := pool.Provider()
provider, err := registry.StorageProvider(providerType)
if err != nil {
return "", nil, errors.Trace(err)
}
return providerType, provider, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:28,代码来源:storage.go
示例4: machineVolumeParams
// machineVolumeParams retrieves VolumeParams for the volumes that should be
// provisioned with, and attached to, the machine. The client should ignore
// parameters that it does not know how to handle.
func (p *ProvisionerAPI) machineVolumeParams(m *state.Machine) ([]params.VolumeParams, error) {
volumeAttachments, err := m.VolumeAttachments()
if err != nil {
return nil, err
}
if len(volumeAttachments) == 0 {
return nil, nil
}
envConfig, err := p.st.EnvironConfig()
if err != nil {
return nil, err
}
poolManager := poolmanager.New(state.NewStateSettings(p.st))
allVolumeParams := make([]params.VolumeParams, 0, len(volumeAttachments))
for _, volumeAttachment := range volumeAttachments {
volumeTag := volumeAttachment.Volume()
volume, err := p.st.Volume(volumeTag)
if err != nil {
return nil, errors.Annotatef(err, "getting volume %q", volumeTag.Id())
}
storageInstance, err := storagecommon.MaybeAssignedStorageInstance(
volume.StorageInstance, p.st.StorageInstance,
)
if err != nil {
return nil, errors.Annotatef(err, "getting volume %q storage instance", volumeTag.Id())
}
volumeParams, err := storagecommon.VolumeParams(volume, storageInstance, envConfig, poolManager)
if err != nil {
return nil, errors.Annotatef(err, "getting volume %q parameters", volumeTag.Id())
}
provider, err := registry.StorageProvider(storage.ProviderType(volumeParams.Provider))
if err != nil {
return nil, errors.Annotate(err, "getting storage provider")
}
if provider.Dynamic() {
// Leave dynamic storage to the storage provisioner.
continue
}
volumeAttachmentParams, ok := volumeAttachment.Params()
if !ok {
// Attachment is already provisioned; this is an insane
// state, so we should not proceed with the volume.
return nil, errors.Errorf(
"volume %s already attached to machine %s",
volumeTag.Id(), m.Id(),
)
}
// Not provisioned yet, so ask the cloud provisioner do it.
volumeParams.Attachment = ¶ms.VolumeAttachmentParams{
volumeTag.String(),
m.Tag().String(),
"", // we're creating the volume, so it has no volume ID.
"", // we're creating the machine, so it has no instance ID.
volumeParams.Provider,
volumeAttachmentParams.ReadOnly,
}
allVolumeParams = append(allVolumeParams, volumeParams)
}
return allVolumeParams, nil
}
开发者ID:kakamessi99,项目名称:juju,代码行数:63,代码来源:provisioner.go
示例5: TestClientServiceDeployWithUnsupportedStoragePool
func (s *serviceSuite) TestClientServiceDeployWithUnsupportedStoragePool(c *gc.C) {
registry.RegisterProvider("hostloop", &mockStorageProvider{kind: storage.StorageKindBlock})
pm := poolmanager.New(state.NewStateSettings(s.State))
_, err := pm.Create("host-loop-pool", provider.HostLoopProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
curl, _ := s.UploadCharm(c, "utopic/storage-block-0", "storage-block")
storageConstraints := map[string]storage.Constraints{
"data": storage.Constraints{
Pool: "host-loop-pool",
Count: 1,
Size: 1024,
},
}
var cons constraints.Value
args := params.ServiceDeploy{
ServiceName: "service",
CharmUrl: curl.String(),
NumUnits: 1,
Constraints: cons,
Storage: storageConstraints,
}
results, err := s.serviceApi.ServicesDeploy(params.ServicesDeploy{
Services: []params.ServiceDeploy{args}},
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Assert(results.Results[0].Error, gc.ErrorMatches,
`.*pool "host-loop-pool" uses storage provider "hostloop" which is not supported for environments of type "dummy"`)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:31,代码来源:service_test.go
示例6: TestDestroyEnvironmentWithPersistentVolumesFails
func (s *EnvironSuite) TestDestroyEnvironmentWithPersistentVolumesFails(c *gc.C) {
// Create a persistent volume.
// TODO(wallyworld) - consider moving this to factory
registry.RegisterEnvironStorageProviders("someprovider", ec2.EBS_ProviderType)
pm := poolmanager.New(state.NewStateSettings(s.State))
_, err := pm.Create("persistent-block", ec2.EBS_ProviderType, map[string]interface{}{"persistent": "true"})
c.Assert(err, jc.ErrorIsNil)
ch := s.AddTestingCharm(c, "storage-block2")
storage := map[string]state.StorageConstraints{
"multi1to10": makeStorageCons("persistent-block", 1024, 1),
}
service := s.AddTestingServiceWithStorage(c, "storage-block2", ch, storage)
unit, err := service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = s.State.AssignUnit(unit, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
volume1, err := s.State.StorageInstanceVolume(names.NewStorageTag("multi1to10/0"))
c.Assert(err, jc.ErrorIsNil)
volumeInfoSet := state.VolumeInfo{Size: 123, Persistent: true, VolumeId: "vol-ume"}
err = s.State.SetVolumeInfo(volume1.VolumeTag(), volumeInfoSet)
c.Assert(err, jc.ErrorIsNil)
env, err := s.State.Environment()
c.Assert(err, jc.ErrorIsNil)
// TODO(wallyworld) when we can destroy/remove volume, ensure env can then be destroyed
c.Assert(errors.Cause(env.Destroy()), gc.Equals, state.ErrPersistentVolumesExist)
}
开发者ID:Pankov404,项目名称:juju,代码行数:29,代码来源:environ_test.go
示例7: TestStorage
// TODO(wallyworld) - add another test that deploy with storage fails for older environments
// (need deploy client to be refactored to use API stub)
func (s *DeploySuite) TestStorage(c *gc.C) {
pm := poolmanager.New(state.NewStateSettings(s.State))
_, err := pm.Create("loop-pool", provider.LoopProviderType, map[string]interface{}{"foo": "bar"})
c.Assert(err, jc.ErrorIsNil)
testcharms.Repo.CharmArchivePath(s.SeriesPath, "storage-block")
err = runDeploy(c, "local:storage-block", "--storage", "data=loop-pool,1G")
c.Assert(err, jc.ErrorIsNil)
curl := charm.MustParseURL("local:trusty/storage-block-1")
service, _ := s.AssertService(c, "storage-block", curl, 1, 0)
cons, err := service.StorageConstraints()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cons, jc.DeepEquals, map[string]state.StorageConstraints{
"data": {
Pool: "loop-pool",
Count: 1,
Size: 1024,
},
"allecto": {
Pool: "loop",
Count: 0,
Size: 1024,
},
})
}
开发者ID:snailwalker,项目名称:juju,代码行数:28,代码来源:deploy_test.go
示例8: makeUnitWithStorage
func (s *MigrationBaseSuite) makeUnitWithStorage(c *gc.C) (*state.Application, *state.Unit, names.StorageTag) {
pool := "loop-pool"
kind := "block"
// Create a default pool for block devices.
pm := poolmanager.New(state.NewStateSettings(s.State), dummy.StorageProviders())
_, err := pm.Create(pool, provider.LoopProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
// There are test charms called "storage-block" and
// "storage-filesystem" which are what you'd expect.
ch := s.AddTestingCharm(c, "storage-"+kind)
storage := map[string]state.StorageConstraints{
"data": makeStorageCons(pool, 1024, 1),
}
service := s.AddTestingServiceWithStorage(c, "storage-"+kind, ch, storage)
unit, err := service.AddUnit()
machine := s.Factory.MakeMachine(c, nil)
err = unit.AssignToMachine(machine)
c.Assert(err, jc.ErrorIsNil)
c.Assert(err, jc.ErrorIsNil)
storageTag := names.NewStorageTag("data/0")
agentVersion := version.MustParseBinary("2.0.1-quantal-and64")
err = unit.SetAgentVersion(agentVersion)
c.Assert(err, jc.ErrorIsNil)
return service, unit, storageTag
}
开发者ID:kat-co,项目名称:juju,代码行数:28,代码来源:migration_export_test.go
示例9: setupTestStorageSupport
func setupTestStorageSupport(c *gc.C, s *state.State) {
stsetts := state.NewStateSettings(s)
poolManager := poolmanager.New(stsetts, dummy.StorageProviders())
_, err := poolManager.Create(testPool, provider.LoopProviderType, map[string]interface{}{"it": "works"})
c.Assert(err, jc.ErrorIsNil)
_, err = poolManager.Create(testPersistentPool, "environscoped", map[string]interface{}{"persistent": true})
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:unitStorage_test.go
示例10: setupTestStorageSupport
func setupTestStorageSupport(c *gc.C, s *state.State) {
stsetts := state.NewStateSettings(s)
poolManager := poolmanager.New(stsetts)
_, err := poolManager.Create(testPool, provider.LoopProviderType, map[string]interface{}{"it": "works"})
c.Assert(err, jc.ErrorIsNil)
registry.RegisterEnvironStorageProviders("dummy", ec2.EBS_ProviderType)
registry.RegisterEnvironStorageProviders("dummyenv", ec2.EBS_ProviderType)
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:storage_test.go
示例11: SetUpTest
func (s *assignCleanSuite) SetUpTest(c *gc.C) {
c.Logf("assignment policy for this test: %q", s.policy)
s.ConnSuite.SetUpTest(c)
wordpress := s.AddTestingService(c, "wordpress", s.AddTestingCharm(c, "wordpress"))
s.wordpress = wordpress
pm := poolmanager.New(state.NewStateSettings(s.State), provider.CommonStorageProviders())
_, err := pm.Create("loop-pool", provider.LoopProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:assign_test.go
示例12: setupStoragePool
func (s *baseSuite) setupStoragePool(c *gc.C) {
pm := poolmanager.New(state.NewStateSettings(s.State))
_, err := pm.Create("loop-pool", provider.LoopProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
err = s.State.UpdateEnvironConfig(map[string]interface{}{
"storage-default-block-source": "loop-pool",
}, nil, nil)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:vonwenm,项目名称:juju,代码行数:9,代码来源:api_test.go
示例13: newStorageProvisionerAPI
func newStorageProvisionerAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*StorageProvisionerAPI, error) {
env, err := stateenvirons.GetNewEnvironFunc(environs.New)(st)
if err != nil {
return nil, errors.Annotate(err, "getting environ")
}
registry := stateenvirons.NewStorageProviderRegistry(env)
pm := poolmanager.New(state.NewStateSettings(st), registry)
return NewStorageProvisionerAPI(stateShim{st}, resources, authorizer, registry, pm)
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:shim.go
示例14: SetUpTest
func (s *poolSuite) SetUpTest(c *gc.C) {
s.StateSuite.SetUpTest(c)
s.settings = state.NewStateSettings(s.State)
s.registry = storage.StaticProviderRegistry{
map[storage.ProviderType]storage.Provider{
"loop": &dummystorage.StorageProvider{},
},
}
s.poolManager = poolmanager.New(s.settings, s.registry)
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:poolmanager_test.go
示例15: TestStoragePools
func (s *MigrationImportSuite) TestStoragePools(c *gc.C) {
pm := poolmanager.New(state.NewStateSettings(s.State), provider.CommonStorageProviders())
_, err := pm.Create("test-pool", provider.LoopProviderType, map[string]interface{}{
"value": 42,
})
c.Assert(err, jc.ErrorIsNil)
_, newSt := s.importModel(c)
pm = poolmanager.New(state.NewStateSettings(newSt), provider.CommonStorageProviders())
pools, err := pm.List()
c.Assert(err, jc.ErrorIsNil)
c.Assert(pools, gc.HasLen, 1)
pool := pools[0]
c.Assert(pool.Name(), gc.Equals, "test-pool")
c.Assert(pool.Provider(), gc.Equals, provider.LoopProviderType)
c.Assert(pool.Attrs(), jc.DeepEquals, map[string]interface{}{
"value": 42,
})
}
开发者ID:kat-co,项目名称:juju,代码行数:21,代码来源:migration_import_test.go
示例16: FilesystemParams
// FilesystemParams returns the parameters for creating the filesystems
// with the specified tags.
func (s *StorageProvisionerAPI) FilesystemParams(args params.Entities) (params.FilesystemParamsResults, error) {
canAccess, err := s.getStorageEntityAuthFunc()
if err != nil {
return params.FilesystemParamsResults{}, err
}
envConfig, err := s.st.EnvironConfig()
if err != nil {
return params.FilesystemParamsResults{}, err
}
results := params.FilesystemParamsResults{
Results: make([]params.FilesystemParamsResult, len(args.Entities)),
}
poolManager := poolmanager.New(s.settings)
one := func(arg params.Entity) (params.FilesystemParams, error) {
tag, err := names.ParseFilesystemTag(arg.Tag)
if err != nil || !canAccess(tag) {
return params.FilesystemParams{}, common.ErrPerm
}
filesystem, err := s.st.Filesystem(tag)
if errors.IsNotFound(err) {
return params.FilesystemParams{}, common.ErrPerm
} else if err != nil {
return params.FilesystemParams{}, err
}
storageInstance, err := storagecommon.MaybeAssignedStorageInstance(
filesystem.Storage,
s.st.StorageInstance,
)
if err != nil {
return params.FilesystemParams{}, err
}
filesystemParams, err := storagecommon.FilesystemParams(
filesystem, storageInstance, envConfig, poolManager,
)
if err != nil {
return params.FilesystemParams{}, err
}
return filesystemParams, nil
}
for i, arg := range args.Entities {
var result params.FilesystemParamsResult
filesystemParams, err := one(arg)
if err != nil {
result.Error = common.ServerError(err)
} else {
result.Result = filesystemParams
}
results.Results[i] = result
}
return results, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:53,代码来源:storageprovisioner.go
示例17: SetUpTest
func (s *StorageStateSuiteBase) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
// Create a default pool for block devices.
pm := poolmanager.New(state.NewStateSettings(s.State), dummy.StorageProviders())
_, err := pm.Create("loop-pool", provider.LoopProviderType, map[string]interface{}{})
c.Assert(err, jc.ErrorIsNil)
// Create a pool that creates persistent block devices.
_, err = pm.Create("persistent-block", "environscoped-block", map[string]interface{}{
"persistent": true,
})
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:kat-co,项目名称:juju,代码行数:14,代码来源:storage_test.go
示例18: TestNewModelDefaultPools
func (s *StorageStateSuite) TestNewModelDefaultPools(c *gc.C) {
st := s.Factory.MakeModel(c, &factory.ModelParams{
StorageProviderRegistry: testingStorageProviders,
})
s.AddCleanup(func(*gc.C) { st.Close() })
// When a model is created, it is populated with the default
// pools of each storage provider supported by the model's
// cloud provider.
pm := poolmanager.New(state.NewStateSettings(st), testingStorageProviders)
listed, err := pm.List()
c.Assert(err, jc.ErrorIsNil)
sort.Sort(byStorageConfigName(listed))
c.Assert(listed, jc.DeepEquals, []*storage.Config{blackPool, radiancePool})
}
开发者ID:kat-co,项目名称:juju,代码行数:15,代码来源:storage_test.go
示例19: storagePools
func (i *importer) storagePools() error {
registry, err := i.st.storageProviderRegistry()
if err != nil {
return errors.Annotate(err, "getting provider registry")
}
pm := poolmanager.New(NewStateSettings(i.st), registry)
for _, pool := range i.model.StoragePools() {
_, err := pm.Create(pool.Name(), storage.ProviderType(pool.Provider()), pool.Attributes())
if err != nil {
return errors.Annotatef(err, "creating pool %q", pool.Name())
}
}
return nil
}
开发者ID:kat-co,项目名称:juju,代码行数:15,代码来源:migration_import.go
示例20: storageConfig
// storageConfig returns the provider type and config attributes for the
// specified poolName. If no such pool exists, we check to see if poolName is
// actually a provider type, in which case config will be empty.
func storageConfig(st *state.State, poolName string) (storage.ProviderType, map[string]interface{}, error) {
pm := poolmanager.New(state.NewStateSettings(st))
p, err := pm.Get(poolName)
// If not a storage pool, then maybe a provider type.
if errors.IsNotFound(err) {
providerType := storage.ProviderType(poolName)
if _, err1 := registry.StorageProvider(providerType); err1 != nil {
return "", nil, errors.Trace(err)
}
return providerType, nil, nil
}
if err != nil {
return "", nil, errors.Trace(err)
}
return p.Provider(), p.Attrs(), nil
}
开发者ID:kakamessi99,项目名称:juju,代码行数:19,代码来源:provisioner.go
注:本文中的github.com/juju/juju/storage/poolmanager.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论