Skip to content

Commit

Permalink
add ip_wait_timeout feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof committed Jan 8, 2023
1 parent 9ba9806 commit cc0bd9a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions builder/nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ type Config struct {
shutdowncommand.ShutdownConfig `mapstructure:",squash"`
ClusterConfig `mapstructure:",squash"`
VmConfig `mapstructure:",squash"`
ForceDeregister bool `mapstructure:"force_deregister" json:"force_deregister" required:"false"`
ImageDescription string `mapstructure:"image_description" json:"image_description" required:"false"`
ForceDeregister bool `mapstructure:"force_deregister" json:"force_deregister" required:"false"`
ImageDescription string `mapstructure:"image_description" json:"image_description" required:"false"`
WaitTimeout time.Duration `mapstructure:"ip_wait_timeout" json:"ip_wait_timeout" required:"false"`

ctx interpolate.Context
}
Expand Down Expand Up @@ -159,6 +160,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.CommConfig.SSHTimeout = 20 * time.Minute
}

// Define default ip_wait_timeout to 15 min
if c.WaitTimeout == 0 {
c.WaitTimeout = 15 * time.Minute
}

errs = packersdk.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
errs = packersdk.MultiErrorAppend(errs, c.CDConfig.Prepare(&c.ctx)...)
errs = packersdk.MultiErrorAppend(errs, c.CommConfig.Prepare(&c.ctx)...)
Expand Down
2 changes: 2 additions & 0 deletions builder/nutanix/config.hcl2spec.go

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

7 changes: 6 additions & 1 deletion builder/nutanix/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,12 @@ func (d *NutanixDriver) Create(req *v3.VMIntentInput) (*nutanixInstance, error)
}

// Wait for the VM obtain an IP address
for i := 0; i < 60; i++ {

log.Printf("[INFO] Waiting for IP, up to timeout: %s", d.Config.WaitTimeout)

iteration := int(d.Config.WaitTimeout.Seconds()) / 5

for i := 0; i < iteration; i++ {
vm, err = conn.V3.GetVM(uuid)
if err != nil || len(vm.Status.Resources.NicList[0].IPEndpointList) == (0) {
log.Printf("Waiting VM (%s) ip configuration", uuid)
Expand Down
1 change: 0 additions & 1 deletion builder/nutanix/step_build_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type stepBuildVM struct {
func (s *stepBuildVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
//Update UI
ui := state.Get("ui").(packer.Ui)
//config := state.Get("config").(*Config)
ui.Say("Creating Packer Builder VM on Nutanix Cluster.")
d := state.Get("driver").(Driver)
config := state.Get("config").(*Config)
Expand Down
3 changes: 2 additions & 1 deletion docs/builders/nutanix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ These parameters allow to define information about platform and temporary VM use
- `nutanix_endpoint` (string) - Prism Central FQDN or IP.
- `cluster_name` or `cluster_uuid` (string) - Nutanix cluster name or uuid used to create and store image.
- `os_type` (string) - OS Type ("Linux" or "Windows").

### Optional
- `nutanix_port` (number) - Port used for connection to Prism Central.
- `nutanix_insecure` (bool) - Authorize connection to Prism Central without valid certificate.
Expand All @@ -30,6 +30,7 @@ These parameters allow to define information about platform and temporary VM use
- `cd_files` (array of strings) - A list of files to place onto a CD that is attached when the VM is booted. This can include either files or directories; any directories will be copied onto the CD recursively, preserving directory structure hierarchy.
- `cd_label` (string) - Label of this CD Drive.
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "UEFI").
- `ip_wait_timeout` (duration string | ex: "0h42m0s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'. Defaults to 15m (15 minutes). See the Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration) documentation for full details.

## Output configuration
These parameters allow to configure everything around image creation, from the temporary VM connection to the final image definition.
Expand Down

0 comments on commit cc0bd9a

Please sign in to comment.