From 86a30141df832aa3397fa373ace1131f1baeaab5 Mon Sep 17 00:00:00 2001 From: TangBin Date: Wed, 27 Nov 2019 14:01:51 +0800 Subject: [PATCH] validate prepaid resource delete condition --- pkg/compute/models/elasticcache_instances.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/compute/models/elasticcache_instances.go b/pkg/compute/models/elasticcache_instances.go index 227abffe47..60da874dcb 100644 --- a/pkg/compute/models/elasticcache_instances.go +++ b/pkg/compute/models/elasticcache_instances.go @@ -19,6 +19,7 @@ import ( "fmt" "regexp" "strings" + "time" "yunion.io/x/jsonutils" "yunion.io/x/log" @@ -697,6 +698,10 @@ func (self *SElasticcache) ValidateDeleteCondition(ctx context.Context) error { return httperrors.NewInvalidStatusError("Elastic cache is locked, cannot delete") } + if self.GetChargeType() == billing.BILLING_TYPE_PREPAID && self.ExpiredAt.Sub(time.Now()).Seconds() > 0 { + return httperrors.NewInvalidStatusError("Elastic cache is not expired, cannot delete") + } + return self.ValidatePurgeCondition(ctx) }