• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang registry.StorageProvider函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/juju/storage/provider/registry.StorageProvider函数的典型用法代码示例。如果您正苦于以下问题:Golang StorageProvider函数的具体用法?Golang StorageProvider怎么用?Golang StorageProvider使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了StorageProvider函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: destroyStorage

func destroyStorage(env environs.Environ) error {
	logger.Infof("destroying storage")
	environConfig := env.Config()
	storageProviderTypes, ok := registry.EnvironStorageProviders(environConfig.Type())
	if !ok {
		return nil
	}
	for _, storageProviderType := range storageProviderTypes {
		storageProvider, err := registry.StorageProvider(storageProviderType)
		if err != nil {
			return errors.Trace(err)
		}
		if !storageProvider.Dynamic() {
			continue
		}
		if storageProvider.Scope() != storage.ScopeEnviron {
			continue
		}
		if err := destroyVolumes(environConfig, storageProviderType, storageProvider); err != nil {
			return errors.Trace(err)
		}
		// TODO(axw) destroy env-level filesystems when we have them.
	}
	return nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:25,代码来源:destroy.go


示例2: 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 = &params.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


示例3: 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


示例4: TestRegisterProvider

func (s *providerRegistrySuite) TestRegisterProvider(c *gc.C) {
	p1 := &mockProvider{}
	ptype := storage.ProviderType("foo")
	registry.RegisterProvider(ptype, p1)
	p, err := registry.StorageProvider(ptype)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(p, gc.Equals, p1)
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:providerregistry_test.go


示例5: TestUnregisterProvider

func (s *providerRegistrySuite) TestUnregisterProvider(c *gc.C) {
	ptype := storage.ProviderType("foo")

	// No-op, since there's nothing registered yet.
	registry.RegisterProvider(ptype, nil)

	// Register and then unregister, ensure that the provider cannot
	// be accessed.
	registry.RegisterProvider(ptype, &mockProvider{})
	registry.RegisterProvider(ptype, nil)
	_, err := registry.StorageProvider(storage.ProviderType("foo"))
	c.Assert(err, gc.ErrorMatches, `storage provider "foo" not found`)
}
开发者ID:imoapps,项目名称:juju,代码行数:13,代码来源:providerregistry_test.go


示例6: StoragePoolConfig

// StoragePoolConfig returns the storage provider type and
// configuration for a named storage pool. If there is no
// such pool with the specified name, but it identifies a
// storage provider, then that type will be returned with a
// nil configuration.
func StoragePoolConfig(name string, poolManager poolmanager.PoolManager) (storage.ProviderType, *storage.Config, error) {
	pool, err := poolManager.Get(name)
	if errors.IsNotFound(err) {
		// If not a storage pool, then maybe a provider type.
		providerType := storage.ProviderType(name)
		if _, err1 := registry.StorageProvider(providerType); err1 != nil {
			return "", nil, errors.Trace(err)
		}
		return providerType, &storage.Config{}, nil
	} else if err != nil {
		return "", nil, errors.Annotatef(err, "getting pool %q", name)
	}
	return pool.Provider(), pool, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:19,代码来源:volumes.go


示例7: poolStorageProvider

func poolStorageProvider(st *State, poolName string) (storage.ProviderType, storage.Provider, error) {
	poolManager := poolmanager.New(NewStateSettings(st))
	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:imoapps,项目名称:juju,代码行数:24,代码来源:storage.go


示例8: 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


示例9: sourceParams

func sourceParams(providerType storage.ProviderType, sourceName, baseStorageDir string) (storage.Provider, *storage.Config, error) {
	provider, err := registry.StorageProvider(providerType)
	if err != nil {
		return nil, nil, errors.Annotate(err, "getting provider")
	}
	attrs := make(map[string]interface{})
	if baseStorageDir != "" {
		storageDir := filepath.Join(baseStorageDir, sourceName)
		attrs[storage.ConfigStorageDir] = storageDir
	}
	sourceConfig, err := storage.NewConfig(sourceName, providerType, attrs)
	if err != nil {
		return nil, nil, errors.Annotate(err, "getting config")
	}
	return provider, sourceConfig, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:16,代码来源:common.go


示例10: configFromSettings

func configFromSettings(settings map[string]interface{}) (*storage.Config, error) {
	providerType := storage.ProviderType(settings[Type].(string))
	name := settings[Name].(string)
	// Ensure returned attributes are stripped of name and type,
	// as these are not user-specified attributes.
	delete(settings, Name)
	delete(settings, Type)
	cfg, err := storage.NewConfig(name, providerType, settings)
	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.Trace(err)
	}
	return cfg, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:20,代码来源:poolmanager.go


示例11: TestMAASProviderRegistered

func (*maasProviderSuite) TestMAASProviderRegistered(c *gc.C) {
	p, err := registry.StorageProvider(maas.MaasStorageProviderType)
	c.Assert(err, jc.ErrorIsNil)
	_, ok := p.(storage.Provider)
	c.Assert(ok, jc.IsTrue)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:6,代码来源:init_test.go


示例12: TestNoSuchProvider

func (s *providerRegistrySuite) TestNoSuchProvider(c *gc.C) {
	_, err := registry.StorageProvider(storage.ProviderType("foo"))
	c.Assert(err, gc.ErrorMatches, `storage provider "foo" not found`)
}
开发者ID:imoapps,项目名称:juju,代码行数:4,代码来源:providerregistry_test.go


示例13: TestEBSProviderRegistered

func (*providerSuite) TestEBSProviderRegistered(c *gc.C) {
	p, err := registry.StorageProvider(ec2.EBS_ProviderType)
	c.Assert(err, jc.ErrorIsNil)
	_, ok := p.(storage.Provider)
	c.Assert(ok, jc.IsTrue)
}
开发者ID:imoapps,项目名称:juju,代码行数:6,代码来源:init_test.go



注:本文中的github.com/juju/juju/storage/provider/registry.StorageProvider函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang testcharms.UploadBundle函数代码示例发布时间:2022-05-23
下一篇:
Golang registry.RegisterProvider函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap