本文整理汇总了Golang中github.com/juju/juju/environs.Provider函数的典型用法代码示例。如果您正苦于以下问题:Golang Provider函数的具体用法?Golang Provider怎么用?Golang Provider使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Provider函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNullAlias
func (s *providerSuite) TestNullAlias(c *gc.C) {
p, err := environs.Provider("manual")
c.Assert(p, gc.NotNil)
c.Assert(err, jc.ErrorIsNil)
p, err = environs.Provider("null")
c.Assert(p, gc.NotNil)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:provider_test.go
示例2: finalizeConfig
// finalizeConfig creates the config object from attributes, calls
// PrepareForCreateEnvironment, and then finally validates the config
// before returning it.
func finalizeConfig(isAdmin bool, controllerCfg *config.Config, attrs map[string]interface{}) (*config.Config, error) {
provider, err := environs.Provider(controllerCfg.Type())
if err != nil {
return nil, errors.Trace(err)
}
// Controller admins creating models do not have to re-supply new secrets.
// These may be copied from the controller model if not supplied.
if isAdmin {
maybeCopyControllerSecrets(provider, controllerCfg.AllAttrs(), attrs)
}
cfg, err := config.New(config.UseDefaults, attrs)
if err != nil {
return nil, errors.Annotate(err, "creating config from values failed")
}
cfg, err = provider.PrepareForCreateEnvironment(cfg)
if err != nil {
return nil, errors.Trace(err)
}
cfg, err = provider.Validate(cfg, nil)
if err != nil {
return nil, errors.Annotate(err, "provider validation failed")
}
return cfg, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:29,代码来源:createmodel.go
示例3: init
func init() {
dummyProvider, err := environs.Provider("dummy")
if err != nil {
panic(err)
}
environs.RegisterProvider("fake", mockProvider{dummyProvider})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:credentials_test.go
示例4: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
oldMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
newMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
if !exploded {
c.Assert(newMetadata, gc.HasLen, len(oldMetadata))
} else {
// new metadata should have more tools.
c.Assert(len(newMetadata), jc.GreaterThan, len(oldMetadata))
var expectedSeries set.Strings
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Ubuntu {
expectedSeries.Add(series)
}
}
c.Assert(newMetadata, gc.HasLen, expectedSeries.Size())
for _, m := range newMetadata {
c.Assert(expectedSeries.Contains(m.Release), jc.IsTrue)
}
}
}
开发者ID:kapilt,项目名称:juju,代码行数:34,代码来源:bootstrap_test.go
示例5: prepare
func (c *imageMetadataCommandBase) prepare(context *cmd.Context) (environs.Environ, error) {
// NOTE(axw) this is a work-around for the TODO below. This
// means that the command will only work if you've bootstrapped
// the specified environment.
bootstrapConfig, params, err := modelcmd.NewGetBootstrapConfigParamsFunc(context, c.ClientStore())(c.ControllerName())
if err != nil {
return nil, errors.Trace(err)
}
provider, err := environs.Provider(bootstrapConfig.CloudType)
if err != nil {
return nil, errors.Trace(err)
}
cfg, err := provider.PrepareConfig(*params)
if err != nil {
return nil, errors.Trace(err)
}
// TODO(axw) we'll need to revise the metadata commands to work
// without preparing an environment. They should take the same
// format as bootstrap, i.e. cloud/region, and we'll use that to
// identify region and endpoint info that we need. Not sure what
// we'll do about simplestreams.MetadataValidator yet. Probably
// move it to the EnvironProvider interface.
return environs.New(environs.OpenParams{
Cloud: params.Cloud,
Config: cfg,
})
}
开发者ID:bac,项目名称:juju,代码行数:27,代码来源:imagemetadata.go
示例6: SetUpTest
func (s *credentialsSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
var err error
s.provider, err = environs.Provider("gce")
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:credentials_test.go
示例7: TestProvidersAreRegistered
func (s *MainSuite) TestProvidersAreRegistered(c *gc.C) {
// check that all the expected providers are registered
for _, name := range expectedProviders {
_, err := environs.Provider(name)
c.Assert(err, jc.ErrorIsNil)
}
}
开发者ID:Pankov404,项目名称:juju,代码行数:7,代码来源:main_test.go
示例8: SetUpTest
func (s *providerSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
var err error
s.provider, err = environs.Provider("gce")
c.Check(err, jc.ErrorIsNil)
}
开发者ID:pmatulis,项目名称:juju,代码行数:7,代码来源:provider_test.go
示例9: ModelConfig
// ModelConfig returns the current environment's configuration.
func (e *ModelWatcher) ModelConfig() (params.ModelConfigResult, error) {
result := params.ModelConfigResult{}
config, err := e.st.ModelConfig()
if err != nil {
return result, err
}
allAttrs := config.AllAttrs()
if !e.authorizer.AuthModelManager() {
// Mask out any secrets in the environment configuration
// with values of the same type, so it'll pass validation.
//
// TODO(dimitern) 201309-26 bug #1231384
// Delete the code below and mark the bug as fixed,
// once it's live tested on MAAS and 1.16 compatibility
// is dropped.
provider, err := environs.Provider(config.Type())
if err != nil {
return result, err
}
secretAttrs, err := provider.SecretAttrs(config)
for k := range secretAttrs {
allAttrs[k] = "not available"
}
}
result.Config = allAttrs
return result, nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:30,代码来源:modelwatcher.go
示例10: builtInProviders
// builtInProviders returns cloud information for those
// providers which are built in to Juju.
func builtInProviders() map[string]jujucloud.Cloud {
builtIn := make(map[string]jujucloud.Cloud)
for _, name := range jujucloud.BuiltInProviderNames {
provider, err := environs.Provider(name)
if err != nil {
// Should never happen but it will on go 1.2
// because lxd provider is not built.
logger.Warningf("cloud %q not available on this platform", name)
continue
}
var regions []jujucloud.Region
if detector, ok := provider.(environs.CloudRegionDetector); ok {
regions, err = detector.DetectRegions()
if err != nil && !errors.IsNotFound(err) {
logger.Warningf("could not detect regions for %q: %v", name, err)
}
}
cloud := jujucloud.Cloud{
Type: name,
Regions: regions,
}
schema := provider.CredentialSchemas()
for authType := range schema {
if authType == jujucloud.EmptyAuthType {
continue
}
cloud.AuthTypes = append(cloud.AuthTypes, authType)
}
builtIn[name] = cloud
}
return builtIn
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:34,代码来源:list.go
示例11: SetUpTest
func (s *providerSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
provider, err := environs.Provider("lxd")
c.Assert(err, jc.ErrorIsNil)
s.provider = provider
}
开发者ID:exekias,项目名称:juju,代码行数:7,代码来源:provider_test.go
示例12: makeTestEnv
func (s *BootstrapSuite) makeTestEnv(c *gc.C) {
attrs := dummy.SampleConfig().Merge(
testing.Attrs{
"agent-version": version.Current.Number.String(),
"bootstrap-timeout": "123",
},
).Delete("admin-secret", "ca-private-key")
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
provider, err := environs.Provider(cfg.Type())
c.Assert(err, jc.ErrorIsNil)
env, err := provider.PrepareForBootstrap(nullContext(), cfg)
c.Assert(err, jc.ErrorIsNil)
envtesting.MustUploadFakeTools(s.toolsStorage, cfg.AgentStream(), cfg.AgentStream())
inst, _, _, err := jujutesting.StartInstance(env, "0")
c.Assert(err, jc.ErrorIsNil)
s.instanceId = inst.Id()
addresses, err := inst.Addresses()
c.Assert(err, jc.ErrorIsNil)
s.bootstrapName = network.SelectPublicAddress(addresses)
s.envcfg = env.Config()
s.b64yamlEnvcfg = b64yaml(s.envcfg.AllAttrs()).encode()
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:25,代码来源:bootstrap_test.go
示例13: SetUpTest
func (s *credentialsSuite) SetUpTest(c *gc.C) {
s.FakeHomeSuite.SetUpTest(c)
var err error
s.provider, err = environs.Provider("maas")
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:credentials_test.go
示例14: SetUpTest
func (s *providerSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
provider, err := environs.Provider("joyent")
c.Assert(err, jc.ErrorIsNil)
s.provider = provider
s.spec = fakeCloudSpec()
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:provider_test.go
示例15: RestrictedProviderFields
// RestrictedProviderFields returns the set of config fields that may not be
// overridden.
func RestrictedProviderFields(providerType string) ([]string, error) {
provider, err := environs.Provider(providerType)
if err != nil {
return nil, errors.Trace(err)
}
var fields []string
fields = append(fields, configValuesFromController...)
fields = append(fields, provider.RestrictedConfigAttributes()...)
return fields, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:12,代码来源:createmodel.go
示例16: createLookupParams
func (c *validateImageMetadataCommand) createLookupParams(context *cmd.Context) (*simplestreams.MetadataLookupParams, error) {
params := &simplestreams.MetadataLookupParams{Stream: c.stream}
if c.providerType == "" {
environ, err := c.prepare(context)
if err != nil {
return nil, err
}
mdLookup, ok := environ.(simplestreams.MetadataValidator)
if !ok {
return nil, fmt.Errorf("%s provider does not support image metadata validation", environ.Config().Type())
}
params, err = mdLookup.MetadataLookupParams(c.region)
if err != nil {
return nil, err
}
oes := &overrideEnvStream{environ, c.stream}
params.Sources, err = environs.ImageMetadataSources(oes)
if err != nil {
return nil, err
}
} else {
prov, err := environs.Provider(c.providerType)
if err != nil {
return nil, err
}
mdLookup, ok := prov.(simplestreams.MetadataValidator)
if !ok {
return nil, fmt.Errorf("%s provider does not support image metadata validation", c.providerType)
}
params, err = mdLookup.MetadataLookupParams(c.region)
if err != nil {
return nil, err
}
}
if c.series != "" {
params.Series = c.series
}
if c.region != "" {
params.Region = c.region
}
if c.endpoint != "" {
params.Endpoint = c.endpoint
}
if c.metadataDir != "" {
dir := filepath.Join(c.metadataDir, "images")
if _, err := os.Stat(dir); err != nil {
return nil, err
}
params.Sources = imagesDataSources(dir)
}
return params, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:54,代码来源:validateimagemetadata.go
示例17: restrictedProviderFields
func (em *EnvironmentManagerAPI) restrictedProviderFields(providerType string) ([]string, error) {
provider, err := environs.Provider(providerType)
if err != nil {
return nil, errors.Trace(err)
}
var fields []string
fields = append(fields, configValuesFromStateServer...)
fields = append(fields, provider.RestrictedConfigAttributes()...)
return fields, nil
}
开发者ID:Pankov404,项目名称:juju,代码行数:11,代码来源:environmentmanager.go
示例18: getBootstrapConfig
func (g bootstrapConfigGetter) getBootstrapConfig(controllerName string) (*config.Config, error) {
bootstrapConfig, params, err := g.getBootstrapConfigParams(controllerName)
if err != nil {
return nil, errors.Trace(err)
}
provider, err := environs.Provider(bootstrapConfig.CloudType)
if err != nil {
return nil, errors.Trace(err)
}
return provider.PrepareConfig(*params)
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:base.go
示例19: environProvider
func environProvider(st *state.State) (environs.EnvironProvider, error) {
model, err := st.Model()
if err != nil {
return nil, errors.Annotate(err, "getting model")
}
cloud, err := st.Cloud(model.Cloud())
if err != nil {
return nil, errors.Annotate(err, "getting cloud")
}
// EnvironProvider implements state.ConfigValidator.
return environs.Provider(cloud.Type)
}
开发者ID:bac,项目名称:juju,代码行数:12,代码来源:policy.go
示例20: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
envtesting.RemoveFakeToolsMetadata(c, env.Storage())
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
// We don't write metadata at bootstrap anymore.
simplestreamsMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
c.Assert(simplestreamsMetadata, gc.HasLen, 0)
// The tools should have been added to state, and
// exploded into each of the supported series of
// the same operating system if the tools were uploaded.
st, err := state.Open(&mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
var expectedSeries set.Strings
if exploded {
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Current.OS {
expectedSeries.Add(series)
}
}
} else {
expectedSeries.Add(version.Current.Series)
}
storage, err := st.ToolsStorage()
c.Assert(err, gc.IsNil)
defer storage.Close()
metadata, err := storage.AllMetadata()
c.Assert(err, gc.IsNil)
c.Assert(metadata, gc.HasLen, expectedSeries.Size())
for _, m := range metadata {
c.Assert(expectedSeries.Contains(m.Version.Series), jc.IsTrue)
}
}
开发者ID:zhouqt,项目名称:juju,代码行数:53,代码来源:bootstrap_test.go
注:本文中的github.com/juju/juju/environs.Provider函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论