Skip to content

Commit 80ce1c4

Browse files
authored
Fix IP wait workflow (#254)
* skip boot_command if not needed * prepare for next version * fix IP wait workflow
1 parent e604291 commit 80ce1c4

File tree

13 files changed

+40
-34
lines changed

13 files changed

+40
-34
lines changed

.web-docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To install this plugin, copy and paste this code into your Packer configuration,
99
packer {
1010
required_plugins {
1111
nutanix = {
12-
version = ">= 0.13.0"
12+
version = ">= 0.13.1"
1313
source = "github.com/nutanix-cloud-native/nutanix"
1414
}
1515
}

.web-docs/components/builder/nutanix/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ These parameters allow to define information about platform and temporary VM use
2323
- `cd_label` (string) - Label of this CD Drive.
2424
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "uefi", default is "legacy").
2525
- `boot_priority` (string) - Priority of boot device ("cdrom" or "disk", default is "cdrom". UEFI support need AHV 8.0.12+, 9.1.1.2+, 9.1.3+, 9.2+ or 10.0+).
26-
- `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.
2726
- `vm_categories` ([]Category) - Assign Categories to the vm.
2827
- `project` (string) - Assign Project to the vm.
2928
- `gpu` ([] GPU) - GPU in cluster name to be attached on temporary VM.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Then, run [`packer init`](https://www.packer.io/docs/commands/init).
3232
packer {
3333
required_plugins {
3434
nutanix = {
35-
version = ">= 0.13.0"
35+
version = ">= 0.13.1"
3636
source = "github.com/nutanix-cloud-native/nutanix"
3737
}
3838
}

builder/nutanix/builder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
6363
},
6464
&stepBuildVM{},
6565
&stepVNCConnect{
66-
VNCEnabled: !b.config.DisableVNC,
67-
ClusterConfig: &b.config.ClusterConfig,
66+
Config: &b.config,
6867
},
6968
&stepVNCBootCommand{
7069
Config: &b.config,

builder/nutanix/config.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
282282
c.CommConfig.SSHTimeout = 20 * time.Minute
283283
}
284284

285-
// Define default ip_wait_timeout to 15 min
286-
if c.WaitTimeout == 0 {
287-
c.WaitTimeout = 15 * time.Minute
288-
}
289-
290285
errs = packersdk.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
291286
errs = packersdk.MultiErrorAppend(errs, c.CDConfig.Prepare(&c.ctx)...)
292287
errs = packersdk.MultiErrorAppend(errs, c.CommConfig.Prepare(&c.ctx)...)

builder/nutanix/driver.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -662,15 +662,20 @@ func (d *NutanixDriver) WaitForIP(ctx context.Context, uuid string, ipNet *net.I
662662

663663
var IPAddress string
664664

665-
vm, err := conn.V3.GetVM(ctx, uuid)
666-
if err != nil {
667-
log.Printf("error getting vm: %s", err.Error())
668-
return "", err
669-
}
670-
671-
if len(vm.Status.Resources.NicList[0].IPEndpointList) == (0) {
672-
log.Printf("vm (%s) not configured with ip address", uuid)
673-
return "", fmt.Errorf("no IP endpoints found for VM with UUID %s", uuid)
665+
var vm *v3.VMIntentResponse
666+
for {
667+
vm, err = conn.V3.GetVM(ctx, uuid)
668+
if err != nil {
669+
log.Printf("error getting vm: %s", err.Error())
670+
return "", err
671+
}
672+
if len(vm.Status.Resources.NicList) > 0 &&
673+
len(vm.Status.Resources.NicList[0].IPEndpointList) > 0 &&
674+
vm.Status.Resources.NicList[0].IPEndpointList[0].IP != nil &&
675+
*vm.Status.Resources.NicList[0].IPEndpointList[0].IP != "" {
676+
break
677+
}
678+
time.Sleep(5 * time.Second)
674679
}
675680

676681
IPAddress = *vm.Status.Resources.NicList[0].IPEndpointList[0].IP

builder/nutanix/step_vnc_boot_command.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type stepVNCBootCommand struct {
1818
}
1919

2020
func (s *stepVNCBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
21+
if s.Config.BootCommand == nil {
22+
return multistep.ActionContinue
23+
}
24+
2125
if s.Config.DisableVNC {
2226
log.Println("Skipping boot command step...")
2327
return multistep.ActionContinue

builder/nutanix/step_vnc_connect.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ import (
1919
)
2020

2121
type stepVNCConnect struct {
22-
VNCEnabled bool
23-
InsecureConnection bool
24-
ClusterConfig *ClusterConfig
22+
Config *Config
2523
}
2624

2725
func (s *stepVNCConnect) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
28-
if !s.VNCEnabled {
26+
ui := state.Get("ui").(packer.Ui)
27+
28+
if s.Config.BootCommand == nil {
29+
return multistep.ActionContinue
30+
}
31+
32+
if s.Config.DisableVNC {
2933
return multistep.ActionContinue
3034
}
31-
ui := state.Get("ui").(packer.Ui)
3235

3336
var c *vnc.ClientConn
3437
var err error
@@ -48,6 +51,7 @@ func (s *stepVNCConnect) Run(ctx context.Context, state multistep.StateBag) mult
4851
}
4952

5053
func (s *stepVNCConnect) ConnectVNCOverWebsocketClient(state multistep.StateBag) (*vnc.ClientConn, error) {
54+
5155
log.Printf("retrieving auth cookie for VNC connection...")
5256
cookie, err := s.getAuthCookie(state)
5357
if err != nil {
@@ -57,7 +61,7 @@ func (s *stepVNCConnect) ConnectVNCOverWebsocketClient(state multistep.StateBag)
5761
vmUUID := state.Get("vm_uuid").(string)
5862
clusterUUID := state.Get("cluster_uuid").(string)
5963

60-
wsURL := fmt.Sprintf("wss://%s:%d/vnc/vm/%s/proxy?proxyClusterUuid=%s", s.ClusterConfig.Endpoint, s.ClusterConfig.Port, vmUUID, clusterUUID)
64+
wsURL := fmt.Sprintf("wss://%s:%d/vnc/vm/%s/proxy?proxyClusterUuid=%s", s.Config.ClusterConfig.Endpoint, s.Config.ClusterConfig.Port, vmUUID, clusterUUID)
6165

6266
// Parse the URL
6367
u, err := url.Parse(wsURL)
@@ -82,7 +86,7 @@ func (s *stepVNCConnect) ConnectVNCOverWebsocketClient(state multistep.StateBag)
8286
wsConfig.Header.Set("Cookie", strings.Join(cookieHeader, "; "))
8387

8488
wsConfig.TlsConfig = &tls.Config{
85-
InsecureSkipVerify: s.ClusterConfig.Insecure,
89+
InsecureSkipVerify: s.Config.ClusterConfig.Insecure,
8690
}
8791

8892
// Connect to the WebSocket server
@@ -110,18 +114,18 @@ func (s *stepVNCConnect) ConnectVNCOverWebsocketClient(state multistep.StateBag)
110114

111115
func (s *stepVNCConnect) getAuthCookie(state multistep.StateBag) ([]*http.Cookie, error) {
112116

113-
loginURL := fmt.Sprintf("https://%s:%d/api/nutanix/v3/users/me", s.ClusterConfig.Endpoint, s.ClusterConfig.Port)
117+
loginURL := fmt.Sprintf("https://%s:%d/api/nutanix/v3/users/me", s.Config.ClusterConfig.Endpoint, s.Config.ClusterConfig.Port)
114118

115119
req, err := http.NewRequest("GET", loginURL, nil)
116120
if err != nil {
117121
return nil, fmt.Errorf("failed to create request: %v", err)
118122
}
119123
req.Header.Add("Content-Type", "application/json")
120-
req.SetBasicAuth(s.ClusterConfig.Username, s.ClusterConfig.Password)
124+
req.SetBasicAuth(s.Config.ClusterConfig.Username, s.Config.ClusterConfig.Password)
121125

122126
// Create a custom HTTP client that skips SSL verification
123127
tr := &http.Transport{
124-
TLSClientConfig: &tls.Config{InsecureSkipVerify: s.ClusterConfig.Insecure},
128+
TLSClientConfig: &tls.Config{InsecureSkipVerify: s.Config.ClusterConfig.Insecure},
125129
}
126130

127131
// Create a cookie jar

builder/nutanix/step_wait_for_ip.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ func (s *stepWaitForIp) Run(ctx context.Context, state multistep.StateBag) multi
8585
cancel()
8686
}()
8787

88+
ui.Say("Waiting for IP...")
89+
8890
go func() {
89-
ui.Say("Waiting for IP...")
9091
ip, err = doGetIp(d, vm, sub, s.Config)
9192
waitDone <- true
9293
}()

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To install this plugin, copy and paste this code into your Packer configuration,
99
packer {
1010
required_plugins {
1111
nutanix = {
12-
version = ">= 0.13.0"
12+
version = ">= 0.13.1"
1313
source = "github.com/nutanix-cloud-native/nutanix"
1414
}
1515
}

docs/builders/nutanix.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ These parameters allow to define information about platform and temporary VM use
3232
- `cd_label` (string) - Label of this CD Drive.
3333
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "uefi", default is "legacy").
3434
- `boot_priority` (string) - Priority of boot device ("cdrom" or "disk", default is "cdrom". UEFI support need AHV 8.0.12+, 9.1.1.2+, 9.1.3+, 9.2+ or 10.0+).
35-
- `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.
3635
- `vm_categories` ([]Category) - Assign Categories to the vm.
3736
- `project` (string) - Assign Project to the vm.
3837
- `gpu` ([] GPU) - GPU in cluster name to be attached on temporary VM.

example/init/plugin.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
packer {
22
required_plugins {
33
nutanix = {
4-
version = ">= 0.13.0"
4+
version = ">= 0.13.1"
55
source = "github.com/nutanix-cloud-native/nutanix"
66
}
77
}

version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
var (
88
// Version is the main version number that is being run at the moment.
9-
Version = "0.13.0"
9+
Version = "0.13.1"
1010

1111
// VersionPrerelease is A pre-release marker for the Version. If this is ""
1212
// (empty string) then it means that it is a final release. Otherwise, this

0 commit comments

Comments
 (0)