Automatic merge from release/2.2.0 -> release/2.3.0

* commit 'd267f92e8e5e74ae8da3e5b4e1de8020694e2310':
  避免因snapshot找不到而删除失败
This commit is contained in:
邱剑
2018-11-21 21:52:29 +08:00
3 changed files with 22 additions and 25 deletions
+7 -17
View File
@@ -9,7 +9,6 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/util/compare"
"yunion.io/x/pkg/utils"
"yunion.io/x/sqlchemy"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
@@ -348,29 +347,20 @@ func (self *SSnapshot) CustomizeDelete(ctx context.Context, userCred mcclient.To
if self.Status == SNAPSHOT_DELETING {
return fmt.Errorf("Cannot delete snapshot in status %s", self.Status)
}
if self.Status == SNAPSHOT_UNKNOWN {
return self.RealDelete(ctx, userCred)
}
if len(self.ExternalId) == 0 {
if utils.IsInStringArray(self.Status, []string{SNAPSHOT_FAILED}) {
return self.RealDelete(ctx, userCred)
}
if self.CreatedBy == MANUAL {
if !self.FakeDeleted {
return self.FakeDelete()
} else {
_, err := SnapshotManager.GetConvertSnapshot(self)
if err != nil {
return fmt.Errorf("Cannot delete snapshot: %s, disk need at least one of snapshot as backing file", err.Error())
}
return self.StartSnapshotDeleteTask(ctx, userCred, false, "")
}
} else {
return fmt.Errorf("Cannot delete snapshot created by %s", self.CreatedBy)
_, err := SnapshotManager.GetConvertSnapshot(self)
if err != nil {
return fmt.Errorf("Cannot delete snapshot: %s, disk need at least one of snapshot as backing file", err.Error())
}
return self.StartSnapshotDeleteTask(ctx, userCred, false, "")
}
} else {
return self.StartSnapshotDeleteTask(ctx, userCred, false, "")
return fmt.Errorf("Cannot delete snapshot created by %s", self.CreatedBy)
}
return self.StartSnapshotDeleteTask(ctx, userCred, false, "")
}
func (self *SSnapshot) AllowPerformDeleted(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
@@ -162,12 +162,16 @@ func (self *SnapshotDeleteTask) deleteExternalSnapshot(ctx context.Context, snap
}
cloudSnapshot, err := cloudRegion.GetISnapshotById(snapshot.ExternalId)
if err != nil {
if err == cloudprovider.ErrNotFound {
return nil
}
log.Errorln(err, cloudSnapshot)
return err
}
cloudSnapshot.Delete()
err = cloudprovider.WaitDeleted(cloudSnapshot, 10*time.Second, 300*time.Second)
return err
if err := cloudSnapshot.Delete(); err != nil {
return err
}
return cloudprovider.WaitDeleted(cloudSnapshot, 10*time.Second, 300*time.Second)
}
func (self *SnapshotDeleteTask) StartReloadDisk(ctx context.Context, snapshot *models.SSnapshot, guest *models.SGuest) {
+8 -5
View File
@@ -160,13 +160,16 @@ func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName
}
func (self *SRegion) GetISnapshotById(snapshotId string) (cloudprovider.ICloudSnapshot, error) {
if snapshots, total, err := self.GetSnapshots("", "", "", []string{snapshotId}, 0, 1); err != nil {
snapshots, total, err := self.GetSnapshots("", "", "", []string{snapshotId}, 0, 1)
if err != nil {
return nil, err
} else if total != 1 {
return nil, cloudprovider.ErrNotFound
} else {
return &snapshots[0], nil
}
if total == 0 {
return nil, cloudprovider.ErrNotFound
} else if total > 1 {
return nil, cloudprovider.ErrDuplicateId
}
return &snapshots[0], nil
}
func (self *SRegion) DeleteSnapshot(snapshotId string) error {