mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(region): change disk billing type (#22532)
This commit is contained in:
@@ -46,6 +46,7 @@ func init() {
|
||||
cmd.Perform("rebuild", &compute_options.DiskRebuildOptions{})
|
||||
cmd.Perform("migrate", &compute_options.DiskMigrateOptions{})
|
||||
cmd.Perform("reset-template", &compute_options.DiskResetTemplateOptions{})
|
||||
cmd.Perform("change-billing-type", new(compute_options.DiskChangeBillingTypeOptions))
|
||||
|
||||
type DiskDetailOptions struct {
|
||||
ID string `help:"ID or Name of disk"`
|
||||
|
||||
@@ -93,14 +93,14 @@ require (
|
||||
k8s.io/cri-api v0.22.17
|
||||
k8s.io/klog/v2 v2.20.0
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250512085204-4c8552cf788d
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250515020430-3c80e4f0c134
|
||||
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256
|
||||
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
|
||||
yunion.io/x/pkg v1.10.4-0.20250403114914-586e94d39281
|
||||
yunion.io/x/pkg v1.10.4-0.20250513085810-efeaaca81a0e
|
||||
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250507115529-f74b83fda63b
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250513031856-ce9f71063b3a
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
|
||||
)
|
||||
|
||||
|
||||
@@ -1376,8 +1376,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250512085204-4c8552cf788d h1:3ofa2X04MnwqHnrGV6bc6nivoU7n4/fi9ckQgTWHXyQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250512085204-4c8552cf788d/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250515020430-3c80e4f0c134 h1:JbyK6805VYmJg426R/4P8WHsPARBhgWCcrnF/bZYIeg=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250515020430-3c80e4f0c134/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
|
||||
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256 h1:kLKQ6zbgPDQflRwoHFAjxNChcbhXIFgsUVLkJwiXu/8=
|
||||
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
@@ -1391,11 +1391,11 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v1.10.4-0.20250403114914-586e94d39281 h1:P22/MaBc9bqE9DyHvS3oQjc4XsaIEbIVGMLdTSroDew=
|
||||
yunion.io/x/pkg v1.10.4-0.20250403114914-586e94d39281/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
|
||||
yunion.io/x/pkg v1.10.4-0.20250513085810-efeaaca81a0e h1:OiBxJR18bq5fFK/IZWYRX+5HTMs2KgQJe0a3BZfdIVU=
|
||||
yunion.io/x/pkg v1.10.4-0.20250513085810-efeaaca81a0e/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
|
||||
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1 h1:1KJ3YYinydPHpDEQRXdr/T8SYcKZ5Er+m489H+PnaQ4=
|
||||
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250507115529-f74b83fda63b h1:VDSvBxXEcrac4pw9+fHP17XXPZNgHzkUPxtGDNx518M=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250507115529-f74b83fda63b/go.mod h1:vCIZpqhZ5Jzaq3tFyrti/vv8BijQKtkzSgNT/uH4H5A=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250513031856-ce9f71063b3a h1:mDW1VyYJxZ4ORITZGDWacUiBNyqX6rMObnQk77NvUOg=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20250513031856-ce9f71063b3a/go.mod h1:vCIZpqhZ5Jzaq3tFyrti/vv8BijQKtkzSgNT/uH4H5A=
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c h1:QuLab2kSRECZRxo4Lo2KcYn6XjQFDGaZ1+x0pYDVVwQ=
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
|
||||
|
||||
@@ -376,3 +376,11 @@ func (d *DiskFsFeatures) IsZero() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type DiskChangeBillingTypeInput struct {
|
||||
// 仅在磁盘挂载在虚拟机上时调用
|
||||
// 目前支持阿里云
|
||||
// enmu: [postpaid, prepaid]
|
||||
// required: true
|
||||
BillingType string `json:"billing_type"`
|
||||
}
|
||||
|
||||
@@ -180,10 +180,6 @@ const (
|
||||
VM_QGA_SET_NETWORK = "qga_set_network"
|
||||
VM_QGA_SET_NETWORK_FAILED = "qga_set_network_failed"
|
||||
|
||||
// 更改计费模式
|
||||
VM_CHANGE_BILLING_TYPE = "change_billing_type"
|
||||
VM_CHANGE_BILLING_TYPE_FAILED = "change_billing_type_failed"
|
||||
|
||||
SHUTDOWN_STOP = "stop"
|
||||
SHUTDOWN_TERMINATE = "terminate"
|
||||
SHUTDOWN_STOP_RELEASE_GPU = "stop_release_gpu"
|
||||
|
||||
@@ -58,6 +58,10 @@ const (
|
||||
STATUS_AVAILABLE = "available"
|
||||
STATUS_CREATE_FAILED = "create_failed"
|
||||
|
||||
// 更改计费模式
|
||||
STATUS_CHANGE_BILLING_TYPE = "change_billing_type"
|
||||
STATUS_CHANGE_BILLING_TYPE_FAILED = "change_billing_type_failed"
|
||||
|
||||
CLOUD_TAG_PREFIX = "ext:"
|
||||
USER_TAG_PREFIX = "user:"
|
||||
SYS_CLOUD_TAG_PREFIX = "sys:"
|
||||
|
||||
@@ -484,7 +484,7 @@ func (drv *SManagedVirtualizedGuestDriver) RequestStartOnHost(ctx context.Contex
|
||||
if guest.BillingType == billing_api.BILLING_TYPE_POSTPAID && jsonutils.QueryBoolean(task.GetParams(), "auto_prepaid", false) {
|
||||
err = ivm.ChangeBillingType(billing_api.BILLING_TYPE_PREPAID)
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented {
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_VM_CHANGE_BILLING_TYPE, errors.Wrapf(err, billing_api.BILLING_TYPE_PREPAID), userCred, false)
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_CHANGE_BILLING_TYPE, errors.Wrapf(err, billing_api.BILLING_TYPE_PREPAID), userCred, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,7 +985,7 @@ func (drv *SManagedVirtualizedGuestDriver) RequestStopOnHost(ctx context.Context
|
||||
if opts.StopCharging && guest.BillingType == billing_api.BILLING_TYPE_PREPAID {
|
||||
err = ivm.ChangeBillingType(billing_api.BILLING_TYPE_POSTPAID)
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented {
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_VM_CHANGE_BILLING_TYPE, errors.Wrapf(err, billing_api.BILLING_TYPE_POSTPAID), task.GetUserCred(), false)
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_CHANGE_BILLING_TYPE, errors.Wrapf(err, billing_api.BILLING_TYPE_POSTPAID), task.GetUserCred(), false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3339,3 +3339,29 @@ func (disk *SDisk) resetDiskinfo(
|
||||
db.OpsLog.LogEvent(disk, db.ACT_UPDATE, notes, userCred)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (disk *SDisk) PerformChangeBillingType(ctx context.Context, userCred mcclient.TokenCredential, _ jsonutils.JSONObject, input *api.DiskChangeBillingTypeInput) (jsonutils.JSONObject, error) {
|
||||
if !utils.IsInStringArray(disk.Status, []string{api.DISK_READY}) {
|
||||
return nil, httperrors.NewServerStatusError("Cannot change disk billing type in status %s", disk.Status)
|
||||
}
|
||||
if len(input.BillingType) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("billing_type")
|
||||
}
|
||||
if !utils.IsInStringArray(input.BillingType, []string{billing_api.BILLING_TYPE_POSTPAID, billing_api.BILLING_TYPE_PREPAID}) {
|
||||
return nil, httperrors.NewInputParameterError("invalid billing_type %s", input.BillingType)
|
||||
}
|
||||
if disk.BillingType == input.BillingType {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, disk.StartChangeBillingTypeTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (disk *SDisk) StartChangeBillingTypeTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
disk.SetStatus(ctx, userCred, apis.STATUS_CHANGE_BILLING_TYPE, "")
|
||||
kwargs := jsonutils.NewDict()
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "DiskChangeBillingTypeTask", disk, userCred, kwargs, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
@@ -6757,7 +6757,7 @@ func (g *SGuest) PerformChangeBillingType(ctx context.Context, userCred mcclient
|
||||
}
|
||||
|
||||
func (self *SGuest) StartChangeBillingTypeTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
self.SetStatus(ctx, userCred, api.VM_CHANGE_BILLING_TYPE, "")
|
||||
self.SetStatus(ctx, userCred, apis.STATUS_CHANGE_BILLING_TYPE, "")
|
||||
kwargs := jsonutils.NewDict()
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "GuestChangeBillingTypeTask", self, userCred, kwargs, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type DiskChangeBillingTypeTask struct {
|
||||
SDiskBaseTask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(DiskChangeBillingTypeTask{})
|
||||
}
|
||||
|
||||
func (self *DiskChangeBillingTypeTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
disk := obj.(*models.SDisk)
|
||||
|
||||
idisk, err := disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
self.taskFail(ctx, disk, errors.Wrapf(err, "GetIDisk"))
|
||||
return
|
||||
}
|
||||
|
||||
billType := ""
|
||||
switch disk.BillingType {
|
||||
case billing_api.BILLING_TYPE_POSTPAID:
|
||||
billType = billing_api.BILLING_TYPE_PREPAID
|
||||
case billing_api.BILLING_TYPE_PREPAID:
|
||||
billType = billing_api.BILLING_TYPE_POSTPAID
|
||||
}
|
||||
|
||||
err = idisk.ChangeBillingType(billType)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
disk.SetStatus(ctx, self.GetUserCred(), api.DISK_READY, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
return
|
||||
}
|
||||
self.taskFail(ctx, disk, errors.Wrapf(err, "ChangeBillingType"))
|
||||
return
|
||||
}
|
||||
|
||||
idisk.Refresh()
|
||||
|
||||
db.Update(disk, func() error {
|
||||
disk.BillingType = billType
|
||||
disk.ExpiredAt = time.Time{}
|
||||
if disk.BillingType == billing_api.BILLING_TYPE_PREPAID {
|
||||
disk.AutoRenew = idisk.IsAutoRenew()
|
||||
disk.ExpiredAt = idisk.GetExpiredAt()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
self.taskComplete(ctx, disk)
|
||||
}
|
||||
|
||||
func (self *DiskChangeBillingTypeTask) taskComplete(ctx context.Context, disk *models.SDisk) {
|
||||
disk.SetStatus(ctx, self.GetUserCred(), api.DISK_READY, "")
|
||||
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_CHANGE_BILLING_TYPE, disk.BillingType, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *DiskChangeBillingTypeTask) taskFail(ctx context.Context, disk *models.SDisk, err error) {
|
||||
disk.SetStatus(ctx, self.GetUserCred(), apis.STATUS_CHANGE_BILLING_TYPE_FAILED, "")
|
||||
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_CHANGE_BILLING_TYPE, err, self.UserCred, false)
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
@@ -49,12 +49,12 @@ func (self *GuestChangeBillingTypeTask) OnInit(ctx context.Context, obj db.IStan
|
||||
}
|
||||
|
||||
func (self *GuestChangeBillingTypeTask) OnGuestChangeBillingTypeTaskComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_CHANGE_BILLING_TYPE, guest.BillingType, self.UserCred, false)
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_CHANGE_BILLING_TYPE, guest.BillingType, self.UserCred, false)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *GuestChangeBillingTypeTask) OnGuestChangeBillingTypeTaskCompleteFailed(ctx context.Context, guest *models.SGuest, reason jsonutils.JSONObject) {
|
||||
guest.SetStatus(ctx, self.GetUserCred(), api.VM_CHANGE_BILLING_TYPE_FAILED, "")
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_CHANGE_BILLING_TYPE, reason.String(), self.UserCred, false)
|
||||
guest.SetStatus(ctx, self.GetUserCred(), apis.STATUS_CHANGE_BILLING_TYPE_FAILED, "")
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_CHANGE_BILLING_TYPE, reason.String(), self.UserCred, false)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -24,10 +24,12 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type GuestCreateDiskTask struct {
|
||||
@@ -211,12 +213,12 @@ func (self *ManagedGuestCreateDiskTask) OnManagedDiskPrepared(ctx context.Contex
|
||||
|
||||
for _, d := range disks {
|
||||
diskId := d.DiskId
|
||||
iDisk, err := models.DiskManager.FetchById(diskId)
|
||||
_disk, err := models.DiskManager.FetchById(diskId)
|
||||
if err != nil {
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
disk := iDisk.(*models.SDisk)
|
||||
disk := _disk.(*models.SDisk)
|
||||
if disk.Status != api.DISK_READY {
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(fmt.Sprintf("disk %s is not ready(status=%s)", disk.Id, disk.Status)))
|
||||
return
|
||||
@@ -240,7 +242,28 @@ func (self *ManagedGuestCreateDiskTask) OnManagedDiskPrepared(ctx context.Contex
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(fmt.Sprintf("Attach Disk to guest fail error: %v", err)))
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
|
||||
if guest.BillingType == billing_api.BILLING_TYPE_PREPAID {
|
||||
idisk, err := disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
if errors.Cause(err) != cloudprovider.ErrNotFound {
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_CHANGE_BILLING_TYPE, errors.Wrapf(err, "GetIDisk %s", disk.ExternalId), self.UserCred, false)
|
||||
continue
|
||||
}
|
||||
}
|
||||
err = idisk.ChangeBillingType(guest.BillingType)
|
||||
if err != nil {
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_CHANGE_BILLING_TYPE, errors.Wrapf(err, "ChangeBillingType %s", disk.ExternalId), self.UserCred, false)
|
||||
continue
|
||||
}
|
||||
|
||||
db.Update(disk, func() error {
|
||||
disk.BillingType = guest.BillingType
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -152,3 +152,16 @@ func (opts *DiskListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
type DiskChangeBillingTypeOptions struct {
|
||||
ID string
|
||||
BillingType string `choices:"prepaid|postpaid"`
|
||||
}
|
||||
|
||||
func (o *DiskChangeBillingTypeOptions) GetId() string {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *DiskChangeBillingTypeOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(map[string]string{"billing_type": o.BillingType}), nil
|
||||
}
|
||||
|
||||
@@ -74,7 +74,6 @@ const (
|
||||
ACT_VM_SETSECGROUP = "vm_setsecgroup"
|
||||
ACT_VM_CPUSET = "vm_cpuset"
|
||||
ACT_VM_CPUSET_REMOVE = "vm_cpuset_remove"
|
||||
ACT_VM_CHANGE_BILLING_TYPE = "vm_change_billing_type"
|
||||
ACT_RESET_DISK = "reset_disk"
|
||||
ACT_SYNC_STATUS = "sync_status"
|
||||
ACT_SYNC_CONF = "sync_conf"
|
||||
@@ -112,6 +111,7 @@ const (
|
||||
ACT_VM_CONVERT = "vm_convert"
|
||||
ACT_FREEZE = "freeze"
|
||||
ACT_UNFREEZE = "unfreeze"
|
||||
ACT_CHANGE_BILLING_TYPE = "change_billing_type"
|
||||
// 到期释放
|
||||
ACT_SET_EXPIRED_TIME = "set_expired_time"
|
||||
ACT_VM_SYNC_ISOLATED_DEVICE = "vm_sync_isolated_device"
|
||||
|
||||
@@ -1533,7 +1533,7 @@ func init() {
|
||||
EN("Set Commit Bound").
|
||||
CN("设置超售比"),
|
||||
)
|
||||
o.Set(ACT_VM_CHANGE_BILLING_TYPE, i18n.NewTableEntry().
|
||||
o.Set(ACT_CHANGE_BILLING_TYPE, i18n.NewTableEntry().
|
||||
EN("Change Billing Type").
|
||||
CN("更改计费模式"),
|
||||
)
|
||||
|
||||
Vendored
+3
-3
@@ -1785,7 +1785,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250512085204-4c8552cf788d
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250515020430-3c80e4f0c134
|
||||
## explicit; go 1.21
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
@@ -1882,7 +1882,7 @@ yunion.io/x/log/hooks
|
||||
yunion.io/x/ovsdb/cli_util
|
||||
yunion.io/x/ovsdb/schema/ovn_nb
|
||||
yunion.io/x/ovsdb/types
|
||||
# yunion.io/x/pkg v1.10.4-0.20250403114914-586e94d39281
|
||||
# yunion.io/x/pkg v1.10.4-0.20250513085810-efeaaca81a0e
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/pkg/appctx
|
||||
yunion.io/x/pkg/errors
|
||||
@@ -1936,7 +1936,7 @@ yunion.io/x/pkg/utils
|
||||
# yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1
|
||||
## explicit; go 1.12
|
||||
yunion.io/x/s3cli
|
||||
# yunion.io/x/sqlchemy v1.1.3-0.20250507115529-f74b83fda63b
|
||||
# yunion.io/x/sqlchemy v1.1.3-0.20250513031856-ce9f71063b3a
|
||||
## explicit; go 1.17
|
||||
yunion.io/x/sqlchemy
|
||||
yunion.io/x/sqlchemy/backends
|
||||
|
||||
+22
@@ -24,6 +24,7 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
billing_api "yunion.io/x/cloudmux/pkg/apis/billing"
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
@@ -159,6 +160,27 @@ func (self *SDisk) Resize(ctx context.Context, sizeMb int64) error {
|
||||
return self.storage.zone.region.resizeDisk(self.DiskId, sizeMb)
|
||||
}
|
||||
|
||||
func (self *SDisk) ChangeBillingType(billingType string) error {
|
||||
return self.storage.zone.region.ChangeDiskChargeType(self.InstanceId, self.DiskId, billingType)
|
||||
}
|
||||
|
||||
func (self *SRegion) ChangeDiskChargeType(vmId, diskId string, billingType string) error {
|
||||
params := make(map[string]string)
|
||||
params["RegionId"] = self.RegionId
|
||||
params["DiskIds"] = jsonutils.Marshal([]string{diskId}).String()
|
||||
switch billingType {
|
||||
case billing_api.BILLING_TYPE_POSTPAID:
|
||||
params["DiskChargeType"] = "PostPaid"
|
||||
case billing_api.BILLING_TYPE_PREPAID:
|
||||
params["DiskChargeType"] = "PrePaid"
|
||||
}
|
||||
params["AutoPay"] = "true"
|
||||
params["ClientToken"] = utils.GenRequestId(20)
|
||||
params["InstanceId"] = vmId
|
||||
_, err := self.ecsRequest("ModifyDiskChargeType", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SDisk) GetName() string {
|
||||
if len(self.DiskName) > 0 {
|
||||
return self.DiskName
|
||||
|
||||
+1
-1
@@ -252,7 +252,7 @@ func (self *SImage) GetSizeByte() int64 {
|
||||
func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
|
||||
if self.imgInfo == nil {
|
||||
name := self.ImageName
|
||||
if len(self.Description) > 0 {
|
||||
if len(self.Description) > 0 && self.GetImageType() != cloudprovider.ImageTypeCustomized {
|
||||
name = self.Description
|
||||
}
|
||||
imgInfo := imagetools.NormalizeImageInfo(name, self.Architecture, getImageOSType(*self), getImageOSDist(*self), getImageOSVersion(*self))
|
||||
|
||||
+1
-1
@@ -183,7 +183,7 @@ var imageVersions = map[string][]string{
|
||||
|
||||
OS_DIST_ALIBABA_CLOUD_LINUX: {"2.1903", "3.2104"},
|
||||
OS_DIST_ANOLIS: {"7.9", "8.2", "8.4"},
|
||||
OS_DIST_ROCKY_LINUX: {"8.5", "8.6", "8.7", "8.8", "8.9", "8.10", "9.0", "9.1", "9.2", "9.3", "9.4"},
|
||||
OS_DIST_ROCKY_LINUX: {"8.5", "8.6", "8.7", "8.8", "8.9", "8.10", "9.0", "9.1", "9.2", "9.3", "9.4", "9.5"},
|
||||
OS_DIST_FEDORA: {"33", "34", "35"},
|
||||
OS_DIST_ALMA_LINUX: {"8.5"},
|
||||
OS_DIST_AMAZON_LINUX: {"2023", "2"},
|
||||
|
||||
+3
@@ -423,5 +423,8 @@ func (c *SBaseCompoundColumn) ConvertFromValue(val interface{}) interface{} {
|
||||
if ok && bVal != nil {
|
||||
return bVal.String()
|
||||
}
|
||||
if _, ok := val.(string); ok {
|
||||
return val
|
||||
}
|
||||
return jsonutils.Marshal(val).String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user