mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 09:46:39 +08:00
fix(region): purge all instance snapshots when purging guest
This commit is contained in:
@@ -3726,6 +3726,18 @@ func (self *SGuest) DeleteAllDisksInDB(ctx context.Context, userCred mcclient.To
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuest) DeleteAllInstanceSnapshotInDB(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
isps, err := self.GetInstanceSnapshots()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to GetInstanceSnapshots")
|
||||
}
|
||||
for i := range isps {
|
||||
err = isps[i].RealDelete(ctx, userCred)
|
||||
return errors.Wrapf(err, "unable to real delete instance snapshot %q for guest %q", isps[i].GetName(), self.GetId())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuest) isNeedDoResetPasswd() bool {
|
||||
guestdisks := self.GetDisks()
|
||||
disk := guestdisks[0].GetDisk()
|
||||
|
||||
@@ -359,6 +359,10 @@ func (manager *SInstanceSnapshotManager) CreateInstanceSnapshot(ctx context.Cont
|
||||
return instanceSnapshot, nil
|
||||
}
|
||||
|
||||
var HypervisorIndependentInstanceSnapshot = []string{
|
||||
api.HYPERVISOR_KVM,
|
||||
}
|
||||
|
||||
func (self *SInstanceSnapshot) ToInstanceCreateInput(
|
||||
sourceInput *api.ServerCreateInput) (*api.ServerCreateInput, error) {
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -123,6 +124,9 @@ func (guest *SGuest) purge(ctx context.Context, userCred mcclient.TokenCredentia
|
||||
guest.EjectIso(userCred)
|
||||
guest.DeleteEip(ctx, userCred)
|
||||
guest.DeleteAllDisksInDB(ctx, userCred)
|
||||
if !utils.IsInStringArray(guest.Hypervisor, HypervisorIndependentInstanceSnapshot) {
|
||||
guest.DeleteAllInstanceSnapshotInDB(ctx, userCred)
|
||||
}
|
||||
|
||||
err := guest.ValidatePurgeCondition(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user