100
102
params.Series = simplestreams.SupportedSeries()
102
104
if len(params.Arches) == 0 {
103
params.Arches = []string{"amd64", "i386", "arm"}
105
params.Arches = arch.AllSupportedArches
105
107
return &ImageConstraint{LookupParams: params}
142
144
type ImageMetadata struct {
143
145
Id string `json:"id"`
144
146
Storage string `json:"root_store,omitempty"`
145
VType string `json:"virt,omitempty"`
147
VirtType string `json:"virt,omitempty"`
146
148
Arch string `json:"arch,omitempty"`
147
149
Version string `json:"version,omitempty"`
148
150
RegionAlias string `json:"crsn,omitempty"`
164
166
// The base URL locations are as specified - the first location which has a file is the one used.
165
167
// Signed data is preferred, but if there is no signed data available and onlySigned is false,
166
168
// then unsigned data is used.
167
func Fetch(sources []simplestreams.DataSource, indexPath string, cons *ImageConstraint, onlySigned bool) ([]*ImageMetadata, error) {
170
sources []simplestreams.DataSource, indexPath string, cons *ImageConstraint,
171
onlySigned bool) ([]*ImageMetadata, *simplestreams.ResolveInfo, error) {
168
172
params := simplestreams.ValueParams{
169
173
DataType: ImageIds,
170
174
FilterFunc: appendMatchingImages,
171
175
ValueTemplate: ImageMetadata{},
172
176
PublicKey: simplestreamsImagesPublicKey,
174
items, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
178
items, resolveInfo, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
180
return nil, resolveInfo, err
178
182
metadata := make([]*ImageMetadata, len(items))
179
183
for i, md := range items {
180
184
metadata[i] = md.(*ImageMetadata)
186
// Sorting the metadata is not strictly necessary, but it ensures consistent ordering for
187
// all compilers, and it just makes it easier to look at the data.
189
return metadata, resolveInfo, nil
192
// Sort sorts a slice of ImageMetadata in ascending order of their id
193
// in order to ensure the results of Fetch are ordered deterministically.
194
func Sort(metadata []*ImageMetadata) {
195
sort.Sort(byId(metadata))
198
type byId []*ImageMetadata
200
func (b byId) Len() int { return len(b) }
201
func (b byId) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
202
func (b byId) Less(i, j int) bool { return b[i].Id < b[j].Id }
185
204
type imageKey struct {
198
217
imagesMap := make(map[imageKey]*ImageMetadata, len(matchingImages))
199
218
for _, val := range matchingImages {
200
219
im := val.(*ImageMetadata)
201
imagesMap[imageKey{im.VType, im.Arch, im.Version, im.RegionName, im.Storage}] = im
220
imagesMap[imageKey{im.VirtType, im.Arch, im.Version, im.RegionName, im.Storage}] = im
203
222
for _, val := range images {
204
223
im := val.(*ImageMetadata)
205
224
if cons != nil && cons.Params().Region != "" && cons.Params().Region != im.RegionName {
208
if _, ok := imagesMap[imageKey{im.VType, im.Arch, im.Version, im.RegionName, im.Storage}]; !ok {
227
if _, ok := imagesMap[imageKey{im.VirtType, im.Arch, im.Version, im.RegionName, im.Storage}]; !ok {
209
228
matchingImages = append(matchingImages, im)