mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #2461 from wanyaoqi/bugfix/wyq/fix-snapshot-delete
bugfix: fix snapshot can't delete
This commit is contained in:
@@ -96,6 +96,7 @@ type IRegionDriver interface {
|
||||
OnDiskReset(ctx context.Context, userCred mcclient.TokenCredential, disk *SDisk, snapshot *SSnapshot, data jsonutils.JSONObject) error
|
||||
RequestApplySnapshotPolicy(ctx context.Context, userCred mcclient.TokenCredential, sp *SSnapshotPolicy, task taskman.ITask, diskId string) error
|
||||
RequestCancelSnapshotPolicy(ctx context.Context, userCred mcclient.TokenCredential, sp *SSnapshotPolicy, task taskman.ITask, diskId string) error
|
||||
OnSnapshotDelete(ctx context.Context, snapshot *SSnapshot, task taskman.ITask) error
|
||||
}
|
||||
|
||||
var regionDrivers map[string]IRegionDriver
|
||||
|
||||
@@ -195,3 +195,7 @@ func (self *SBaseRegionDriver) OnDiskReset(ctx context.Context, userCred mcclien
|
||||
func (self *SBaseRegionDriver) ValidateCreateSnapshopolicyDiskData(ctx context.Context, userCred mcclient.TokenCredential, diskID string) error {
|
||||
return fmt.Errorf("Not Implement ValidateCreateSnapshotpolicyDiskData")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) OnSnapshotDelete(ctx context.Context, snapshot *models.SSnapshot, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not implement OnSnapshotDelete")
|
||||
}
|
||||
|
||||
@@ -808,3 +808,9 @@ func (self *SKVMRegionDriver) RequestCancelSnapshotPolicy(ctx context.Context, u
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) OnSnapshotDelete(ctx context.Context, snapshot *models.SSnapshot, task taskman.ITask) error {
|
||||
task.SetStage("OnKvmSnapshotDelete", nil)
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1123,23 +1123,27 @@ func (self *SManagedVirtualizationRegionDriver) ValidateSnapshotDelete(ctx conte
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteSnapshot(ctx context.Context, snapshot *models.SSnapshot, task taskman.ITask) error {
|
||||
cloudRegion, err := snapshot.GetISnapshotRegion()
|
||||
if err != nil {
|
||||
log.Errorln(err, cloudRegion, snapshot.CloudregionId)
|
||||
return err
|
||||
}
|
||||
cloudSnapshot, err := cloudRegion.GetISnapshotById(snapshot.ExternalId)
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNotFound {
|
||||
return nil
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
cloudRegion, err := snapshot.GetISnapshotRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Errorln(err, cloudSnapshot)
|
||||
return err
|
||||
}
|
||||
if err := cloudSnapshot.Delete(); err != nil {
|
||||
return err
|
||||
}
|
||||
return cloudprovider.WaitDeleted(cloudSnapshot, 10*time.Second, 300*time.Second)
|
||||
cloudSnapshot, err := cloudRegion.GetISnapshotById(snapshot.ExternalId)
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if err := cloudSnapshot.Delete(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := cloudprovider.WaitDeleted(cloudSnapshot, 10*time.Second, 300*time.Second); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateSnapshotCreate(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, data *jsonutils.JSONDict) error {
|
||||
@@ -1222,3 +1226,9 @@ func (self *SManagedVirtualizationRegionDriver) ValidateCreateSnapshotPolicyData
|
||||
input.CloudregionId = cloudregion.GetId()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) OnSnapshotDelete(ctx context.Context, snapshot *models.SSnapshot, task taskman.ITask) error {
|
||||
task.SetStage("OnManagedSnapshotDelete", nil)
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -43,18 +43,25 @@ func (self *SnapshotDeleteTask) OnRequestSnapshotFailed(ctx context.Context, sna
|
||||
}
|
||||
|
||||
func (self *SnapshotDeleteTask) OnRequestSnapshot(ctx context.Context, snapshot *models.SSnapshot, data jsonutils.JSONObject) {
|
||||
if len(snapshot.ExternalId) > 0 {
|
||||
snapshot.RealDelete(ctx, self.GetUserCred())
|
||||
self.TaskComplete(ctx, snapshot, nil)
|
||||
err := snapshot.GetRegionDriver().OnSnapshotDelete(ctx, snapshot, self)
|
||||
if err != nil {
|
||||
self.TaskFailed(ctx, snapshot, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SnapshotDeleteTask) OnManagedSnapshotDelete(ctx context.Context, snapshot *models.SSnapshot, data jsonutils.JSONObject) {
|
||||
snapshot.RealDelete(ctx, self.GetUserCred())
|
||||
self.TaskComplete(ctx, snapshot, nil)
|
||||
}
|
||||
|
||||
func (self *SnapshotDeleteTask) OnKvmSnapshotDelete(ctx context.Context, snapshot *models.SSnapshot, data jsonutils.JSONObject) {
|
||||
snapshot.SetStatus(self.UserCred, api.SNAPSHOT_READY, "")
|
||||
if jsonutils.QueryBoolean(self.Params, "reload_disk", false) && snapshot.OutOfChain {
|
||||
self.SetStage("OnReloadDiskSnapshot", nil)
|
||||
self.OnReloadDiskSnapshot(ctx, snapshot, data)
|
||||
} else {
|
||||
snapshot.SetStatus(self.UserCred, api.SNAPSHOT_READY, "")
|
||||
if jsonutils.QueryBoolean(self.Params, "reload_disk", false) && snapshot.OutOfChain {
|
||||
self.SetStage("OnReloadDiskSnapshot", nil)
|
||||
self.OnReloadDiskSnapshot(ctx, snapshot, data)
|
||||
} else {
|
||||
self.SetStage("OnDeleteSnapshot", nil)
|
||||
self.OnDeleteSnapshot(ctx, snapshot, data)
|
||||
}
|
||||
self.SetStage("OnDeleteSnapshot", nil)
|
||||
self.OnDeleteSnapshot(ctx, snapshot, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user