Skip to content

Commit

Permalink
fix fip wait command
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4c6565 committed Jul 1, 2021
1 parent 3d499b6 commit 6f43069
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions cmd/ecloud/ecloud_floatingip.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ func ecloudFloatingIPDelete(service ecloud.ECloudService, cmd *cobra.Command, ar

waitFlag, _ := cmd.Flags().GetBool("wait")
if waitFlag {
err := helper.WaitForCommand(FloatingIPResourceSyncStatusWaitFunc(service, arg, ecloud.SyncStatusComplete))
err := helper.WaitForCommand(FloatingIPNotFoundWaitFunc(service, arg))
if err != nil {
output.OutputWithErrorLevelf("Error waiting for floating IP [%s] sync: %s", arg, err)
output.OutputWithErrorLevelf("Error waiting for removal of floating IP [%s]: %s", arg, err)
continue
}
}
Expand Down Expand Up @@ -331,3 +331,19 @@ func FloatingIPResourceSyncStatusWaitFunc(service ecloud.ECloudService, fipID st
return fip.Sync.Status, nil
}, status)
}

func FloatingIPNotFoundWaitFunc(service ecloud.ECloudService, fipID string) helper.WaitFunc {
return func() (finished bool, err error) {
_, err = service.GetFloatingIP(fipID)
if err != nil {
switch err.(type) {
case *ecloud.FloatingIPNotFoundError:
return true, nil
default:
return false, fmt.Errorf("Failed to retrieve floating IP [%s]: %s", fipID, err)
}
}

return false, nil
}
}

0 comments on commit 6f43069

Please sign in to comment.