Skip to content

Commit

Permalink
Merge pull request docker#4477 from shahiddev/master
Browse files Browse the repository at this point in the history
Add support to disable hyperv dynamic memory management
  • Loading branch information
dgageot committed Jun 4, 2018
2 parents 635818a + 6aeb46f commit 1e4713b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
44 changes: 30 additions & 14 deletions drivers/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@ import (

type Driver struct {
*drivers.BaseDriver
Boot2DockerURL string
VSwitch string
DiskSize int
MemSize int
CPU int
MacAddr string
VLanID int
Boot2DockerURL string
VSwitch string
DiskSize int
MemSize int
CPU int
MacAddr string
VLanID int
DisableDynamicMemory bool
}

const (
defaultDiskSize = 20000
defaultMemory = 1024
defaultCPU = 1
defaultVLanID = 0
defaultDiskSize = 20000
defaultMemory = 1024
defaultCPU = 1
defaultVLanID = 0
defaultDisableDynamicMemory = false
)

// NewDriver creates a new Hyper-v driver with default settings.
func NewDriver(hostName, storePath string) *Driver {
return &Driver{
DiskSize: defaultDiskSize,
MemSize: defaultMemory,
CPU: defaultCPU,
DiskSize: defaultDiskSize,
MemSize: defaultMemory,
CPU: defaultCPU,
DisableDynamicMemory: defaultDisableDynamicMemory,
BaseDriver: &drivers.BaseDriver{
MachineName: hostName,
StorePath: storePath,
Expand Down Expand Up @@ -88,6 +91,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Value: defaultVLanID,
EnvVar: "HYPERV_VLAN_ID",
},
mcnflag.BoolFlag{
Name: "hyperv-disable-dynamic-memory",
Usage: "Disable dynamic memory management setting",
EnvVar: "HYPERV_DISABLE_DYNAMIC_MEMORY",
},
}
}

Expand All @@ -100,6 +108,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.MacAddr = flags.String("hyperv-static-macaddress")
d.VLanID = flags.Int("hyperv-vlan-id")
d.SSHUser = "docker"
d.DisableDynamicMemory = flags.Bool("hyperv-disable-dynamic-memory")
d.SetSwarmConfigFromFlags(flags)

return nil
Expand Down Expand Up @@ -212,6 +221,13 @@ func (d *Driver) Create() error {
"-MemoryStartupBytes", toMb(d.MemSize)); err != nil {
return err
}
if d.DisableDynamicMemory {
if err := cmd("Hyper-V\\Set-VMMemory",
"-VMName", d.MachineName,
"-DynamicMemoryEnabled", "$false"); err != nil {
return err
}
}

if d.CPU > 1 {
if err := cmd("Hyper-V\\Set-VMProcessor",
Expand Down
17 changes: 10 additions & 7 deletions drivers/hyperv/hyperv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ func TestSetConfigFromDefaultFlags(t *testing.T) {
assert.Equal(t, "", driver.MacAddr)
assert.Equal(t, defaultVLanID, driver.VLanID)
assert.Equal(t, "docker", driver.GetSSHUsername())
assert.Equal(t, defaultDisableDynamicMemory, driver.DisableDynamicMemory)
}

func TestSetConfigFromCustomFlags(t *testing.T) {
driver := NewDriver("default", "path")

checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"hyperv-boot2docker-url": "B2D_URL",
"hyperv-virtual-switch": "TheSwitch",
"hyperv-disk-size": 100000,
"hyperv-memory": 4096,
"hyperv-cpu-count": 4,
"hyperv-static-macaddress": "00:0a:95:9d:68:16",
"hyperv-vlan-id": 2,
"hyperv-boot2docker-url": "B2D_URL",
"hyperv-virtual-switch": "TheSwitch",
"hyperv-disk-size": 100000,
"hyperv-memory": 4096,
"hyperv-cpu-count": 4,
"hyperv-static-macaddress": "00:0a:95:9d:68:16",
"hyperv-vlan-id": 2,
"hyperv-disable-dynamic-memory": true,
},
CreateFlags: driver.GetCreateFlags(),
}
Expand All @@ -65,4 +67,5 @@ func TestSetConfigFromCustomFlags(t *testing.T) {
assert.Equal(t, "00:0a:95:9d:68:16", driver.MacAddr)
assert.Equal(t, 2, driver.VLanID)
assert.Equal(t, "docker", driver.GetSSHUsername())
assert.Equal(t, true, driver.DisableDynamicMemory)
}

0 comments on commit 1e4713b

Please sign in to comment.