From d23414f3f6ba8cd21e04352500d2566c86af8eaa Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Fri, 8 Mar 2019 00:01:14 +0800 Subject: [PATCH 1/2] fix: validate host status before doing renew prepaid recycle --- pkg/compute/models/host_recycle.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/compute/models/host_recycle.go b/pkg/compute/models/host_recycle.go index ad44d1a900..eeece5362c 100644 --- a/pkg/compute/models/host_recycle.go +++ b/pkg/compute/models/host_recycle.go @@ -688,6 +688,15 @@ func (self *SHost) AllowPerformRenewPrepaidRecycle(ctx context.Context, userCred } func (self *SHost) PerformRenewPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { + if !self.IsPrepaidRecycle() { + return nil, httperrors.NewInputParameterError("Not a prepaid recycle host") + } + if len(self.RealExternalId) == 0 { + return nil, httperrors.NewGeneralError(fmt.Errorf("host RealExternalId is empty")) + } + if len(self.ExternalId) == 0 { + return nil, httperrors.NewGeneralError(fmt.Errorf("host ExternalId is empty")) + } durationStr := jsonutils.GetAnyString(data, []string{"duration"}) if len(durationStr) == 0 { return nil, httperrors.NewInputParameterError("missing duration") From e62ceb5007e57d71e4f049640528b91a20ae86f6 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Fri, 8 Mar 2019 00:09:48 +0800 Subject: [PATCH 2/2] show expired_at colume for host --- pkg/mcclient/modules/mod_hosts.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/mcclient/modules/mod_hosts.go b/pkg/mcclient/modules/mod_hosts.go index f3f69078a4..4fddee1706 100644 --- a/pkg/mcclient/modules/mod_hosts.go +++ b/pkg/mcclient/modules/mod_hosts.go @@ -177,7 +177,9 @@ func init() { "mem_commit_rate", "cpu_commit_bound", "mem_commit_bound", "node_count", "sn", "storage_type", "host_type", "version", "schedtags", - "storage_size"}, + "storage_size", + "expired_at", + }, []string{})} registerCompute(&Hosts) }