Merge pull request #1456 from ioito/bugfix/qx-guest-attach-disk

fix attach disk not effect
This commit is contained in:
yunion-ci-robot
2019-07-01 18:17:52 +08:00
committed by GitHub
6 changed files with 26 additions and 9 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ func (self *SBaseGuestDriver) RequestDetachDisk(ctx context.Context, guest *mode
return nil
}
func (self *SBaseGuestDriver) RequestAttachDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
func (self *SBaseGuestDriver) RequestAttachDisk(ctx context.Context, guest *models.SGuest, disk *models.SDisk, task taskman.ITask) error {
task.ScheduleRun(nil)
return nil
}
+1 -1
View File
@@ -321,7 +321,7 @@ func (self *SKVMGuestDriver) RequestDetachDisk(ctx context.Context, guest *model
return guest.StartSyncTask(ctx, task.GetUserCred(), false, task.GetTaskId())
}
func (self *SKVMGuestDriver) RequestAttachDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
func (self *SKVMGuestDriver) RequestAttachDisk(ctx context.Context, guest *models.SGuest, disk *models.SDisk, task taskman.ITask) error {
return guest.StartSyncTask(ctx, task.GetUserCred(), false, task.GetTaskId())
}
+16 -2
View File
@@ -166,8 +166,22 @@ func (self *SManagedVirtualizedGuestDriver) RequestDetachDisk(ctx context.Contex
return nil
}
func (self *SManagedVirtualizedGuestDriver) RequestAttachDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
return guest.StartSyncTask(ctx, task.GetUserCred(), false, task.GetTaskId())
func (self *SManagedVirtualizedGuestDriver) RequestAttachDisk(ctx context.Context, guest *models.SGuest, disk *models.SDisk, task taskman.ITask) error {
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
iVM, err := guest.GetIVM()
if err != nil {
return nil, errors.Wrapf(err, "guest.GetIVM")
}
if len(disk.ExternalId) == 0 {
return nil, fmt.Errorf("disk %s(%s) is not a managed resource", disk.Name, disk.Id)
}
err = iVM.AttachDisk(ctx, disk.ExternalId)
if err != nil {
return nil, errors.Wrapf(err, "iVM.AttachDisk")
}
return nil, nil
})
return nil
}
func (self *SManagedVirtualizedGuestDriver) RequestStartOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, userCred mcclient.TokenCredential, task taskman.ITask) (jsonutils.JSONObject, error) {
+1 -1
View File
@@ -128,7 +128,7 @@ type IGuestDriver interface {
GetGuestVncInfo(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, host *SHost) (*jsonutils.JSONDict, error)
RequestAttachDisk(ctx context.Context, guest *SGuest, task taskman.ITask) error
RequestAttachDisk(ctx context.Context, guest *SGuest, disk *SDisk, task taskman.ITask) error
RequestDetachDisk(ctx context.Context, guest *SGuest, disk *SDisk, task taskman.ITask) error
GetDetachDiskStatus() ([]string, error)
GetAttachDiskStatus() ([]string, error)
+1 -1
View File
@@ -61,7 +61,7 @@ func (self *GuestAttachDiskTask) OnInit(ctx context.Context, obj db.IStandaloneM
}
disk.SetStatus(self.UserCred, api.DISK_ATTACHING, "Disk attach")
self.SetStage("on_sync_config_complete", nil)
guest.GetDriver().RequestAttachDisk(ctx, guest, self)
guest.GetDriver().RequestAttachDisk(ctx, guest, disk, self)
}
func (self *GuestAttachDiskTask) OnSyncConfigComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
+6 -3
View File
@@ -18,6 +18,8 @@ import (
"context"
"fmt"
"github.com/pkg/errors"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/utils"
@@ -120,7 +122,8 @@ func (self *GuestDetachDiskTask) OnSyncConfigCompleteFailed(ctx context.Context,
diskId, _ := self.Params.GetString("disk_id")
objDisk, err := models.DiskManager.FetchById(diskId)
if err != nil {
self.OnTaskFail(ctx, guest, nil, err)
log.Warningf("failed to fetch disk by id %s error: %v", diskId, err)
self.OnTaskFail(ctx, guest, nil, errors.New(reason.String()))
return
}
disk := objDisk.(*models.SDisk)
@@ -128,9 +131,9 @@ func (self *GuestDetachDiskTask) OnSyncConfigCompleteFailed(ctx context.Context,
disk.SetDiskReady(ctx, self.UserCred, "")
err = guest.AttachDisk(ctx, disk, self.UserCred, driver, cache, mountpoint)
if err != nil {
self.OnTaskFail(ctx, guest, disk, err)
return
log.Warningf("recover attach disk %s(%s) for guest %s(%s) error: %v", disk.Name, disk.Id, guest.Name, guest.Id, err)
}
self.OnTaskFail(ctx, guest, nil, errors.New(reason.String()))
}
func (self *GuestDetachDiskTask) OnTaskFail(ctx context.Context, guest *models.SGuest, disk *models.SDisk, err error) {