Skip to content

Commit

Permalink
fix(region): esxi change config (#19089)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Dec 25, 2023
1 parent 5ed79e2 commit 0e4583c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/compute/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ type ServerChangeConfigInput struct {
Flavor string `json:"flavor" yunion-deprecated-by:"instance_type"`

// cpu卡槽数
// vmware 若开机调整配置时,需要保证调整前及调整后 vcpu_count / cpu_sockets 保持不变
// vmware开机调整配置同样需要注意 https://kb.vmware.com/s/article/2008405
CpuSockets *int `json:"cpu_sockets"`
// cpu大小
VcpuCount *int `json:"vcpu_count"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/guestdrivers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (drv *SBaseGuestDriver) IsSupportPublicIp() bool {
return false
}

func (drv *SBaseGuestDriver) NeedStopForChangeSpec(ctx context.Context, guest *models.SGuest, addCpu int, addMemMb int) bool {
func (drv *SBaseGuestDriver) NeedStopForChangeSpec(ctx context.Context, guest *models.SGuest, addCpu int, addMemMb, addSocket int) bool {
return false
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/compute/guestdrivers/esxi.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,10 @@ func (drv *SESXiGuestDriver) RequestUndeployGuestOnHost(ctx context.Context, gue
return nil
}

func (drv *SESXiGuestDriver) NeedStopForChangeSpec(ctx context.Context, guest *models.SGuest, addCpu int, addMemMb int) bool {
if guest.CpuSockets > 1 {
// cannot chagne esxi VM CPU cores if cpu_sockets > 1
return false
func (drv *SESXiGuestDriver) NeedStopForChangeSpec(ctx context.Context, guest *models.SGuest, addCpu int, addMemMb, addSocket int) bool {
// cannot chagne esxi VM CPU cores
if float32(guest.VcpuCount+addCpu)/float32(guest.CpuSockets+addSocket)-float32(guest.VcpuCount)/float32(guest.CpuSockets) > 0.0001 {
return true
}
// https://kb.vmware.com/s/article/2008405
// cannot increse memory beyond 3G if the initial CPU memories is lower than 3G
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/guestdrivers/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (self *SKVMGuestDriver) RequestAssociateEip(ctx context.Context, userCred m
return nil
}

func (self *SKVMGuestDriver) NeedStopForChangeSpec(ctx context.Context, guest *models.SGuest, addCpu int, addMemMb int) bool {
func (self *SKVMGuestDriver) NeedStopForChangeSpec(ctx context.Context, guest *models.SGuest, addCpu int, addMemMb, addSocket int) bool {
return guest.GetMetadata(ctx, api.VM_METADATA_HOTPLUG_CPU_MEM, nil) != "enable" || apis.IsARM(guest.OsArch)
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/compute/models/guest_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
return nil, errors.Wrapf(err, "GetHost")
}

var addCpu, addMem int
var addCpu, addMem, addSocket int
var cpuChanged, cpuSocketsChanged, memChanged bool

confs := jsonutils.NewDict()
Expand Down Expand Up @@ -2758,14 +2758,12 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
if *input.CpuSockets > self.VcpuCount+addCpu {
return nil, httperrors.NewInputParameterError("The number of cpu sockets cannot be greater than the number of cpus")
}
if self.PowerStates == api.VM_POWER_STATES_ON {
return nil, httperrors.NewInvalidStatusError("cannot change CPU socket in power status %s", self.PowerStates)
}
cpuSocketsChanged = true
addSocket = *input.CpuSockets - self.CpuSockets
confs.Set("cpu_sockets", jsonutils.NewInt(int64(*input.CpuSockets)))
}

if self.PowerStates == api.VM_POWER_STATES_ON && (cpuChanged || memChanged || cpuSocketsChanged) && self.GetDriver().NeedStopForChangeSpec(ctx, self, addCpu, addMem) {
if self.PowerStates == api.VM_POWER_STATES_ON && (cpuChanged || memChanged || cpuSocketsChanged) && self.GetDriver().NeedStopForChangeSpec(ctx, self, addCpu, addMem, addSocket) {
return nil, httperrors.NewInvalidStatusError("cannot change CPU/Memory spec in power status %s", self.PowerStates)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/models/guestdrivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type IGuestDriver interface {
IsSupportPublicIp() bool
ValidateCreateEip(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerCreateEipInput) error

NeedStopForChangeSpec(ctx context.Context, guest *SGuest, addCpu int, addMemMb int) bool
NeedStopForChangeSpec(ctx context.Context, guest *SGuest, addCpu int, addMemMb, addSocket int) bool

OnGuestChangeCpuMemFailed(ctx context.Context, guest *SGuest, data *jsonutils.JSONDict, task taskman.ITask) error
IsSupportGuestClone() bool
Expand Down

0 comments on commit 0e4583c

Please sign in to comment.