Skip to content

Commit

Permalink
Add force flag to switch deletion (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar authored Jul 12, 2024
1 parent 178be81 commit ad8a8bb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metalctl/cmd/sorters"
"github.com/metal-stack/metalctl/cmd/tableprinters"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -59,6 +60,9 @@ func newSwitchCmd(c *config) *cobra.Command {
genericcli.Must(cmd.RegisterFlagCompletionFunc("os-vendor", c.comp.SwitchOSVendorListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("os-version", c.comp.SwitchOSVersionListCompletion))
},
DeleteCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().Bool("force", false, "forcefully delete the switch accepting the risk that it still has machines connected to it")
},
}

switchDetailCmd := &cobra.Command{
Expand Down Expand Up @@ -222,7 +226,7 @@ func (c switchCmd) List() ([]*models.V1SwitchResponse, error) {
}

func (c switchCmd) Delete(id string) (*models.V1SwitchResponse, error) {
resp, err := c.client.SwitchOperations().DeleteSwitch(switch_operations.NewDeleteSwitchParams().WithID(id), nil)
resp, err := c.client.SwitchOperations().DeleteSwitch(switch_operations.NewDeleteSwitchParams().WithID(id).WithForce(pointer.Pointer(viper.GetBool("force"))), nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST S
},
mocks: &client.MetalMockFns{
SwitchOperations: func(mock *mock.Mock) {
mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID)), nil).Return(&switch_operations.DeleteSwitchOK{
mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID).WithForce(pointer.Pointer(false))), nil).Return(&switch_operations.DeleteSwitchOK{
Payload: switch1,
}, nil)
},
Expand Down Expand Up @@ -387,7 +387,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST S
},
mocks: &client.MetalMockFns{
SwitchOperations: func(mock *mock.Mock) {
mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID)), nil).Return(&switch_operations.DeleteSwitchOK{
mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID).WithForce(pointer.Pointer(false))), nil).Return(&switch_operations.DeleteSwitchOK{
Payload: switch1,
}, nil)
},
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_switch_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ metalctl switch delete <id> [flags]
the file can also contain multiple documents and perform a bulk operation.
--force forcefully delete the switch accepting the risk that it still has machines connected to it
-h, --help help for delete
--skip-security-prompts skips security prompt for bulk operations
--timestamps when used with --file (bulk operation): prints timestamps in-between the operations
Expand Down

0 comments on commit ad8a8bb

Please sign in to comment.