Skip to content

Commit

Permalink
Adds wait timeout option for Hyper-V driver
Browse files Browse the repository at this point in the history
Signed-off-by: Zhongcheng Lao <[email protected]>
  • Loading branch information
laozc committed Nov 15, 2019
1 parent e5b2079 commit d3b4e7c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions drivers/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Driver struct {
VLanID int
DisableDynamicMemory bool
PreferredNetworkProtocol int
WaitTimeoutInSeconds time.Duration
}

const (
Expand All @@ -43,20 +44,22 @@ const (
defaultVLanID = 0
defaultDisableDynamicMemory = false
defaultSwitchID = "c08cb7b8-9b3c-408e-8e30-5e16a3aeb444"
defaultTimeout = time.Minute * 10
defaultWaitTimeoutInSeconds = 3 * 60
)

// NewDriver creates a new Hyper-v driver with default settings.
func NewDriver(hostName, storePath string) *Driver {
return &Driver{
DiskSize: defaultDiskSize,
MemSize: defaultMemory,
CPU: defaultCPU,
DisableDynamicMemory: defaultDisableDynamicMemory,
BaseDriver: &drivers.BaseDriver{
MachineName: hostName,
StorePath: storePath,
},
DiskSize: defaultDiskSize,
MemSize: defaultMemory,
CPU: defaultCPU,
DisableDynamicMemory: defaultDisableDynamicMemory,
PreferredNetworkProtocol: DefaultProtocol,
WaitTimeoutInSeconds: defaultWaitTimeoutInSeconds,
}
}

Expand Down Expand Up @@ -113,6 +116,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Preferred network protocol (IPv4/v6)",
EnvVar: "HYPERV_PREFERRED_NETWORK_PROTOCOL",
},
mcnflag.IntFlag{
Name: "hyperv-wait-timeout",
Usage: "Wait timeout (in seconds)",
Value: defaultWaitTimeoutInSeconds,
EnvVar: "HYPERV_WAIT_TIMEOUT",
},
}
}

Expand All @@ -126,6 +135,8 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.VLanID = flags.Int("hyperv-vlan-id")
d.SSHUser = "docker"
d.DisableDynamicMemory = flags.Bool("hyperv-disable-dynamic-memory")
d.PreferredNetworkProtocol = flags.Int("hyperv-preferred-network-protocol")
d.WaitTimeoutInSeconds = time.Duration(flags.Int("hyperv-wait-timeout"))
d.SetSwarmConfigFromFlags(flags)

return nil
Expand Down Expand Up @@ -349,7 +360,7 @@ func (d *Driver) waitForIP() (string, error) {
return ip, nil
}

if time.Since(start) >= defaultTimeout {
if time.Since(start) >= d.WaitTimeoutInSeconds*time.Second {
return "", errors.New("timeout waiting for IP")
}

Expand All @@ -372,7 +383,7 @@ func (d *Driver) waitStopped() error {
return nil
}

if time.Since(start) >= defaultTimeout {
if time.Since(start) >= d.WaitTimeoutInSeconds*time.Second {
return errors.New("timeout waiting for stopped")
}

Expand Down

0 comments on commit d3b4e7c

Please sign in to comment.