fix: validate host status before doing renew prepaid recycle

This commit is contained in:
Qiu Jian
2019-03-08 00:01:14 +08:00
parent 9339bee71c
commit d23414f3f6
+9
View File
@@ -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")