fix(region): purge all instance snapshots when purging guest

This commit is contained in:
rainzm
2020-11-23 17:38:22 +08:00
parent e4cd054b74
commit 33a702617f
3 changed files with 20 additions and 0 deletions
+12
View File
@@ -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()
+4
View File
@@ -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) {
+4
View File
@@ -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 {