Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions .web-docs/components/builder/vsphere-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ disks are stored.
- `disk_eagerly_scrub` (bool) - Enable eager scrubbing for the disk.
Defaults to `false`.

- `disk_controller_index` (int) - The assigned disk controller for the disk.
Defaults to the first controller, `(0)`.
- `disk_controller_index` (int) - The assigned disk controller for the disk at the zero-based index
(0, 1, 2, ...). Defaults to the first controller, `(0)`.
Mutually exclusive with `disk_controller_unit`.

- `disk_controller_unit` (string) - Explicit controller address for the disk when cloning from a `template`
Expand Down Expand Up @@ -1597,35 +1597,39 @@ wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/foo/bar/preseed.cfg

<!-- Code generated from the comments of the WaitIpConfig struct in builder/vsphere/common/step_wait_for_ip.go; DO NOT EDIT MANUALLY -->

- `ip_wait_timeout` (duration string | ex: "1h5m2s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'.
Defaults to `30m` (30 minutes). Refer to the Golang
- `ip_wait_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait for virtual machine's IP, similar to
`ssh_timeout`. Defaults to `30m` (30 minutes). Refer to the Golang
[ParseDuration](https://golang.org/pkg/time/#ParseDuration)
documentation for full details.
documentation for more information.

- `ip_settle_timeout` (duration string | ex: "1h5m2s") - Amount of time to wait for VM's IP to settle down, sometimes VM may
report incorrect IP initially, then it is recommended to set that
parameter to apx. 2 minutes. Examples `45s` and `10m`.
Defaults to `5s` (5 seconds). Refer to the Golang
[ParseDuration](https://golang.org/pkg/time/#ParseDuration)
documentation for full details.
- `ip_settle_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait for virtual machine's IP to settle down. For
example, `45s` and `10m`. Defaults to `5s` (5 seconds). Refer to the
Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration)
documentation for more information.

- `ip_wait_address` (\*string) - Set this to a CIDR address to cause the service to wait for an address that is contained in
this network range. Defaults to `0.0.0.0/0` for any IPv4 address.
- `ip_wait_address` (\*string) - The IP address range in CIDR notation to wait for. Defaults to
`0.0.0.0/0` for any IPv4 address.

-> **Note:** This only filters which guest-reported IP is accepted; it does not disable IP wait. Use `disable_ip_wait` to skip
waiting for a guest-reported IP entirely. When `disable_ip_wait` is true, this setting still applies to HTTP IP discovery.
-> **Note:** This only filters which guest-reported IP is accepted; it
does not disable IP wait. Use `disable_ip_wait` to skip waiting for a
guest-reported IP entirely. When `disable_ip_wait` is `true`, this
setting still applies to HTTP IP discovery.

Examples include:
* empty string ("") - remove all filters
* `0:0:0:0:0:0:0:0/0` - allow only ipv6 addresses
* `192.168.1.0/24` - only allow ipv4 addresses from 192.168.1.1 to 192.168.1.254
* `0:0:0:0:0:0:0:0/0` - allow only IPv6 addresses
* `192.168.1.0/24` - only allow IPv4 addresses from 192.168.1.1 to 192.168.1.254

- `ip_wait_adapter_index` (\*int) - When set, wait for an IP on a specific network adapter at this zero-based
index (0, 1, 2, ...).

- `disable_ip_wait` (bool) - When true, skip waiting for a guest-reported IP from vCenter. The default wait relies on
VMware Tools or open-vm-tools guest information. Use when they cannot be installed during
guest operating system install. Defaults to `false`.
- `disable_ip_wait` (bool) - When `true`, skip waiting for a guest-reported IP from vCenter. The
default wait relies on VMware Tools or open-vm-tools guest information.
Use when they cannot be installed during guest operating system install.
Defaults to `false`.

-> **Note:** You must set `ssh_host` or `winrm_host`; reachability timing uses `ssh_timeout`
or `winrm_timeout`, not `ip_wait_timeout`.
-> **Note:** You must set `ssh_host` or `winrm_host`; reachability timing
uses `ssh_timeout` or `winrm_timeout`, not `ip_wait_timeout`.

<!-- End of code generated from the comments of the WaitIpConfig struct in builder/vsphere/common/step_wait_for_ip.go; -->

Expand Down
48 changes: 26 additions & 22 deletions .web-docs/components/builder/vsphere-iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ JSON Example:
- `disk_eagerly_scrub` (bool) - Enable eager scrubbing for the disk.
Defaults to `false`.

- `disk_controller_index` (int) - The assigned disk controller for the disk.
Defaults to the first controller, `(0)`.
- `disk_controller_index` (int) - The assigned disk controller for the disk at the zero-based index
(0, 1, 2, ...). Defaults to the first controller, `(0)`.
Mutually exclusive with `disk_controller_unit`.

- `disk_controller_unit` (string) - Explicit controller address for the disk when cloning from a `template`
Expand Down Expand Up @@ -1212,35 +1212,39 @@ JSON Example:

<!-- Code generated from the comments of the WaitIpConfig struct in builder/vsphere/common/step_wait_for_ip.go; DO NOT EDIT MANUALLY -->

- `ip_wait_timeout` (duration string | ex: "1h5m2s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'.
Defaults to `30m` (30 minutes). Refer to the Golang
- `ip_wait_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait for virtual machine's IP, similar to
`ssh_timeout`. Defaults to `30m` (30 minutes). Refer to the Golang
[ParseDuration](https://golang.org/pkg/time/#ParseDuration)
documentation for full details.
documentation for more information.

- `ip_settle_timeout` (duration string | ex: "1h5m2s") - Amount of time to wait for VM's IP to settle down, sometimes VM may
report incorrect IP initially, then it is recommended to set that
parameter to apx. 2 minutes. Examples `45s` and `10m`.
Defaults to `5s` (5 seconds). Refer to the Golang
[ParseDuration](https://golang.org/pkg/time/#ParseDuration)
documentation for full details.
- `ip_settle_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait for virtual machine's IP to settle down. For
example, `45s` and `10m`. Defaults to `5s` (5 seconds). Refer to the
Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration)
documentation for more information.

- `ip_wait_address` (\*string) - Set this to a CIDR address to cause the service to wait for an address that is contained in
this network range. Defaults to `0.0.0.0/0` for any IPv4 address.
- `ip_wait_address` (\*string) - The IP address range in CIDR notation to wait for. Defaults to
`0.0.0.0/0` for any IPv4 address.

-> **Note:** This only filters which guest-reported IP is accepted; it does not disable IP wait. Use `disable_ip_wait` to skip
waiting for a guest-reported IP entirely. When `disable_ip_wait` is true, this setting still applies to HTTP IP discovery.
-> **Note:** This only filters which guest-reported IP is accepted; it
does not disable IP wait. Use `disable_ip_wait` to skip waiting for a
guest-reported IP entirely. When `disable_ip_wait` is `true`, this
setting still applies to HTTP IP discovery.

Examples include:
* empty string ("") - remove all filters
* `0:0:0:0:0:0:0:0/0` - allow only ipv6 addresses
* `192.168.1.0/24` - only allow ipv4 addresses from 192.168.1.1 to 192.168.1.254
* `0:0:0:0:0:0:0:0/0` - allow only IPv6 addresses
* `192.168.1.0/24` - only allow IPv4 addresses from 192.168.1.1 to 192.168.1.254

- `ip_wait_adapter_index` (\*int) - When set, wait for an IP on a specific network adapter at this zero-based
index (0, 1, 2, ...).

- `disable_ip_wait` (bool) - When true, skip waiting for a guest-reported IP from vCenter. The default wait relies on
VMware Tools or open-vm-tools guest information. Use when they cannot be installed during
guest operating system install. Defaults to `false`.
- `disable_ip_wait` (bool) - When `true`, skip waiting for a guest-reported IP from vCenter. The
default wait relies on VMware Tools or open-vm-tools guest information.
Use when they cannot be installed during guest operating system install.
Defaults to `false`.

-> **Note:** You must set `ssh_host` or `winrm_host`; reachability timing uses `ssh_timeout`
or `winrm_timeout`, not `ip_wait_timeout`.
-> **Note:** You must set `ssh_host` or `winrm_host`; reachability timing
uses `ssh_timeout` or `winrm_timeout`, not `ip_wait_timeout`.

<!-- End of code generated from the comments of the WaitIpConfig struct in builder/vsphere/common/step_wait_for_ip.go; -->

Expand Down
2 changes: 2 additions & 0 deletions builder/vsphere/clone/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 43 additions & 22 deletions builder/vsphere/common/step_wait_for_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,40 @@ import (
)

type WaitIpConfig struct {
// Amount of time to wait for VM's IP, similar to 'ssh_timeout'.
// Defaults to `30m` (30 minutes). Refer to the Golang
// The amount of time to wait for virtual machine's IP, similar to
// `ssh_timeout`. Defaults to `30m` (30 minutes). Refer to the Golang
// [ParseDuration](https://golang.org/pkg/time/#ParseDuration)
// documentation for full details.
// documentation for more information.
WaitTimeout time.Duration `mapstructure:"ip_wait_timeout"`
// Amount of time to wait for VM's IP to settle down, sometimes VM may
// report incorrect IP initially, then it is recommended to set that
// parameter to apx. 2 minutes. Examples `45s` and `10m`.
// Defaults to `5s` (5 seconds). Refer to the Golang
// [ParseDuration](https://golang.org/pkg/time/#ParseDuration)
// documentation for full details.
// The amount of time to wait for virtual machine's IP to settle down. For
// example, `45s` and `10m`. Defaults to `5s` (5 seconds). Refer to the
// Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration)
// documentation for more information.
SettleTimeout time.Duration `mapstructure:"ip_settle_timeout"`
// Set this to a CIDR address to cause the service to wait for an address that is contained in
// this network range. Defaults to `0.0.0.0/0` for any IPv4 address.
// The IP address range in CIDR notation to wait for. Defaults to
// `0.0.0.0/0` for any IPv4 address.
//
// -> **Note:** This only filters which guest-reported IP is accepted; it does not disable IP wait. Use `disable_ip_wait` to skip
// waiting for a guest-reported IP entirely. When `disable_ip_wait` is true, this setting still applies to HTTP IP discovery.
// -> **Note:** This only filters which guest-reported IP is accepted; it
// does not disable IP wait. Use `disable_ip_wait` to skip waiting for a
// guest-reported IP entirely. When `disable_ip_wait` is `true`, this
// setting still applies to HTTP IP discovery.
//
// Examples include:
// * empty string ("") - remove all filters
// * `0:0:0:0:0:0:0:0/0` - allow only ipv6 addresses
// * `192.168.1.0/24` - only allow ipv4 addresses from 192.168.1.1 to 192.168.1.254
// * `0:0:0:0:0:0:0:0/0` - allow only IPv6 addresses
// * `192.168.1.0/24` - only allow IPv4 addresses from 192.168.1.1 to 192.168.1.254
WaitAddress *string `mapstructure:"ip_wait_address"`
ipnet *net.IPNet
// When true, skip waiting for a guest-reported IP from vCenter. The default wait relies on
// VMware Tools or open-vm-tools guest information. Use when they cannot be installed during
// guest operating system install. Defaults to `false`.
// When set, wait for an IP on a specific network adapter at this zero-based
// index (0, 1, 2, ...).
WaitAdapterIndex *int `mapstructure:"ip_wait_adapter_index"`
// When `true`, skip waiting for a guest-reported IP from vCenter. The
// default wait relies on VMware Tools or open-vm-tools guest information.
// Use when they cannot be installed during guest operating system install.
// Defaults to `false`.
//
// -> **Note:** You must set `ssh_host` or `winrm_host`; reachability timing uses `ssh_timeout`
// or `winrm_timeout`, not `ip_wait_timeout`.
// -> **Note:** You must set `ssh_host` or `winrm_host`; reachability timing
// uses `ssh_timeout` or `winrm_timeout`, not `ip_wait_timeout`.
DisableIpWait bool `mapstructure:"disable_ip_wait"`
}

Expand Down Expand Up @@ -79,6 +83,10 @@ func (c *WaitIpConfig) Prepare() []error {
}
}

if c.WaitAdapterIndex != nil && *c.WaitAdapterIndex < 0 {
errs = append(errs, fmt.Errorf("ip_wait_adapter_index must be >= 0"))
}

return errs
}

Expand Down Expand Up @@ -115,7 +123,11 @@ func (s *StepWaitForIp) Run(ctx context.Context, state multistep.StateBag) multi
}()

go func() {
ui.Say("Waiting for IP...")
if s.Config.WaitAdapterIndex != nil {
ui.Sayf("Waiting for IP on network adapter with index %d...", *s.Config.WaitAdapterIndex)
} else {
ui.Say("Waiting for IP...")
}
ip, err = doGetIp(vm, sub, s.Config)
waitDone <- true
}()
Expand Down Expand Up @@ -170,7 +182,7 @@ func doGetIp(vm *driver.VirtualMachineDriver, ctx context.Context, c *WaitIpConf
interval = 1 * time.Second
}
loop:
ip, err := vm.WaitForIP(ctx, c.ipnet)
ip, err := vm.WaitForIP(ctx, c.ipnet, c.WaitAdapterIndex)
if err != nil {
return "", err
}
Expand All @@ -182,6 +194,15 @@ loop:
default:
}

if ip == "" {
select {
case <-ctx.Done():
return "", fmt.Errorf("IP wait cancelled")
case <-time.After(interval):
goto loop
}
}

if prevIp == "" || prevIp != ip {
if prevIp == "" {
log.Printf("VM IP acquired: %s", ip)
Expand Down
18 changes: 10 additions & 8 deletions builder/vsphere/common/step_wait_for_ip.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions builder/vsphere/common/step_wait_for_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,18 @@ func TestWaitIpConfig_ValidateDisableIpWait(t *testing.T) {
}
})
}

func TestWaitIpConfig_Prepare_adapterIndex(t *testing.T) {
neg := -1
c := WaitIpConfig{WaitAdapterIndex: &neg}
errs := c.Prepare()
if len(errs) != 1 {
t.Fatalf("expected 1 error, got %v", errs)
}

zero := 0
c = WaitIpConfig{WaitAdapterIndex: &zero}
if errs := c.Prepare(); len(errs) != 0 {
t.Fatalf("unexpected errors: %v", errs)
}
}
4 changes: 2 additions & 2 deletions builder/vsphere/common/storage_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type DiskConfig struct {
// Enable eager scrubbing for the disk.
// Defaults to `false`.
DiskEagerlyScrub bool `mapstructure:"disk_eagerly_scrub"`
// The assigned disk controller for the disk.
// Defaults to the first controller, `(0)`.
// The assigned disk controller for the disk at the zero-based index
// (0, 1, 2, ...). Defaults to the first controller, `(0)`.
// Mutually exclusive with `disk_controller_unit`.
DiskControllerIndex int `mapstructure:"disk_controller_index"`
// Explicit controller address for the disk when cloning from a `template`
Expand Down
Loading