From 6eaad273d0e9bf26c39c478191d6ecd864e12451 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Mon, 4 Nov 2024 14:06:54 +0800 Subject: [PATCH] fix(esxi): disable swap --- pkg/multicloud/esxi/host.go | 19 +++++++++++++++++++ pkg/multicloud/esxi/storagecache.go | 1 + 2 files changed, 20 insertions(+) diff --git a/pkg/multicloud/esxi/host.go b/pkg/multicloud/esxi/host.go index f39ce2dc9..967eed292 100644 --- a/pkg/multicloud/esxi/host.go +++ b/pkg/multicloud/esxi/host.go @@ -778,6 +778,7 @@ type SCreateVMParam struct { Nics []jsonutils.JSONObject ResourcePool string InstanceSnapshotInfo SEsxiInstanceSnapshotInfo + EnableEsxiSwap bool } type SEsxiInstanceSnapshotInfo struct { @@ -1080,7 +1081,17 @@ func (host *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat CpuHotAddEnabled: &True, CpuHotRemoveEnabled: &True, MemoryHotAddEnabled: &True, + + ExtraConfig: []types.BaseOptionValue{}, + } + + if !params.EnableEsxiSwap { + spec.ExtraConfig = append(spec.ExtraConfig, &types.OptionValue{ + Key: "sched.swap.vmxSwapEnabled", + Value: "FALSE", + }) } + spec.Files = &types.VirtualMachineFileInfo{ VmPathName: datastorePath, } @@ -1319,6 +1330,14 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot CpuHotAddEnabled: &True, CpuHotRemoveEnabled: &True, MemoryHotAddEnabled: &True, + + ExtraConfig: []types.BaseOptionValue{}, + } + if !params.EnableEsxiSwap { + spec.ExtraConfig = append(spec.ExtraConfig, &types.OptionValue{ + Key: "sched.swap.vmxSwapEnabled", + Value: "FALSE", + }) } cloneSpec.Config = &spec task, err := ovm.Clone(ctx, folders.VmFolder, name, *cloneSpec) diff --git a/pkg/multicloud/esxi/storagecache.go b/pkg/multicloud/esxi/storagecache.go index 86fc19a09..9e0536b82 100644 --- a/pkg/multicloud/esxi/storagecache.go +++ b/pkg/multicloud/esxi/storagecache.go @@ -42,6 +42,7 @@ type SDatastoreImageCache struct { type EsxiOptions struct { ReasonableCIDREsxi string `help:"Reasonable CIDR in esxi, such as '10.0.0.0/8'" defautl:""` TemplateNameRegex string `help:"Regex of template name"` + EnableEsxiSwap bool `help:"Enable esxi vm swap" default:"false"` } var tempalteNameRegex *regexp.Regexp