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 { |