Skip to content

Commit

Permalink
add wait flag
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4c6565 committed Jul 1, 2021
1 parent 2cca756 commit 7bde779
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/ecloud/ecloud_floatingip.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func ecloudFloatingIPAssignCmd(f factory.ClientFactory) *cobra.Command {

cmd.Flags().String("resource", "", "ID of resource to assign")
cmd.MarkFlagRequired("resource")
cmd.Flags().Bool("wait", false, "Specifies that the command should wait until the floating IP has been completely created before continuing on")
cmd.Flags().Bool("wait", false, "Specifies that the command should wait until the floating IP has been completely assigned before continuing on")

return cmd
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func ecloudFloatingIPAssign(service ecloud.ECloudService, cmd *cobra.Command, ar
}

func ecloudFloatingIPUnassignCmd(f factory.ClientFactory) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "unassign <fip: id>...",
Short: "Unassigns a floating IP",
Long: "This command unassigns one or more floating IPs from connected resources",
Expand All @@ -272,13 +272,26 @@ func ecloudFloatingIPUnassignCmd(f factory.ClientFactory) *cobra.Command {
},
RunE: ecloudCobraRunEFunc(f, ecloudFloatingIPUnassign),
}

cmd.Flags().Bool("wait", false, "Specifies that the command should wait until the floating IP has been completely unassigned before continuing on")

return cmd
}

func ecloudFloatingIPUnassign(service ecloud.ECloudService, cmd *cobra.Command, args []string) error {
for _, arg := range args {
err := service.UnassignFloatingIP(arg)
if err != nil {
output.OutputWithErrorLevelf("Error unassigning floating IP [%s]: %s", arg, err)
continue
}

waitFlag, _ := cmd.Flags().GetBool("wait")
if waitFlag {
err := helper.WaitForCommand(FloatingIPResourceSyncStatusWaitFunc(service, arg, ecloud.SyncStatusComplete))
if err != nil {
return fmt.Errorf("Error waiting for floating IP [%s] sync: %s", arg, err)
}
}
}
return nil
Expand Down

0 comments on commit 7bde779

Please sign in to comment.