From dde614dbb0e799661aa4966c553dc2c0eeec25d3 Mon Sep 17 00:00:00 2001 From: Paul Biggar Date: Wed, 25 Mar 2015 20:04:34 -0700 Subject: [PATCH] Adds virtualbox-cpu-count - fixes #819 Signed-off-by: Paul Biggar --- docs/index.md | 1 + drivers/virtualbox/virtualbox.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index c4fd217483..eedae096f6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -823,6 +823,7 @@ Options: - `--virtualbox-boot2docker-url`: The URL of the boot2docker image. Defaults to the latest available version. - `--virtualbox-disk-size`: Size of disk for the host in MB. Default: `20000` - `--virtualbox-memory`: Size of memory for the host in MB. Default: `1024` + - `--virtualbox-cpu-count`: Number of CPUs to use to create the VM. Defaults to number of available CPUs. The VirtualBox driver uses the latest boot2docker image. diff --git a/drivers/virtualbox/virtualbox.go b/drivers/virtualbox/virtualbox.go index e7dc7f986e..d2bbb75a5f 100644 --- a/drivers/virtualbox/virtualbox.go +++ b/drivers/virtualbox/virtualbox.go @@ -31,6 +31,7 @@ const ( ) type Driver struct { + CPU int MachineName string SSHUser string SSHPort int @@ -46,6 +47,7 @@ type Driver struct { } type CreateFlags struct { + CPU *int Memory *int DiskSize *int Boot2DockerURL *string @@ -67,6 +69,12 @@ func GetCreateFlags() []cli.Flag { Usage: "Size of memory for host in MB", Value: 1024, }, + cli.IntFlag{ + Name: "virtualbox-cpu-count", + Usage: "number of CPUs for the machine (-1 to use the number of CPUs available)", + EnvVar: "VIRTUALBOX_CPU_COUNT", + Value: -1, + }, cli.IntFlag{ Name: "virtualbox-disk-size", Usage: "Size of disk for host in MB", @@ -137,6 +145,7 @@ func (d *Driver) GetURL() (string, error) { } func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { + d.CPU = flags.Int("virtualbox-cpu-count") d.Memory = flags.Int("virtualbox-memory") d.DiskSize = flags.Int("virtualbox-disk-size") d.Boot2DockerURL = flags.String("virtualbox-boot2docker-url") @@ -225,7 +234,10 @@ func (d *Driver) Create() error { return err } - cpus := uint(runtime.NumCPU()) + cpus := d.CPU + if cpus < 1 { + cpus = int(runtime.NumCPU()) + } if cpus > 32 { cpus = 32 }