Skip to content

Commit

Permalink
vetu ip: fix Vetu not finding the VM's IP when --wait is 0 (the defau…
Browse files Browse the repository at this point in the history
…lt) (#26)
  • Loading branch information
edigaryev committed Nov 21, 2023
1 parent 3a8f108 commit d294ee4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions internal/command/ip/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,20 @@ func runIP(cmd *cobra.Command, args []string) error {

hardwareAddr := vmDir.Config().MACAddress.HardwareAddr

waitCtx, waitCtxCancel := context.WithTimeout(cmd.Context(), time.Duration(wait)*time.Second)
defer waitCtxCancel()
retryOpts := []retry.Option{
retry.DelayType(retry.FixedDelay),
retry.Delay(1 * time.Second),
retry.LastErrorOnly(true),
}

if wait == 0 {
retryOpts = append(retryOpts, retry.Context(cmd.Context()), retry.Attempts(1))
} else {
waitCtx, waitCtxCancel := context.WithTimeout(cmd.Context(), time.Duration(wait)*time.Second)
defer waitCtxCancel()

retryOpts = append(retryOpts, retry.Context(waitCtx), retry.Attempts(0))
}

err = retry.Do(func() error {
ip, err := arpTableLookup(hardwareAddr)
Expand All @@ -59,11 +71,7 @@ func runIP(cmd *cobra.Command, args []string) error {
fmt.Println(ip)

return nil
}, retry.Context(waitCtx),
retry.DelayType(retry.FixedDelay),
retry.Delay(1*time.Second),
retry.LastErrorOnly(true),
)
}, retryOpts...)
if errors.Is(err, context.DeadlineExceeded) {
return ErrIPNotFound
}
Expand Down

0 comments on commit d294ee4

Please sign in to comment.