Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1080)

Unified Diff: environs/instances/image.go

Issue 89900043: Always pick amd64 if it's an option
Patch Set: Always pick amd64 if it's an option Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « [revision details] ('k') | environs/instances/image_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: environs/instances/image.go
=== modified file 'environs/instances/image.go'
--- environs/instances/image.go 2014-03-20 05:03:57 +0000
+++ environs/instances/image.go 2014-04-23 20:36:26 +0000
@@ -8,6 +8,7 @@
"launchpad.net/juju-core/constraints"
"launchpad.net/juju-core/environs/imagemetadata"
+ "launchpad.net/juju-core/juju/arch"
)
// InstanceConstraint constrains the possible instances that may be
@@ -56,14 +57,20 @@
return nil, err
}
+ specs := []*InstanceSpec{}
+
for _, itype := range matchingTypes {
for _, image := range possibleImages {
if image.match(itype) {
- return &InstanceSpec{itype, image}, nil
+ specs = append(specs, &InstanceSpec{itype, image})
}
}
}
+ if spec := preferredSpec(specs); spec != nil {
+ return spec, nil
+ }
+
if len(possibleImages) == 0 || len(matchingTypes) == 0 {
return nil, fmt.Errorf("no %q images in %s with arches %s",
ic.Series, ic.Region, ic.Arches)
@@ -76,6 +83,20 @@
return nil, fmt.Errorf("no %q images in %s matching instance types %v", ic.Series, ic.Region, names)
}
+func preferredSpec(specs []*InstanceSpec) *InstanceSpec {
+ if len(specs) > 1 {
+ for _, spec := range specs {
+ if spec.Image.Arch == arch.HostArch() {
+ return spec
+ }
+ }
+ }
+ if len(specs) > 0 {
+ return specs[0]
+ }
+ return nil
+}
+
// Image holds the attributes that vary amongst relevant images for
// a given series in a given region.
type Image struct {
« no previous file with comments | « [revision details] ('k') | environs/instances/image_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b