From 127711a96586888df2daf3f9c53e414b24e3cd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Thu, 30 Nov 2023 13:33:34 +0800 Subject: [PATCH] fix(region): optional vcpu when change vm config (#18825) --- pkg/apis/compute/guests.go | 2 +- pkg/compute/models/guest_actions.go | 6 +++--- pkg/mcclient/cloudpods/instance.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 0996c937335..373c1dd0012 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -771,7 +771,7 @@ type ServerChangeConfigInput struct { // cpu卡槽数 CpuSockets *int `json:"cpu_sockets"` // cpu大小 - VcpuCount int `json:"vcpu_count"` + VcpuCount *int `json:"vcpu_count"` // 内存大小, 1024M, 1G VmemSize string `json:"vmem_size"` diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index d6b35e7b15a..bb9edb02be5 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -2731,10 +2731,10 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T } } } else { - if input.VcpuCount != self.VcpuCount { + if input.VcpuCount != nil && *input.VcpuCount != self.VcpuCount { cpuChanged = true - addCpu = input.VcpuCount - self.VcpuCount - confs.Add(jsonutils.NewInt(int64(input.VcpuCount)), "vcpu_count") + addCpu = *input.VcpuCount - self.VcpuCount + confs.Add(jsonutils.NewInt(int64(*input.VcpuCount)), "vcpu_count") } if len(input.VmemSize) > 0 { if !regutils.MatchSize(input.VmemSize) { diff --git a/pkg/mcclient/cloudpods/instance.go b/pkg/mcclient/cloudpods/instance.go index 29ccc6936e9..3ec8cd82908 100644 --- a/pkg/mcclient/cloudpods/instance.go +++ b/pkg/mcclient/cloudpods/instance.go @@ -293,7 +293,7 @@ func (self *SInstance) DeployVM(ctx context.Context, name string, username strin func (self *SInstance) ChangeConfig(ctx context.Context, opts *cloudprovider.SManagedVMChangeConfig) error { input := api.ServerChangeConfigInput{} input.VmemSize = fmt.Sprintf("%dM", opts.MemoryMB) - input.VcpuCount = opts.Cpu + input.VcpuCount = &opts.Cpu input.InstanceType = opts.InstanceType _, err := self.host.zone.region.perform(&modules.Servers, self.Id, "change-config", input) return err