本文整理汇总了Golang中github.com/juju/juju/environs.ImageMetadataSources函数的典型用法代码示例。如果您正苦于以下问题:Golang ImageMetadataSources函数的具体用法?Golang ImageMetadataSources怎么用?Golang ImageMetadataSources使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageMetadataSources函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestBootstrapMetadataImagesMissing
func (s *bootstrapSuite) TestBootstrapMetadataImagesMissing(c *gc.C) {
environs.UnregisterImageDataSourceFunc("bootstrap metadata")
noImagesDir := c.MkDir()
stor, err := filestorage.NewFileStorageWriter(noImagesDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
AdminSecret: "admin-secret",
CAPrivateKey: coretesting.CAKey,
MetadataDir: noImagesDir,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.bootstrapCount, gc.Equals, 1)
datasources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
c.Assert(datasources, gc.HasLen, 2)
c.Assert(datasources[0].Description(), gc.Equals, "default cloud images")
c.Assert(datasources[1].Description(), gc.Equals, "default ubuntu cloud images")
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:bootstrap_test.go
示例2: TestImageMetadataURLsRegisteredFuncs
func (s *ImageMetadataSuite) TestImageMetadataURLsRegisteredFuncs(c *gc.C) {
environs.RegisterImageDataSourceFunc("id0", func(environs.Environ) (simplestreams.DataSource, error) {
return simplestreams.NewURLDataSource("id0", "betwixt/releases", utils.NoVerifySSLHostnames), nil
})
environs.RegisterImageDataSourceFunc("id1", func(environs.Environ) (simplestreams.DataSource, error) {
return simplestreams.NewURLDataSource("id1", "yoink", utils.NoVerifySSLHostnames), nil
})
// overwrite the one previously registered against id1
environs.RegisterImageDataSourceFunc("id1", func(environs.Environ) (simplestreams.DataSource, error) {
return nil, errors.NewNotSupported(nil, "oyvey")
})
environs.RegisterUserImageDataSourceFunc("id2", func(environs.Environ) (simplestreams.DataSource, error) {
return simplestreams.NewURLDataSource("id2", "foobar", utils.NoVerifySSLHostnames), nil
})
defer environs.UnregisterImageDataSourceFunc("id0")
defer environs.UnregisterImageDataSourceFunc("id1")
defer environs.UnregisterImageDataSourceFunc("id2")
env := s.env(c, "config-image-metadata-url", "")
sources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
sstesting.AssertExpectedSources(c, sources, []string{
"config-image-metadata-url/",
"foobar/",
"betwixt/releases/",
"http://cloud-images.ubuntu.com/releases/",
})
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:28,代码来源:imagemetadata_test.go
示例3: findImageMetadata
func findImageMetadata(env *environ, args environs.StartInstanceParams) (*OvaFileMetadata, error) {
arches := args.Tools.Arches()
series := args.Tools.OneSeries()
ic := &imagemetadata.ImageConstraint{
LookupParams: simplestreams.LookupParams{
Series: []string{series},
Arches: arches,
Stream: env.ecfg.ImageStream(),
},
}
sources, err := environs.ImageMetadataSources(env)
if err != nil {
return nil, errors.Trace(err)
}
matchingImages, err := imageMetadataFetch(sources, ic)
if err != nil {
return nil, errors.Trace(err)
}
if len(matchingImages) == 0 {
return nil, errors.Errorf("no matching images found for given constraints: %v", ic)
}
return matchingImages[0], nil
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:image_metadata.go
示例4: TestBootstrapImageMetadataFromAllSources
// TestBootstrapImageMetadataFromAllSources tests that we are looking for
// image metadata in all data sources available to environment.
// Abandoning look up too soon led to misleading bootstrap failures:
// Juju reported no images available for a particular configuration,
// despite image metadata in other data sources compatible with the same configuration as well.
// Related to bug#1560625.
func (s *bootstrapSuite) TestBootstrapImageMetadataFromAllSources(c *gc.C) {
s.PatchValue(&series.HostSeries, func() string { return "raring" })
s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
// Ensure that we can find at least one image metadata
// early on in the image metadata lookup.
// We should continue looking despite it.
metadataDir, _ := createImageMetadata(c)
stor, err := filestorage.NewFileStorageWriter(metadataDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
env := bootstrapEnvironWithRegion{
newEnviron("foo", useDefaultKeys, nil),
simplestreams.CloudSpec{
Region: "region",
Endpoint: "endpoint",
},
}
s.setDummyStorage(c, env.bootstrapEnviron)
bootstrapCons := constraints.MustParse("arch=amd64")
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
BootstrapConstraints: bootstrapCons,
MetadataDir: metadataDir,
})
c.Assert(err, jc.ErrorIsNil)
datasources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
for _, source := range datasources {
// make sure we looked in each and all...
c.Assert(c.GetTestLog(), jc.Contains, fmt.Sprintf("image metadata in %s", source.Description()))
}
}
开发者ID:makyo,项目名称:juju,代码行数:41,代码来源:bootstrap_test.go
示例5: TestBootstrapMetadata
func (s *bootstrapSuite) TestBootstrapMetadata(c *gc.C) {
environs.UnregisterImageDataSourceFunc("bootstrap metadata")
metadataDir, metadata := createImageMetadata(c)
stor, err := filestorage.NewFileStorageWriter(metadataDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
MetadataDir: metadataDir,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.bootstrapCount, gc.Equals, 1)
c.Assert(envtools.DefaultBaseURL, gc.Equals, metadataDir)
datasources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
c.Assert(datasources, gc.HasLen, 3)
c.Assert(datasources[0].Description(), gc.Equals, "bootstrap metadata")
// This data source does not require to contain signed data.
// However, it may still contain it.
// Since we will always try to read signed data first,
// we want to be able to try to read this signed data
// with a user provided key.
// for this test, user provided key is empty.
// Bugs #1542127, #1542131
c.Assert(datasources[0].PublicSigningKey(), gc.Equals, "")
c.Assert(env.instanceConfig, gc.NotNil)
c.Assert(env.instanceConfig.CustomImageMetadata, gc.HasLen, 1)
c.Assert(env.instanceConfig.CustomImageMetadata[0], gc.DeepEquals, metadata[0])
}
开发者ID:makyo,项目名称:juju,代码行数:33,代码来源:bootstrap_test.go
示例6: TestImageMetadataURLsRegisteredFuncs
func (s *ImageMetadataSuite) TestImageMetadataURLsRegisteredFuncs(c *gc.C) {
environs.RegisterImageDataSourceFunc("id0", func(environs.Environ) (simplestreams.DataSource, error) {
return simplestreams.NewURLDataSource("id0", "betwixt/releases", utils.NoVerifySSLHostnames, simplestreams.DEFAULT_CLOUD_DATA, false), nil
})
environs.RegisterImageDataSourceFunc("id1", func(environs.Environ) (simplestreams.DataSource, error) {
return simplestreams.NewURLDataSource("id1", "yoink", utils.NoVerifySSLHostnames, simplestreams.SPECIFIC_CLOUD_DATA, false), nil
})
// overwrite the one previously registered against id1
environs.RegisterImageDataSourceFunc("id1", func(environs.Environ) (simplestreams.DataSource, error) {
return nil, errors.NewNotSupported(nil, "oyvey")
})
environs.RegisterUserImageDataSourceFunc("id2", func(environs.Environ) (simplestreams.DataSource, error) {
return simplestreams.NewURLDataSource("id2", "foobar", utils.NoVerifySSLHostnames, simplestreams.CUSTOM_CLOUD_DATA, false), nil
})
defer environs.UnregisterImageDataSourceFunc("id0")
defer environs.UnregisterImageDataSourceFunc("id1")
defer environs.UnregisterImageDataSourceFunc("id2")
env := s.env(c, "config-image-metadata-url", "")
sources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
sstesting.AssertExpectedSources(c, sources, []sstesting.SourceDetails{
{"config-image-metadata-url/", ""},
{"foobar/", ""},
{"betwixt/releases/", ""},
{"https://streams.canonical.com/juju/images/releases/", imagemetadata.SimplestreamsImagesPublicKey},
{"http://cloud-images.ubuntu.com/releases/", imagemetadata.SimplestreamsImagesPublicKey},
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:29,代码来源:imagemetadata_test.go
示例7: TestBootstrapMetadata
func (s *bootstrapSuite) TestBootstrapMetadata(c *gc.C) {
environs.UnregisterImageDataSourceFunc("bootstrap metadata")
metadataDir, metadata := createImageMetadata(c)
stor, err := filestorage.NewFileStorageWriter(metadataDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
MetadataDir: metadataDir,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.bootstrapCount, gc.Equals, 1)
c.Assert(envtools.DefaultBaseURL, gc.Equals, metadataDir)
datasources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
c.Assert(datasources, gc.HasLen, 3)
c.Assert(datasources[0].Description(), gc.Equals, "bootstrap metadata")
c.Assert(env.instanceConfig, gc.NotNil)
c.Assert(env.instanceConfig.CustomImageMetadata, gc.HasLen, 1)
c.Assert(env.instanceConfig.CustomImageMetadata[0], gc.DeepEquals, metadata[0])
}
开发者ID:pmatulis,项目名称:juju,代码行数:25,代码来源:bootstrap_test.go
示例8: SetImageMetadata
func SetImageMetadata(env environs.Environ, series, arches []string, out *[]*imagemetadata.ImageMetadata) error {
hasRegion, ok := env.(simplestreams.HasRegion)
if !ok {
return nil
}
sources, err := environs.ImageMetadataSources(env)
if err != nil {
return errors.Trace(err)
}
region, err := hasRegion.Region()
if err != nil {
return errors.Trace(err)
}
imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{
CloudSpec: region,
Series: series,
Arches: arches,
Stream: env.Config().ImageStream(),
})
imageMetadata, _, err := imagemetadata.Fetch(sources, imageConstraint)
if err != nil {
return errors.Trace(err)
}
*out = imageMetadata
return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:26,代码来源:instance.go
示例9: FindInstanceSpec
// FindInstanceSpec returns an InstanceSpec satisfying the supplied instanceConstraint.
func (env *joyentEnviron) FindInstanceSpec(ic *instances.InstanceConstraint) (*instances.InstanceSpec, error) {
// Require at least one VCPU so we get KVM rather than smart package.
if ic.Constraints.CpuCores == nil {
ic.Constraints.CpuCores = &defaultCpuCores
}
allInstanceTypes, err := env.listInstanceTypes()
if err != nil {
return nil, err
}
imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{
CloudSpec: simplestreams.CloudSpec{ic.Region, env.Ecfg().SdcUrl()},
Series: []string{ic.Series},
Arches: ic.Arches,
})
sources, err := environs.ImageMetadataSources(env)
if err != nil {
return nil, err
}
matchingImages, _, err := imagemetadata.Fetch(sources, imageConstraint, signedImageDataOnly)
if err != nil {
return nil, err
}
images := instances.ImageMetadataToImages(matchingImages)
spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes)
if err != nil {
return nil, err
}
return spec, nil
}
开发者ID:kakamessi99,项目名称:juju,代码行数:31,代码来源:environ_instance.go
示例10: TestImageMetadataURLs
func (s *ImageMetadataSuite) TestImageMetadataURLs(c *gc.C) {
env := s.env(c, "config-image-metadata-url", "")
sources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
sstesting.AssertExpectedSources(c, sources, []string{
"config-image-metadata-url/", "http://cloud-images.ubuntu.com/releases/",
})
}
开发者ID:Pankov404,项目名称:juju,代码行数:8,代码来源:imagemetadata_test.go
示例11: TestImageMetadataURLsNonReleaseStream
func (s *ImageMetadataSuite) TestImageMetadataURLsNonReleaseStream(c *gc.C) {
env := s.env(c, "", "daily")
sources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
sstesting.AssertExpectedSources(c, sources, []string{
"http://cloud-images.ubuntu.com/daily/",
})
}
开发者ID:Pankov404,项目名称:juju,代码行数:8,代码来源:imagemetadata_test.go
示例12: TestImageMetadataURLsNoConfigURL
func (s *ImageMetadataSuite) TestImageMetadataURLsNoConfigURL(c *gc.C) {
env := s.env(c, "", "")
sources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
sstesting.AssertExpectedSources(c, sources, []string{
"https://streams.canonical.com/juju/images/releases/",
"http://cloud-images.ubuntu.com/releases/",
})
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:imagemetadata_test.go
示例13: TestImageMetadataURLsNonReleaseStream
func (s *ImageMetadataSuite) TestImageMetadataURLsNonReleaseStream(c *gc.C) {
env := s.env(c, "", "daily")
sources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
sstesting.AssertExpectedSources(c, sources, []sstesting.SourceDetails{
{"https://streams.canonical.com/juju/images/daily/", imagemetadata.SimplestreamsImagesPublicKey},
{"http://cloud-images.ubuntu.com/daily/", imagemetadata.SimplestreamsImagesPublicKey},
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:9,代码来源:imagemetadata_test.go
示例14: TestImageMetadataURLs
func (s *ImageMetadataSuite) TestImageMetadataURLs(c *gc.C) {
env := s.env(c, "config-image-metadata-url", "")
sources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
sstesting.AssertExpectedSources(c, sources, []sstesting.SourceDetails{
{"config-image-metadata-url/", ""},
{"https://streams.canonical.com/juju/images/releases/", keys.JujuPublicKey},
{"http://cloud-images.ubuntu.com/releases/", imagemetadata.SimplestreamsImagesPublicKey},
})
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:imagemetadata_test.go
示例15: TestImageMetadataURLsRegisteredFuncsError
func (s *ImageMetadataSuite) TestImageMetadataURLsRegisteredFuncsError(c *gc.C) {
environs.RegisterImageDataSourceFunc("id0", func(environs.Environ) (simplestreams.DataSource, error) {
return nil, errors.New("oyvey!")
})
defer environs.UnregisterImageDataSourceFunc("id0")
env := s.env(c, "config-image-metadata-url", "")
_, err := environs.ImageMetadataSources(env)
c.Assert(err, gc.ErrorMatches, "oyvey!")
}
开发者ID:Pankov404,项目名称:juju,代码行数:10,代码来源:imagemetadata_test.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: TestValidateImageMetadata
func (s *localServerSuite) TestValidateImageMetadata(c *gc.C) {
env := s.Prepare(c)
params, err := env.(simplestreams.MetadataValidator).MetadataLookupParams("some-region")
c.Assert(err, jc.ErrorIsNil)
params.Sources, err = environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
params.Series = "raring"
image_ids, _, err := imagemetadata.ValidateImageMetadata(params)
c.Assert(err, jc.ErrorIsNil)
c.Assert(image_ids, gc.DeepEquals, []string{"11223344-0a0a-dd77-33cd-abcd1234e5f6"})
}
开发者ID:exekias,项目名称:juju,代码行数:11,代码来源:local_test.go
示例18: TestValidateImageMetadata
func (t *localServerSuite) TestValidateImageMetadata(c *gc.C) {
env := t.Prepare(c)
params, err := env.(simplestreams.MetadataValidator).MetadataLookupParams("test")
c.Assert(err, jc.ErrorIsNil)
params.Series = coretesting.FakeDefaultSeries
params.Endpoint = "https://ec2.endpoint.com"
params.Sources, err = environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
image_ids, _, err := imagemetadata.ValidateImageMetadata(params)
c.Assert(err, jc.ErrorIsNil)
sort.Strings(image_ids)
c.Assert(image_ids, gc.DeepEquals, []string{"ami-00000033", "ami-00000034", "ami-00000035", "ami-00000039"})
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:13,代码来源:local_test.go
示例19: SupportedArchitectures
// SupportedArchitectures returns all the image architectures for env matching the constraints.
func SupportedArchitectures(env environs.Environ, imageConstraint *imagemetadata.ImageConstraint) ([]string, error) {
sources, err := environs.ImageMetadataSources(env)
if err != nil {
return nil, err
}
matchingImages, _, err := imagemetadata.Fetch(sources, imageConstraint, false)
if err != nil {
return nil, err
}
var arches = set.NewStrings()
for _, im := range matchingImages {
arches.Add(im.Arch)
}
return arches.Values(), nil
}
开发者ID:Pankov404,项目名称:juju,代码行数:16,代码来源:supportedarchitectures.go
示例20: retrievePublished
func (api *API) retrievePublished() error {
envCfg, err := api.metadata.ModelConfig()
if err != nil {
return errors.Annotatef(err, "getting environ config")
}
env, err := environs.New(envCfg)
if err != nil {
return errors.Annotatef(err, "getting environ")
}
sources, err := environs.ImageMetadataSources(env)
if err != nil {
return errors.Annotatef(err, "getting cloud specific image metadata sources")
}
cons := envmetadata.NewImageConstraint(simplestreams.LookupParams{})
if inst, ok := env.(simplestreams.HasRegion); !ok {
// Published image metadata for some providers are in simple streams.
// Providers that do not rely on simplestreams, don't need to do anything here.
return nil
} else {
// If we can determine current region,
// we want only metadata specific to this region.
cloud, err := inst.Region()
if err != nil {
return errors.Annotatef(err, "getting cloud specific region information")
}
cons.CloudSpec = cloud
}
// We want all relevant metadata from all data sources.
for _, source := range sources {
logger.Debugf("looking in data source %v", source.Description())
metadata, info, err := envmetadata.Fetch([]simplestreams.DataSource{source}, cons)
if err != nil {
// Do not stop looking in other data sources if there is an issue here.
logger.Errorf("encountered %v while getting published images metadata from %v", err, source.Description())
continue
}
err = api.saveAll(info, source.Priority(), metadata)
if err != nil {
// Do not stop looking in other data sources if there is an issue here.
logger.Errorf("encountered %v while saving published images metadata from %v", err, source.Description())
}
}
return nil
}
开发者ID:exekias,项目名称:juju,代码行数:47,代码来源:metadata.go
注:本文中的github.com/juju/juju/environs.ImageMetadataSources函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论