mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix isolated device attach
This commit is contained in:
@@ -1578,14 +1578,29 @@ func (self *SGuest) PerformDetachIsolatedDevice(ctx context.Context, userCred mc
|
||||
logclient.AddActionLogWithContext(ctx, self, logclient.ACT_GUEST_DETACH_ISOLATED_DEVICE, msg, userCred, false)
|
||||
return nil, httperrors.NewInvalidStatusError(msg)
|
||||
}
|
||||
device, err := data.GetString("device")
|
||||
if err != nil {
|
||||
msg := "Missing isolated device"
|
||||
logclient.AddActionLogWithContext(ctx, self, logclient.ACT_GUEST_DETACH_ISOLATED_DEVICE, msg, userCred, false)
|
||||
return nil, httperrors.NewBadRequestError(msg)
|
||||
var detachAllDevice = jsonutils.QueryBoolean(data, "detach_all", false)
|
||||
if !detachAllDevice {
|
||||
device, err := data.GetString("device")
|
||||
if err != nil {
|
||||
msg := "Missing isolated device"
|
||||
logclient.AddActionLogWithContext(ctx, self, logclient.ACT_GUEST_DETACH_ISOLATED_DEVICE, msg, userCred, false)
|
||||
return nil, httperrors.NewBadRequestError(msg)
|
||||
}
|
||||
err = self.startDetachIsolateDevice(ctx, userCred, device)
|
||||
return nil, err
|
||||
} else {
|
||||
devs := self.GetIsolatedDevices()
|
||||
host := self.GetHost()
|
||||
lockman.LockObject(ctx, host)
|
||||
defer lockman.ReleaseObject(ctx, host)
|
||||
for i := 0; i < len(devs); i++ {
|
||||
err := self.detachIsolateDevice(ctx, userCred, &devs[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
err = self.startDetachIsolateDevice(ctx, userCred, device)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (self *SGuest) startDetachIsolateDevice(ctx context.Context, userCred mcclient.TokenCredential, device string) error {
|
||||
|
||||
@@ -612,7 +612,7 @@ func (manager *SIsolatedDeviceManager) DeleteDevicesByHost(ctx context.Context,
|
||||
|
||||
func (manager *SIsolatedDeviceManager) GetDevsOnHost(hostId string, model string, count int) ([]SIsolatedDevice, error) {
|
||||
devs := make([]SIsolatedDevice, 0)
|
||||
q := manager.Query().Equals("host_id", hostId).Equals("model", model).IsEmpty("guest_id").Limit(count)
|
||||
q := manager.Query().Equals("host_id", hostId).Equals("model", model).IsNullOrEmpty("guest_id").Limit(count)
|
||||
err := db.FetchModelObjects(manager, q, &devs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user