diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 9c131c1e1b..ae47a61902 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1839,6 +1839,11 @@ func (self *SGuest) syncRemoveCloudVM(ctx context.Context, userCred mcclient.Tok return nil } + if options.SyncPurgeRemovedResources.Contains(self.Keyword()) { + log.Debugf("purge removed resource %s", self.Name) + return self.purge(ctx, userCred) + } + if !lostNamePattern.MatchString(self.Name) { db.Update(self, func() error { self.Name = fmt.Sprintf("%s-lost@%s", self.Name, timeutils.ShortDate(time.Now())) diff --git a/pkg/compute/options/namesync.go b/pkg/compute/options/namesync.go index a7945bd0a8..10bfdc1bf6 100644 --- a/pkg/compute/options/namesync.go +++ b/pkg/compute/options/namesync.go @@ -8,9 +8,14 @@ import ( var ( NameSyncResources stringutils2.SSortedStrings + + SyncPurgeRemovedResources stringutils2.SSortedStrings ) func InitNameSyncResources() { NameSyncResources = stringutils2.NewSortedStrings(Options.NameSyncResources) log.Infof("NameSyncResources: %s", NameSyncResources) + + SyncPurgeRemovedResources = stringutils2.NewSortedStrings(Options.SyncPurgeRemovedResources) + log.Infof("SyncPurgeRemovedResources: %s", SyncPurgeRemovedResources) } diff --git a/pkg/compute/options/options.go b/pkg/compute/options/options.go index 6792a0cfe9..114f7600c4 100644 --- a/pkg/compute/options/options.go +++ b/pkg/compute/options/options.go @@ -101,6 +101,8 @@ type ComputeOptions struct { NameSyncResources []string `help:"resources that need synchronization of name"` + SyncPurgeRemovedResources []string `help:"resources that shoud be purged immediately if found removed"` + DisconnectedCloudAccountRetryProbeIntervalHours int `help:"interval to wait to probe status of a disconnected cloud account" default:"24"` SCapabilityOptions