~ubuntu-branches/ubuntu/trusty/juju-core/trusty

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/environs/imagemetadata/simplestreams.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-03-24 16:05:44 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20140324160544-g8lsfufby18d5fj4
Tags: 1.17.6-0ubuntu1
* New upstream point release, including fixes for:
  - br0 not bought up by cloud-init with MAAS provider (LP: #1271144).
  - ppc64el enablement for juju/lxc (LP: #1273769).
  - juju userdata should not restart networking (LP: #1248283).
  - error detecting hardware characteristics (LP: #1276909).
  - juju instances not including the default security group (LP: #1129720).
  - juju bootstrap does not honor https_proxy (LP: #1240260).
* d/control,rules: Drop BD on bash-completion, install bash-completion
  direct from upstream source code.
* d/rules: Set HOME prior to generating man pages.
* d/control: Drop alternative dependency on mongodb-server; juju now only
  works on trusty with juju-mongodb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
import (
10
10
        "fmt"
 
11
        "sort"
11
12
 
12
13
        "launchpad.net/juju-core/environs/simplestreams"
 
14
        "launchpad.net/juju-core/juju/arch"
13
15
)
14
16
 
15
17
func init() {
100
102
                params.Series = simplestreams.SupportedSeries()
101
103
        }
102
104
        if len(params.Arches) == 0 {
103
 
                params.Arches = []string{"amd64", "i386", "arm"}
 
105
                params.Arches = arch.AllSupportedArches
104
106
        }
105
107
        return &ImageConstraint{LookupParams: params}
106
108
}
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) {
 
169
func Fetch(
 
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,
173
177
        }
174
 
        items, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
 
178
        items, resolveInfo, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
175
179
        if err != nil {
176
 
                return nil, err
 
180
                return nil, resolveInfo, err
177
181
        }
178
182
        metadata := make([]*ImageMetadata, len(items))
179
183
        for i, md := range items {
180
184
                metadata[i] = md.(*ImageMetadata)
181
185
        }
182
 
        return metadata, nil
183
 
}
 
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.
 
188
        Sort(metadata)
 
189
        return metadata, resolveInfo, nil
 
190
}
 
191
 
 
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))
 
196
}
 
197
 
 
198
type byId []*ImageMetadata
 
199
 
 
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 }
184
203
 
185
204
type imageKey struct {
186
205
        vtype   string
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
202
221
        }
203
222
        for _, val := range images {
204
223
                im := val.(*ImageMetadata)
205
224
                if cons != nil && cons.Params().Region != "" && cons.Params().Region != im.RegionName {
206
225
                        continue
207
226
                }
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)
210
229
                }
211
230
        }