mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(region): support renew kvm vm (#25593)
This commit is contained in:
@@ -423,6 +423,8 @@ type AutoRenewInput struct {
|
||||
}
|
||||
|
||||
type RenewInput struct {
|
||||
// 续费时长
|
||||
// example: 1d, 1w, 1m
|
||||
Duration string `json:"duration"`
|
||||
}
|
||||
|
||||
|
||||
@@ -317,7 +317,7 @@ func (drv *SBaseGuestDriver) IsSupportShutdownMode() bool {
|
||||
}
|
||||
|
||||
func (drv *SBaseGuestDriver) RequestRenewInstance(ctx context.Context, guest *models.SGuest, bc billing.SBillingCycle) (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
return bc.EndAt(guest.GetExpiredAt()), nil
|
||||
}
|
||||
|
||||
func (drv *SBaseGuestDriver) IsSupportEip() bool {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/billing"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
@@ -574,10 +573,6 @@ func (self *SCloudpodsESXiGuestDriver) DoGuestCreateDisksTask(ctx context.Contex
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudpodsESXiGuestDriver) RequestRenewInstance(ctx context.Context, guest *models.SGuest, bc billing.SBillingCycle) (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
|
||||
func (self *SCloudpodsESXiGuestDriver) IsSupportEip() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/billing"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
@@ -587,10 +586,6 @@ func (self *SESXiGuestDriver) DoGuestCreateDisksTask(ctx context.Context, guest
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) RequestRenewInstance(ctx context.Context, guest *models.SGuest, bc billing.SBillingCycle) (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) IsSupportEip() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -17,10 +17,8 @@ package guestdrivers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/pkg/util/billing"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
@@ -165,10 +163,6 @@ func (self *SNutanixGuestDriver) AllowReconfigGuest() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SNutanixGuestDriver) RequestRenewInstance(ctx context.Context, guest *models.SGuest, bc billing.SBillingCycle) (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
|
||||
func (self *SNutanixGuestDriver) IsSupportEip() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -4967,15 +4967,18 @@ func (self *SGuest) PerformPostpaidExpire(ctx context.Context, userCred mcclient
|
||||
}
|
||||
|
||||
// 续费
|
||||
func (self *SGuest) PerformRenew(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
durationStr, _ := data.GetString("duration")
|
||||
if len(durationStr) == 0 {
|
||||
return nil, httperrors.NewInputParameterError("missong duration")
|
||||
func (self *SGuest) PerformRenew(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.RenewInput) (jsonutils.JSONObject, error) {
|
||||
if self.BillingType != billing_api.BILLING_TYPE_PREPAID {
|
||||
return nil, httperrors.NewUnsupportOperationError("Only %s guest support renew operation", billing_api.BILLING_TYPE_PREPAID)
|
||||
}
|
||||
|
||||
bc, err := billing.ParseBillingCycle(durationStr)
|
||||
if len(input.Duration) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("duration")
|
||||
}
|
||||
|
||||
bc, err := billing.ParseBillingCycle(input.Duration)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s: %s", durationStr, err)
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s: %s", input.Duration, err)
|
||||
}
|
||||
|
||||
driver, err := self.GetDriver()
|
||||
@@ -4984,10 +4987,10 @@ func (self *SGuest) PerformRenew(ctx context.Context, userCred mcclient.TokenCre
|
||||
}
|
||||
|
||||
if !driver.IsSupportedBillingCycle(bc) {
|
||||
return nil, httperrors.NewInputParameterError("unsupported duration %s", durationStr)
|
||||
return nil, httperrors.NewInputParameterError("unsupported duration %s", input.Duration)
|
||||
}
|
||||
|
||||
err = self.startGuestRenewTask(ctx, userCred, durationStr, "")
|
||||
err = self.startGuestRenewTask(ctx, userCred, input.Duration, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user