Skip to content

Commit

Permalink
Merge pull request #18448 from ioito/hotfix/qx-esxi-vm-delete
Browse files Browse the repository at this point in the history
fix(region): 避免esxi vm没有被真正删除
  • Loading branch information
zexi authored Oct 27, 2023
2 parents 00f1f52 + 0da45a1 commit f62ea03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions pkg/compute/guestdrivers/esxi.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,23 @@ func (self *SESXiGuestDriver) SyncOsInfo(ctx context.Context, userCred mcclient.
}
return nil
}

func (drv *SESXiGuestDriver) RequestUndeployGuestOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
iVm, err := guest.GetIVM(ctx)
if err != nil {
if errors.Cause(err) == cloudprovider.ErrNotFound {
return nil, nil
}
return nil, errors.Wrapf(err, "GetIVM")
}

err = iVm.DeleteVM(ctx)
if err != nil {
return nil, errors.Wrapf(err, "DeleteVM")
}

return nil, cloudprovider.WaitDeleted(iVm, time.Second*10, time.Minute*3)
})
return nil
}
4 changes: 2 additions & 2 deletions pkg/compute/models/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5799,7 +5799,7 @@ func (self *SGuest) GetIVM(ctx context.Context) (cloudprovider.ICloudVM, error)
}
iregion, err := host.GetIRegion(ctx)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "GetIRegion")
}
ihost, err := iregion.GetIHostById(host.ExternalId)
if err != nil {
Expand All @@ -5808,7 +5808,7 @@ func (self *SGuest) GetIVM(ctx context.Context) (cloudprovider.ICloudVM, error)
ivm, err := ihost.GetIVMById(self.ExternalId)
if err != nil {
if errors.Cause(err) != cloudprovider.ErrNotFound {
return nil, err
return nil, errors.Wrapf(err, "GetIVMById(%s)", self.ExternalId)
}
return iregion.GetIVMById(self.ExternalId)
}
Expand Down

0 comments on commit f62ea03

Please sign in to comment.