From 6f430690a8e4cdca7d83cefa23b38b8f1b853e2f Mon Sep 17 00:00:00 2001 From: Lee Spottiswood Date: Thu, 1 Jul 2021 09:20:01 +0100 Subject: [PATCH] fix fip wait command --- cmd/ecloud/ecloud_floatingip.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/ecloud/ecloud_floatingip.go b/cmd/ecloud/ecloud_floatingip.go index 5057e6d..acc9abc 100644 --- a/cmd/ecloud/ecloud_floatingip.go +++ b/cmd/ecloud/ecloud_floatingip.go @@ -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 } } @@ -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 + } +}