fix isolated device attach

This commit is contained in:
wanyaoqi
2019-11-05 14:35:18 +08:00
parent 1493abfe86
commit bf13fa2410
2 changed files with 23 additions and 8 deletions
+22 -7
View File
@@ -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 {
+1 -1
View File
@@ -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