Skip to content

Commit

Permalink
fix: 避免因磁盘数量导致创建机器失败
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed May 28, 2020
1 parent 6c87cd3 commit caf07c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
12 changes: 6 additions & 6 deletions pkg/compute/guestdrivers/managedvirtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,20 +490,20 @@ func (self *SManagedVirtualizedGuestDriver) RemoteDeployGuestForCreate(ctx conte
return nil, err
}

ret, expect := 0, len(desc.DataDisks)+1
err = cloudprovider.RetryUntil(func() (bool, error) {
idisks, err := iVM.GetIDisks()
if err != nil {
log.Errorf("fail to find vm disks %s after create", err)
return false, err
return false, errors.Wrap(err, "iVM.GetIDisks")
}
if len(idisks) == len(desc.DataDisks)+1 {
ret = len(idisks)
if ret >= expect { // 有可能自定义镜像里面也有磁盘,会导致返回的磁盘多于创建时的磁盘
return true, nil
} else {
return false, nil
}
return false, nil
}, 10)
if err != nil {
return nil, errors.Wrap(err, "GuestDriver.RemoteDeployGuestForCreate.RetryUntil")
return nil, errors.Wrapf(err, "GuestDriver.RemoteDeployGuestForCreate.RetryUntil expect %d disks return %d disks", expect, ret)
}

guest.GetDriver().RemoteActionAfterGuestCreated(ctx, userCred, guest, host, iVM, &desc)
Expand Down
17 changes: 10 additions & 7 deletions pkg/multicloud/aliyun/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,16 @@ func (a byAttachedTime) Less(i, j int) bool {
}

func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
disks, total, err := self.host.zone.region.GetDisks(self.InstanceId, "", "", nil, 0, 50)
if err != nil {
log.Errorf("fetchDisks fail %s", err)
return nil, err
}
if total > len(disks) {
disks, _, err = self.host.zone.region.GetDisks(self.InstanceId, "", "", nil, 0, total)
disks := []SDisk{}
for {
part, total, err := self.host.zone.region.GetDisks(self.InstanceId, "", "", nil, len(disks), 50)
if err != nil {
return nil, errors.Wrapf(err, "GetDisks for %s", self.InstanceId)
}
disks = append(disks, part...)
if len(disks) >= total {
break
}
}

sort.Sort(byAttachedTime(disks))
Expand Down

0 comments on commit caf07c2

Please sign in to comment.