Skip to content

Commit

Permalink
Add force flag to switch deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Jul 5, 2024
1 parent e922dcf commit c9e5a8a
Show file tree
Hide file tree
Showing 3 changed files with 7 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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,5 @@ require (
sigs.k8s.io/yaml v1.4.0 // indirect
tailscale.com v1.54.1 // indirect
)

replace github.com/metal-stack/metal-go v0.32.0 => ../metal-go
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ
github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/metal-stack/metal-go v0.32.0 h1:8wpKkyx36qw4oKB0tt/95uENrw40DkCFbjq7bFz3KMs=
github.com/metal-stack/metal-go v0.32.0/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/metal-lib v0.17.0 h1:0fCRUtYweJ5wbUwiEalFGiHkEz0mZwTWQUIIo3Npzkw=
github.com/metal-stack/metal-lib v0.17.0/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s=
github.com/metal-stack/security v0.8.0 h1:tVaSDB9m5clwYrnLyaXfPy7mQlJTnmeoHscG+RUy/xo=
Expand Down

0 comments on commit c9e5a8a

Please sign in to comment.