diff --git a/pkg/util/qcloud/instance.go b/pkg/util/qcloud/instance.go index 497fe81c9c..643bd2f722 100644 --- a/pkg/util/qcloud/instance.go +++ b/pkg/util/qcloud/instance.go @@ -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 }