fix(region): support renew kvm vm (#25593)

This commit is contained in:
屈轩
2026-09-08 15:50:11 +08:00
committed by GitHub
parent d6419376fa
commit 705ae5ef5a
6 changed files with 14 additions and 25 deletions

View File

@@ -423,6 +423,8 @@ type AutoRenewInput struct {
}
type RenewInput struct {
// 续费时长
// example: 1d, 1w, 1m
Duration string `json:"duration"`
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}