From ad8a8bba859d55665f24a7eb076f084d42a24e68 Mon Sep 17 00:00:00 2001 From: Ilja Rotar <77339620+iljarotar@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:47:49 +0200 Subject: [PATCH 1/2] Add force flag to switch deletion (#254) --- cmd/switch.go | 6 +++++- cmd/switch_test.go | 4 ++-- docs/metalctl_switch_delete.md | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/switch.go b/cmd/switch.go index d9fb46f5..58927825 100644 --- a/cmd/switch.go +++ b/cmd/switch.go @@ -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" @@ -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{ @@ -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 } diff --git a/cmd/switch_test.go b/cmd/switch_test.go index 41934bca..da16d9ba 100644 --- a/cmd/switch_test.go +++ b/cmd/switch_test.go @@ -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) }, @@ -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) }, diff --git a/docs/metalctl_switch_delete.md b/docs/metalctl_switch_delete.md index 791b19dd..0d4b62d0 100644 --- a/docs/metalctl_switch_delete.md +++ b/docs/metalctl_switch_delete.md @@ -22,6 +22,7 @@ metalctl switch delete [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 From e616e8a89b2aa3fc2ed9c7c003940640592394a9 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Tue, 30 Jul 2024 11:32:43 +0200 Subject: [PATCH 2/2] Allow sorting IPs by creation date. (#257) --- .github/workflows/docker.yaml | 2 +- cmd/sorters/ip.go | 4 ++++ docs/metalctl_network_ip_list.md | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 476e31cf..f151efc8 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -31,7 +31,7 @@ jobs: cache: false - name: Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: args: --build-tags integration -p bugs -p unused --timeout=5m diff --git a/cmd/sorters/ip.go b/cmd/sorters/ip.go index dd958887..5bafb0fc 100644 --- a/cmd/sorters/ip.go +++ b/cmd/sorters/ip.go @@ -2,6 +2,7 @@ package sorters import ( "net/netip" + "time" "github.com/metal-stack/metal-go/api/models" "github.com/metal-stack/metal-lib/pkg/multisort" @@ -32,5 +33,8 @@ func IPSorter() *multisort.Sorter[*models.V1IPResponse] { "type": func(a, b *models.V1IPResponse, descending bool) multisort.CompareResult { return multisort.Compare(p.SafeDeref(a.Type), p.SafeDeref(b.Type), descending) }, + "age": func(a, b *models.V1IPResponse, descending bool) multisort.CompareResult { + return multisort.Compare(time.Time(a.Created).Unix(), time.Time(b.Created).Unix(), descending) + }, }, multisort.Keys{{ID: "ipaddress"}}) } diff --git a/docs/metalctl_network_ip_list.md b/docs/metalctl_network_ip_list.md index 6b196fe6..3acfee4c 100644 --- a/docs/metalctl_network_ip_list.md +++ b/docs/metalctl_network_ip_list.md @@ -16,7 +16,7 @@ metalctl network ip list [flags] --network string network to filter [optional] --prefix string prefix to filter [optional] --project string project to filter [optional] - --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: description|id|ipaddress|name|network|type + --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: age|description|id|ipaddress|name|network|type --tags strings tags to filter [optional] --type string type to filter [optional] ```