Merge pull request #597 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-conflict-resolve-2.4.0 to release/2.4.0

* commit '39bde25db5c1102d9b2462406bebfae3b91fbd9c':
  删除虚拟机时避免无限循环
This commit is contained in:
邱剑
2018-11-29 12:25:18 +08:00
+7 -13
View File
@@ -5,6 +5,7 @@ import (
"time"
"context"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/cloudprovider"
@@ -528,9 +529,12 @@ func (self *SRegion) StopVM(instanceId string, isForce bool) error {
return self.doStopVM(instanceId, isForce)
}
func (self *SRegion) DeleteVM(ctx context.Context, instanceId string) error {
func (self *SRegion) DeleteVM(instanceId string) error {
status, err := self.GetInstanceStatus(instanceId)
if err != nil {
if err == cloudprovider.ErrNotFound {
return nil
}
log.Errorf("Fail to get instance status on DeleteVM: %s", err)
return err
}
@@ -583,18 +587,8 @@ func (self *SRegion) DeployVM(instanceId string, name string, password string, k
}
func (self *SInstance) DeleteVM(ctx context.Context) error {
for {
err := self.host.zone.region.DeleteVM(ctx, self.InstanceId)
if err != nil {
// if isError(err, "IncorrectInstanceStatus.Initializing") {
// log.Infof("The instance is initializing, try later ...")
// time.Sleep(10 * time.Second)
// } else {
// return err
// }
} else {
break
}
if err := self.host.zone.region.DeleteVM(self.InstanceId); err != nil {
return err
}
return cloudprovider.WaitDeleted(self, 10*time.Second, 300*time.Second) // 5minutes
}