示例#1
0
// storeImageMetadataFromFiles puts image metadata found in sources into state.
func storeImageMetadataFromFiles(st *state.State, env environs.Environ, source simplestreams.DataSource) error {
	// Read the image metadata, as we'll want to upload it to the environment.
	imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{})
	if inst, ok := env.(simplestreams.HasRegion); ok {
		// If we can determine current region,
		// we want only metadata specific to this region.
		cloud, err := inst.Region()
		if err != nil {
			return err
		}
		imageConstraint.CloudSpec = cloud
	}

	existingMetadata, info, err := imagemetadata.Fetch([]simplestreams.DataSource{source}, imageConstraint)
	if err != nil && !errors.IsNotFound(err) {
		return errors.Annotate(err, "cannot read image metadata")
	}
	return storeImageMetadataInState(st, info.Source, source.Priority(), existingMetadata)
}