From b6ebe0024995cba88e935741a905db0b470d0596 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 29 Dec 2018 23:58:05 +0300 Subject: [PATCH 1/3] provide memory and cpus like other builders does Signed-off-by: Vasiliy Tolstov --- builder/qemu/builder.go | 12 ++++++++++++ builder/qemu/step_run.go | 5 ++++- website/source/docs/builders/qemu.html.md.erb | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 1535eda86..a6d4b84f1 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -96,6 +96,7 @@ type Config struct { ISOSkipCache bool `mapstructure:"iso_skip_cache"` Accelerator string `mapstructure:"accelerator"` + CpuCount int `mapstructure:"cpus"` DiskInterface string `mapstructure:"disk_interface"` DiskSize uint `mapstructure:"disk_size"` DiskCache string `mapstructure:"disk_cache"` @@ -108,6 +109,7 @@ type Config struct { DiskImage bool `mapstructure:"disk_image"` UseBackingFile bool `mapstructure:"use_backing_file"` MachineType string `mapstructure:"machine_type"` + MemorySize int `mapstructure:"memory"` NetDevice string `mapstructure:"net_device"` OutputDir string `mapstructure:"output_directory"` QemuArgs [][]string `mapstructure:"qemuargs"` @@ -200,6 +202,16 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { b.config.QemuBinary = "qemu-system-x86_64" } + if b.config.MemorySize < 10 { + log.Printf("MemorySize %d is too small, using default: 512", b.config.MemorySize) + b.config.MemorySize = 512 + } + + if b.config.CpuCount < 1 { + log.Printf("CpuCount %d too small, using default: 1", b.config.CpuCount) + b.config.CpuCount = 1 + } + if b.config.SSHHostPortMin == 0 { b.config.SSHHostPortMin = 2222 } diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index 1d4fa9dfc..c806e10dd 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -150,7 +150,10 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error defaultArgs["-cdrom"] = isoPath } defaultArgs["-boot"] = bootDrive - defaultArgs["-m"] = "512M" + defaultArgs["-m"] = fmt.Sprintf("%dM", config.MemorySize) + if config.CpuCount > 1 { + defaultArgs["-smp"] = fmt.Sprintf("cpus=%d,sockets=%d", config.CpuCount, config.CpuCount) + } defaultArgs["-vnc"] = vnc // Append the accelerator to the machine type if it is specified diff --git a/website/source/docs/builders/qemu.html.md.erb b/website/source/docs/builders/qemu.html.md.erb index 0099f657f..8ecb1e51e 100644 --- a/website/source/docs/builders/qemu.html.md.erb +++ b/website/source/docs/builders/qemu.html.md.erb @@ -135,6 +135,8 @@ Linux server and have not enabled X11 forwarding (`ssh -X`). five seconds and one minute 30 seconds, respectively. If this isn't specified, the default is `10s` or 10 seconds. +- `cpus` (number) - The number of cpus to use when building the VM. + - `disk_cache` (string) - The cache mode to use for disk. Allowed values include any of `writethrough`, `writeback`, `none`, `unsafe` or `directsync`. By default, this is set to `writeback`. @@ -237,6 +239,9 @@ Linux server and have not enabled X11 forwarding (`ssh -X`). qemu binary with the flags `-machine help` to list available types for your system. This defaults to `pc`. +- `memory` (number) - The amount of memory to use when building the VM + in megabytes. + - `net_device` (string) - The driver to use for the network interface. Allowed values `ne2k_pci`, `i82551`, `i82557b`, `i82559er`, `rtl8139`, `e1000`, `pcnet`, `virtio`, `virtio-net`, `virtio-net-pci`, `usb-net`, `i82559a`, From 69b95db4ba3f59f3ddd6fe2230acb79cbe43d7c2 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Thu, 24 Jan 2019 00:23:16 +0300 Subject: [PATCH 2/3] Update website/source/docs/builders/qemu.html.md.erb Co-Authored-By: vtolstov --- website/source/docs/builders/qemu.html.md.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/builders/qemu.html.md.erb b/website/source/docs/builders/qemu.html.md.erb index 8ecb1e51e..01636d633 100644 --- a/website/source/docs/builders/qemu.html.md.erb +++ b/website/source/docs/builders/qemu.html.md.erb @@ -240,7 +240,7 @@ Linux server and have not enabled X11 forwarding (`ssh -X`). your system. This defaults to `pc`. - `memory` (number) - The amount of memory to use when building the VM - in megabytes. + in megabytes. This defaults to `512` megabytes. - `net_device` (string) - The driver to use for the network interface. Allowed values `ne2k_pci`, `i82551`, `i82557b`, `i82559er`, `rtl8139`, `e1000`, From c6b5cd7b73b87b4e736cc4d2ae1df8471a65b1d9 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Thu, 24 Jan 2019 00:23:30 +0300 Subject: [PATCH 3/3] Update website/source/docs/builders/qemu.html.md.erb Co-Authored-By: vtolstov --- website/source/docs/builders/qemu.html.md.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/website/source/docs/builders/qemu.html.md.erb b/website/source/docs/builders/qemu.html.md.erb index 01636d633..ee67068e5 100644 --- a/website/source/docs/builders/qemu.html.md.erb +++ b/website/source/docs/builders/qemu.html.md.erb @@ -136,6 +136,7 @@ Linux server and have not enabled X11 forwarding (`ssh -X`). specified, the default is `10s` or 10 seconds. - `cpus` (number) - The number of cpus to use when building the VM. + The default is `1` CPU. - `disk_cache` (string) - The cache mode to use for disk. Allowed values include any of `writethrough`, `writeback`, `none`, `unsafe`