mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(host): not purge isolated device when detaching it (#22224)
This commit is contained in:
@@ -26,4 +26,5 @@ func init() {
|
||||
cmd.Update(&compute.DeviceUpdateOptions{})
|
||||
cmd.Show(&compute.DeviceShowOptions{})
|
||||
cmd.BatchDelete(&compute.DeviceDeleteOptions{})
|
||||
cmd.BatchPerform("purge", &compute.DevicePurgeOptions{})
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrMsgIsolatedDeviceUsedByServer = "Isolated device used by server"
|
||||
)
|
||||
|
||||
type IsolateDeviceDetails struct {
|
||||
apis.StandaloneResourceDetails
|
||||
HostResourceInfo
|
||||
|
||||
@@ -948,7 +948,7 @@ func (self *SIsolatedDevice) PerformPurge(ctx context.Context, userCred mcclient
|
||||
func (self *SIsolatedDevice) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
if len(self.GuestId) > 0 {
|
||||
if !jsonutils.QueryBoolean(data, "purge", false) {
|
||||
return httperrors.NewBadRequestError("Isolated device used by server: %s", self.GuestId)
|
||||
return httperrors.NewBadRequestError("%s: %s", api.ErrMsgIsolatedDeviceUsedByServer, self.GuestId)
|
||||
}
|
||||
iGuest, err := GuestManager.FetchById(self.GuestId)
|
||||
if err != nil {
|
||||
|
||||
@@ -402,11 +402,15 @@ func (man *isolatedDeviceManager) StartDetachTask() {
|
||||
log.Infof("Start delete cloud device %s", jsonutils.Marshal(dev))
|
||||
if _, err := modules.IsolatedDevices.PerformAction(man.getSession(), dev.Id, "purge",
|
||||
jsonutils.Marshal(map[string]interface{}{
|
||||
"purge": true,
|
||||
//"purge": true,
|
||||
})); err != nil {
|
||||
if errors.Cause(err) == httperrors.ErrResourceNotFound {
|
||||
break
|
||||
}
|
||||
if strings.Contains(err.Error(), api.ErrMsgIsolatedDeviceUsedByServer) {
|
||||
log.Warningf("Purge isolated device %s failed: %v", jsonutils.Marshal(dev), err)
|
||||
break
|
||||
}
|
||||
log.Errorf("Detach device %s failed: %v, try again later", dev.Id, err)
|
||||
time.Sleep(30 * time.Second)
|
||||
continue
|
||||
|
||||
@@ -61,3 +61,14 @@ type DeviceUpdateOptions struct {
|
||||
func (o *DeviceUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(o), nil
|
||||
}
|
||||
|
||||
type DevicePurgeOptions struct {
|
||||
options.BaseIdsOptions
|
||||
Purge bool `help:"purge devices when attached to guest"`
|
||||
}
|
||||
|
||||
func (o *DevicePurgeOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(map[string]interface{}{
|
||||
"purge": o.Purge,
|
||||
}), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user