From 705ae5ef5a3cab0c70d6ed4667bb1442ecf55f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Tue, 8 Sep 2026 15:50:11 +0800 Subject: [PATCH] fix(region): support renew kvm vm (#25593) --- pkg/apis/input.go | 2 ++ pkg/compute/guestdrivers/base.go | 2 +- pkg/compute/guestdrivers/cloudpods-esxi.go | 5 ----- pkg/compute/guestdrivers/esxi.go | 5 ----- pkg/compute/guestdrivers/nutanix.go | 6 ------ pkg/compute/models/guest_actions.go | 19 +++++++++++-------- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/pkg/apis/input.go b/pkg/apis/input.go index ec71ac03f6..5201a44c2c 100644 --- a/pkg/apis/input.go +++ b/pkg/apis/input.go @@ -423,6 +423,8 @@ type AutoRenewInput struct { } type RenewInput struct { + // 续费时长 + // example: 1d, 1w, 1m Duration string `json:"duration"` } diff --git a/pkg/compute/guestdrivers/base.go b/pkg/compute/guestdrivers/base.go index f1ac156bc4..a2b339a086 100644 --- a/pkg/compute/guestdrivers/base.go +++ b/pkg/compute/guestdrivers/base.go @@ -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 { diff --git a/pkg/compute/guestdrivers/cloudpods-esxi.go b/pkg/compute/guestdrivers/cloudpods-esxi.go index 8c5bc0dc57..42bf3b78dc 100644 --- a/pkg/compute/guestdrivers/cloudpods-esxi.go +++ b/pkg/compute/guestdrivers/cloudpods-esxi.go @@ -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 } diff --git a/pkg/compute/guestdrivers/esxi.go b/pkg/compute/guestdrivers/esxi.go index 958f5f153a..c033036591 100644 --- a/pkg/compute/guestdrivers/esxi.go +++ b/pkg/compute/guestdrivers/esxi.go @@ -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 } diff --git a/pkg/compute/guestdrivers/nutanix.go b/pkg/compute/guestdrivers/nutanix.go index 266d4d9ab3..4d5a839f34 100644 --- a/pkg/compute/guestdrivers/nutanix.go +++ b/pkg/compute/guestdrivers/nutanix.go @@ -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 } diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 79f1484f29..f9af646648 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -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 }