mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(region,host): slvm snapshot delete and instance snapshot purge (#22022)
This commit is contained in:
@@ -59,6 +59,17 @@ func init() {
|
||||
printBatchResults(ret, modules.InstanceSnapshots.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
type InstanceSnapshotPurgeOptions struct {
|
||||
ID string `help:"Delete snapshot id"`
|
||||
}
|
||||
R(&InstanceSnapshotPurgeOptions{}, "instance-snapshot-purge", "Purge snapshots", func(s *mcclient.ClientSession, args *InstanceSnapshotPurgeOptions) error {
|
||||
result, err := modules.InstanceSnapshots.PerformAction(s, args.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type InstanceSnapshotShowOptions struct {
|
||||
ID string `help:"ID or Name of snapshot"`
|
||||
|
||||
@@ -606,6 +606,29 @@ func (self *SInstanceSnapshot) StartInstanceSnapshotDeleteTask(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SInstanceSnapshot) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
snapshots, err := self.GetSnapshots()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range snapshots {
|
||||
snapshotId := snapshots[i].Id
|
||||
isjp := new(SInstanceSnapshotJoint)
|
||||
err = InstanceSnapshotJointManager.Query().
|
||||
Equals("instance_snapshot_id", self.Id).Equals("snapshot_id", snapshotId).First(isjp)
|
||||
err = isjp.Delete(ctx, userCred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "delete instance snapshot joint: %s", snapshotId)
|
||||
}
|
||||
_, err = snapshots[i].PerformPurge(ctx, userCred, query, data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "delete snapshot: %s", snapshotId)
|
||||
}
|
||||
}
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (self *SInstanceSnapshot) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return db.DeleteModel(ctx, userCred, self)
|
||||
}
|
||||
|
||||
@@ -304,10 +304,13 @@ func (d *SSLVMDisk) DeleteSnapshot(snapshotId, convertSnapshot string, blockStre
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "LVActive")
|
||||
}
|
||||
convertSnapshotPath := d.GetSnapshotPath(convertSnapshot)
|
||||
err = lvmutils.LVActive(convertSnapshotPath, false, d.Storage.Lvmlockd())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "LVActive convert snapshot")
|
||||
var convertSnapshotPath string
|
||||
if len(convertSnapshot) > 0 {
|
||||
convertSnapshotPath = d.GetSnapshotPath(convertSnapshot)
|
||||
err = lvmutils.LVActive(convertSnapshotPath, false, d.Storage.Lvmlockd())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "LVActive convert snapshot")
|
||||
}
|
||||
}
|
||||
|
||||
err = d.SLVMDisk.DeleteSnapshot(snapshotId, convertSnapshot, blockStream, encryptInfo)
|
||||
@@ -316,9 +319,12 @@ func (d *SSLVMDisk) DeleteSnapshot(snapshotId, convertSnapshot string, blockStre
|
||||
if e != nil {
|
||||
log.Errorf("failed active with share mode: %s", e)
|
||||
}
|
||||
e = lvmutils.LVActive(convertSnapshotPath, d.Storage.Lvmlockd(), false)
|
||||
if e != nil {
|
||||
log.Errorf("failed active convert snapshot %s with share mode: %s", convertSnapshotPath, e)
|
||||
if len(convertSnapshot) > 0 {
|
||||
e = lvmutils.LVActive(convertSnapshotPath, d.Storage.Lvmlockd(), false)
|
||||
if e != nil {
|
||||
log.Errorf("failed active convert snapshot %s with share mode: %s", convertSnapshotPath, e)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user