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

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/environs/tools/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:
13
13
        "hash"
14
14
        "io"
15
15
        "path"
 
16
        "sort"
16
17
        "strings"
17
18
        "time"
18
19
 
102
103
}
103
104
 
104
105
// NewVersionedToolsConstraint returns a ToolsConstraint for a tools with a specific version.
105
 
func NewVersionedToolsConstraint(vers string, params simplestreams.LookupParams) *ToolsConstraint {
106
 
        versNum := version.MustParse(vers)
107
 
        return &ToolsConstraint{LookupParams: params, Version: versNum}
 
106
func NewVersionedToolsConstraint(vers version.Number, params simplestreams.LookupParams) *ToolsConstraint {
 
107
        return &ToolsConstraint{LookupParams: params, Version: vers}
108
108
}
109
109
 
110
110
// NewGeneralToolsConstraint returns a ToolsConstraint for tools with matching major/minor version numbers.
168
168
// The base URL locations are as specified - the first location which has a file is the one used.
169
169
// Signed data is preferred, but if there is no signed data available and onlySigned is false,
170
170
// then unsigned data is used.
171
 
func Fetch(sources []simplestreams.DataSource, indexPath string, cons *ToolsConstraint, onlySigned bool) ([]*ToolsMetadata, error) {
 
171
func Fetch(
 
172
        sources []simplestreams.DataSource, indexPath string, cons *ToolsConstraint,
 
173
        onlySigned bool) ([]*ToolsMetadata, *simplestreams.ResolveInfo, error) {
 
174
 
172
175
        params := simplestreams.ValueParams{
173
176
                DataType:        ContentDownload,
174
177
                FilterFunc:      appendMatchingTools,
176
179
                ValueTemplate:   ToolsMetadata{},
177
180
                PublicKey:       simplestreamsToolsPublicKey,
178
181
        }
179
 
        items, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
 
182
        items, resolveInfo, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
180
183
        if err != nil {
181
 
                return nil, err
 
184
                return nil, nil, err
182
185
        }
183
186
        metadata := make([]*ToolsMetadata, len(items))
184
187
        for i, md := range items {
185
188
                metadata[i] = md.(*ToolsMetadata)
186
189
        }
187
 
        return metadata, nil
188
 
}
 
190
        // Sorting the metadata is not strictly necessary, but it ensures consistent ordering for
 
191
        // all compilers, and it just makes it easier to look at the data.
 
192
        Sort(metadata)
 
193
        return metadata, resolveInfo, nil
 
194
}
 
195
 
 
196
// Sort sorts a slice of ToolsMetadata in ascending order of their version
 
197
// in order to ensure the results of Fetch are ordered deterministically.
 
198
func Sort(metadata []*ToolsMetadata) {
 
199
        sort.Sort(byVersion(metadata))
 
200
}
 
201
 
 
202
type byVersion []*ToolsMetadata
 
203
 
 
204
func (b byVersion) Len() int           { return len(b) }
 
205
func (b byVersion) Swap(i, j int)      { b[i], b[j] = b[j], b[i] }
 
206
func (b byVersion) Less(i, j int) bool { return b[i].binary().String() < b[j].binary().String() }
189
207
 
190
208
// appendMatchingTools updates matchingTools with tools metadata records from tools which belong to the
191
209
// specified series. If a tools record already exists in matchingTools, it is not overwritten.
306
324
        for _, metadata := range merged {
307
325
                list = append(list, metadata)
308
326
        }
 
327
        Sort(list)
309
328
        return list, nil
310
329
}
311
330
 
312
331
// ReadMetadata returns the tools metadata from the given storage.
313
332
func ReadMetadata(store storage.StorageReader) ([]*ToolsMetadata, error) {
314
 
        dataSource := storage.NewStorageSimpleStreamsDataSource(store, storage.BaseToolsPath)
 
333
        dataSource := storage.NewStorageSimpleStreamsDataSource("existing metadata", store, storage.BaseToolsPath)
315
334
        toolsConstraint, err := makeToolsConstraint(simplestreams.CloudSpec{}, -1, -1, coretools.Filter{})
316
335
        if err != nil {
317
336
                return nil, err
318
337
        }
319
 
        metadata, err := Fetch([]simplestreams.DataSource{dataSource}, simplestreams.DefaultIndexPath, toolsConstraint, false)
 
338
        metadata, _, err := Fetch(
 
339
                []simplestreams.DataSource{dataSource}, simplestreams.DefaultIndexPath, toolsConstraint, false)
320
340
        if err != nil && !errors.IsNotFoundError(err) {
321
341
                return nil, err
322
342
        }