Commit 6aeb46f7 authored by Shahid Iqbal's avatar Shahid Iqbal

Add support to disable hyperv dynamic memory management during VM creation

Signed-off-by: default avatarShahid Iqbal <[email protected]>
parent 7890e8dc
......@@ -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,
......@@ -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",
},
}
}
......@@ -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
......@@ -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",
......
......@@ -31,6 +31,7 @@ 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) {
......@@ -38,13 +39,14 @@ func TestSetConfigFromCustomFlags(t *testing.T) {
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(),
}
......@@ -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)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment