Merge lp:~sidnei/juju-core/sort-by-cost-lowest-fallback into lp:~go-bot/juju-core/trunk
Proposed by
Sidnei da Silva
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Sidnei da Silva | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 1621 | ||||
Proposed branch: | lp:~sidnei/juju-core/sort-by-cost-lowest-fallback | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
293 lines (+135/-34) 3 files modified
environs/instances/instancetype.go (+18/-2) environs/instances/instancetype_test.go (+117/-31) environs/openstack/image.go (+0/-1) |
||||
To merge this branch: | bzr merge lp:~sidnei/juju-core/sort-by-cost-lowest-fallback | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+179191@code.launchpad.net |
Commit message
Fallback cost sort to mem, cpu-power, cpu-cores
Not all environments provide a cost option, so when computing an appropriate
instance type from provided constraints, use mem, cpu-power and cpu-cores as
fallback options. When any two of them are the same, we fallback to the next
option.
https:/
R=dimitern, rogpeppe
Description of the change
Fallback cost sort to mem, cpu-power, cpu-cores
Not all environments provide a cost option, so when computing an appropriate
instance type from provided constraints, use mem, cpu-power and cpu-cores as
fallback options. When any two of them are the same, we fallback to the next
option.
To post a comment you must log in.
Reviewers: mp+179191_ code.launchpad. net,
Message:
Please take a look.
Description:
Fallback cost sort to mem, cpu-power, cpu-cores
Not all environments provide a cost option, so when computing an
appropriate
instance type from provided constraints, use mem, cpu-power and
cpu-cores as
fallback options. When any two of them are the same, we fallback to the
next
option.
https:/ /code.launchpad .net/~sidnei/ juju-core/ sort-by- cost-lowest- fallback/ +merge/ 179191
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/12569044/
Affected files: instances/ instancetype. go instances/ instancetype_ test.go openstack/ image.go
A [revision details]
M environs/
M environs/
M environs/
Index: [revision details] 20130808095436- ia7cq6t6ybdpo2h f
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: environs/ instances/ instancetype. go instances/ instancetype. go' instances/ instancetype. go 2013-05-20 23:33:29 +0000 instances/ instancetype. go 2013-08-08 13:36:50 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -126,8 +126,27 @@
// byCost is used to sort a slice of instance types by Cost.
type byCost []InstanceType
-func (bc byCost) Len() int { return len(bc) }
-func (bc byCost) Less(i, j int) bool { return bc[i].Cost < bc[j].Cost }
+func (bc byCost) Len() int { return len(bc) }
+func (bc byCost) Less(i, j int) bool {
+ if bc[i].Cost != bc[j].Cost {
+ return bc[i].Cost < bc[j].Cost
+ }
+ if bc[i].Mem != bc[j].Mem {
+ return bc[i].Mem < bc[j].Mem
+ }
+ iCpuPower := uint64(0)
+ jCpuPower := uint64(0)
+ if bc[i].CpuPower != nil {
+ iCpuPower = *bc[i].CpuPower
+ }
+ if bc[j].CpuPower != nil {
+ jCpuPower = *bc[j].CpuPower
+ }
+ if iCpuPower != jCpuPower {
+ return iCpuPower < jCpuPower
+ }
+ return bc[i].CpuCores < bc[j].CpuCores
+}
func (bc byCost) Swap(i, j int) {
bc[i], bc[j] = bc[j], bc[i]
}
Index: environs/ instances/ instancetype_ test.go instances/ instancetype_ test.go' instances/ instancetype_ test.go 2013-05-17 06:34:24 +0000 instances/ instancetype_ test.go 2013-08-08 13:36:50 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -4,6 +4,8 @@
package instances
import ( net/gocheck" net/juju- core/constraint s" net/juju- core/testing"
+ "sort"
+
. "launchpad.
"launchpad.
"launchpad.
@@ -231,3 +233,68 @@
}
}
}
+
+var byCostTest = []struct {
+ info string
+ itypesToUse []InstanceType
+ expectedItypes []string
+}{
+ {
+ info: "default to lowest cost",
+ itypesToUse: []InstanceType{
+ {Id: "2", Name: "it-2", CpuCores: 2, Mem: 4096, Cost: 240},
+ {Id: "1", Name: "it-1", CpuCores: 1, Mem: 2048, Cost: 241},
+ },
+ expectedItypes: []string{
+ "it-2", "it-1",
+ },
+ }, {
+ info: "when no cost associated, pick lowest ram",
+ itypesToUse: []InstanceType{
+ {Id: "2", Name: "it-2", CpuCores: 2, Mem: 4096},
+ {Id: "1", Name: "it-1", CpuCores: 1, Mem: 2048},
+ },
+ expectedItypes: []string{
+ "it-1", "it-2",
+ },
+ }, {
+ info:...