Merge pull request #45 in YUNIONIO/onecloud from ~LIZEXI/onecloud:bugfix/lzx-scheduler-specify-network to release/2.0.0

* commit 'c7656041a5eb21dcf88a3ce930de78552a5a8273':
  修正: 调度器指定网络批量失败的bug
This commit is contained in:
邱剑
2018-08-13 14:59:09 +08:00
+14 -7
View File
@@ -163,15 +163,20 @@ func (c *MinCounters) Add(counter Counter) {
}
func (c *MinCounters) GetCount() int64 {
n := EmptyCapacity
for _, c0 := range c.counters {
if len(c.counters) == 0 {
return EmptyCapacity
}
minCount := c.counters[0].GetCount()
if len(c.counters) == 1 {
return minCount
}
for _, c0 := range c.counters[1:] {
count := c0.GetCount()
if count != EmptyCapacity && count < n {
n = count
if count < minCount {
minCount = count
}
}
return n
return minCount
}
type Capacity struct {
@@ -448,7 +453,9 @@ func (u *Unit) SetCapacity(id string, name string, capacity Counter) error {
// Capacity must >= 0
if !validateCapacityInput(capacity) {
return fmt.Errorf("Capacity invalid: %d", capacity)
err := fmt.Errorf("Capacity counter invalid: %#v, count: %d", capacity, capacity.GetCount())
log.Errorf("SetCapacity error: %v", err)
return err
}
log.V(10).Debugf("%q setCapacity id: %s, capacity: %d", name, id, capacity.GetCount())