From d9251c9bbd8b866d773f137fdebd04838e5ac59b Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 18 Nov 2026 13:37:09 +0100 Subject: [PATCH 1/2] Add more flags for switch connected-machines. --- cmd/admin/v2/switch.go | 12 +++---- cmd/completion/machine.go | 11 +++++- docs/admin/metalctlv2_admin_housekeeping.md | 34 ++++++++++++++++++ ...2_admin_housekeeping_machine-liveliness.md | 35 +++++++++++++++++++ ...v2_admin_housekeeping_machine-resurrect.md | 35 +++++++++++++++++++ ...dmin_housekeeping_machine-vpn-connected.md | 35 +++++++++++++++++++ ...alctlv2_admin_switch_connected-machines.md | 2 ++ 7 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 docs/admin/metalctlv2_admin_housekeeping.md create mode 100644 docs/admin/metalctlv2_admin_housekeeping_machine-liveliness.md create mode 100644 docs/admin/metalctlv2_admin_housekeeping_machine-resurrect.md create mode 100644 docs/admin/metalctlv2_admin_housekeeping_machine-vpn-connected.md diff --git a/cmd/admin/v2/switch.go b/cmd/admin/v2/switch.go index 68e336b..435558c 100644 --- a/cmd/admin/v2/switch.go +++ b/cmd/admin/v2/switch.go @@ -79,18 +79,14 @@ func newSwitchCmd(c *config.Config) *cobra.Command { switchConnectedMachinesCmd.Flags().String("partition", "", "Partition of this switch.") switchConnectedMachinesCmd.Flags().String("rack", "", "Rack of this switch.") switchConnectedMachinesCmd.Flags().Duration("last-event-error-threshold", 1*time.Hour, "the duration up to how long in the past a machine last event error will be counted as an issue [optional]") - - // TODO: add once size and machine completion are implemented - // switchMachinesCmd.Flags().String("size", "", "Size of the connected machines.") - // switchMachinesCmd.Flags().String("machine-id", "", "The id of the connected machine, ignores size flag if set.") + switchConnectedMachinesCmd.Flags().String("machine-id", "", "ID of the connected machine.") + switchConnectedMachinesCmd.Flags().String("size", "", "Size of the connected machines.") genericcli.Must(switchConnectedMachinesCmd.RegisterFlagCompletionFunc("id", c.Completion.Switch)) genericcli.Must(switchConnectedMachinesCmd.RegisterFlagCompletionFunc("partition", c.Completion.SwitchPartition)) genericcli.Must(switchConnectedMachinesCmd.RegisterFlagCompletionFunc("rack", c.Completion.SwitchRack)) - - // TODO: add once size and machine completion are implemented - // genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("size", c.Completion.SizeListCompletion)) - // genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("machine-id", c.Completion.MachineListCompletion)) + genericcli.Must(switchConnectedMachinesCmd.RegisterFlagCompletionFunc("machine-id", c.Completion.AdminMachine)) + genericcli.Must(switchConnectedMachinesCmd.RegisterFlagCompletionFunc("size", c.Completion.Size)) switchConsoleCmd := &cobra.Command{ Use: "console ", diff --git a/cmd/completion/machine.go b/cmd/completion/machine.go index 5f85edb..1bd8b4c 100644 --- a/cmd/completion/machine.go +++ b/cmd/completion/machine.go @@ -28,7 +28,16 @@ func (c *Completion) Machine(cmd *cobra.Command, args []string, toComplete strin } func (c *Completion) AdminMachine(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - resp, err := c.Client.Adminv2().Machine().List(cmd.Context(), &adminv2.MachineServiceListRequest{}) + q := &adminv2.MachineServiceListRequest{} + + // this is a bit rough from the approach, but I have no better idea + if partitionID, _ := cmd.Flags().GetString("partition"); partitionID != "" { + q.Query = &apiv2.MachineQuery{ + Partition: &partitionID, + } + } + + resp, err := c.Client.Adminv2().Machine().List(cmd.Context(), q) if err != nil { return nil, cobra.ShellCompDirectiveError } diff --git a/docs/admin/metalctlv2_admin_housekeeping.md b/docs/admin/metalctlv2_admin_housekeeping.md new file mode 100644 index 0000000..0d9bd3f --- /dev/null +++ b/docs/admin/metalctlv2_admin_housekeeping.md @@ -0,0 +1,34 @@ +## metalctlv2 admin housekeeping + +execute housekeeping commands + +### Synopsis + +housekeeping commands are usually as cronjobs in the control-plane + +### Options + +``` + -h, --help help for housekeeping +``` + +### Options inherited from parent commands + +``` + --api-token string the token used for api requests + --api-url string the url to the metal-stack.io api + -c, --config string alternative config file path, (default is ~/.metal-stack/config.yaml) + --debug debug output + --force-color force colored output even without tty + -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") + --template string output template for template output-format, go template format. For property names inspect the output of -o json or -o yaml for reference. + --timeout duration request timeout used for api requests +``` + +### SEE ALSO + +* [metalctlv2 admin](metalctlv2_admin.md) - admin commands +* [metalctlv2 admin housekeeping machine-liveliness](metalctlv2_admin_housekeeping_machine-liveliness.md) - execute machine liveliness housekeeping +* [metalctlv2 admin housekeeping machine-resurrect](metalctlv2_admin_housekeeping_machine-resurrect.md) - execute machine resurrect housekeeping +* [metalctlv2 admin housekeeping machine-vpn-connected](metalctlv2_admin_housekeeping_machine-vpn-connected.md) - execute machine vpn connected housekeeping + diff --git a/docs/admin/metalctlv2_admin_housekeeping_machine-liveliness.md b/docs/admin/metalctlv2_admin_housekeeping_machine-liveliness.md new file mode 100644 index 0000000..799639b --- /dev/null +++ b/docs/admin/metalctlv2_admin_housekeeping_machine-liveliness.md @@ -0,0 +1,35 @@ +## metalctlv2 admin housekeeping machine-liveliness + +execute machine liveliness housekeeping + +### Synopsis + +updates the liveleness of all machines, only the modified machines are returned + +``` +metalctlv2 admin housekeeping machine-liveliness [flags] +``` + +### Options + +``` + -h, --help help for machine-liveliness +``` + +### Options inherited from parent commands + +``` + --api-token string the token used for api requests + --api-url string the url to the metal-stack.io api + -c, --config string alternative config file path, (default is ~/.metal-stack/config.yaml) + --debug debug output + --force-color force colored output even without tty + -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") + --template string output template for template output-format, go template format. For property names inspect the output of -o json or -o yaml for reference. + --timeout duration request timeout used for api requests +``` + +### SEE ALSO + +* [metalctlv2 admin housekeeping](metalctlv2_admin_housekeeping.md) - execute housekeeping commands + diff --git a/docs/admin/metalctlv2_admin_housekeeping_machine-resurrect.md b/docs/admin/metalctlv2_admin_housekeeping_machine-resurrect.md new file mode 100644 index 0000000..7874824 --- /dev/null +++ b/docs/admin/metalctlv2_admin_housekeeping_machine-resurrect.md @@ -0,0 +1,35 @@ +## metalctlv2 admin housekeeping machine-resurrect + +execute machine resurrect housekeeping + +### Synopsis + +tries to resurrect machines which are not allocated but not in waiting state by forcing a restart, only machines where a restart was triggered are returned + +``` +metalctlv2 admin housekeeping machine-resurrect [flags] +``` + +### Options + +``` + -h, --help help for machine-resurrect +``` + +### Options inherited from parent commands + +``` + --api-token string the token used for api requests + --api-url string the url to the metal-stack.io api + -c, --config string alternative config file path, (default is ~/.metal-stack/config.yaml) + --debug debug output + --force-color force colored output even without tty + -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") + --template string output template for template output-format, go template format. For property names inspect the output of -o json or -o yaml for reference. + --timeout duration request timeout used for api requests +``` + +### SEE ALSO + +* [metalctlv2 admin housekeeping](metalctlv2_admin_housekeeping.md) - execute housekeeping commands + diff --git a/docs/admin/metalctlv2_admin_housekeeping_machine-vpn-connected.md b/docs/admin/metalctlv2_admin_housekeeping_machine-vpn-connected.md new file mode 100644 index 0000000..4dd431c --- /dev/null +++ b/docs/admin/metalctlv2_admin_housekeeping_machine-vpn-connected.md @@ -0,0 +1,35 @@ +## metalctlv2 admin housekeeping machine-vpn-connected + +execute machine vpn connected housekeeping + +### Synopsis + +updates the vpn connection details of machines which have vpn configured, only the modified machines are returned + +``` +metalctlv2 admin housekeeping machine-vpn-connected [flags] +``` + +### Options + +``` + -h, --help help for machine-vpn-connected +``` + +### Options inherited from parent commands + +``` + --api-token string the token used for api requests + --api-url string the url to the metal-stack.io api + -c, --config string alternative config file path, (default is ~/.metal-stack/config.yaml) + --debug debug output + --force-color force colored output even without tty + -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") + --template string output template for template output-format, go template format. For property names inspect the output of -o json or -o yaml for reference. + --timeout duration request timeout used for api requests +``` + +### SEE ALSO + +* [metalctlv2 admin housekeeping](metalctlv2_admin_housekeeping.md) - execute housekeeping commands + diff --git a/docs/admin/metalctlv2_admin_switch_connected-machines.md b/docs/admin/metalctlv2_admin_switch_connected-machines.md index 60d7017..5226ce1 100644 --- a/docs/admin/metalctlv2_admin_switch_connected-machines.md +++ b/docs/admin/metalctlv2_admin_switch_connected-machines.md @@ -18,8 +18,10 @@ The command will show the machines connected to the switch ports. -h, --help help for connected-machines --id string ID of the switch. --last-event-error-threshold duration the duration up to how long in the past a machine last event error will be counted as an issue [optional] (default 1h0m0s) + --machine-id string ID of the connected machine. --partition string Partition of this switch. --rack string Rack of this switch. + --size string Size of the connected machines. ``` ### Options inherited from parent commands From 3de2c6105d8f6c765ea68bd271abf149bc76b004 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 18 Nov 2026 13:45:33 +0100 Subject: [PATCH 2/2] Add test. --- tests/e2e/admin/switch_test.go | 36 +++++++++++++++++++++++++------ tests/e2e/testresources/switch.go | 2 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/tests/e2e/admin/switch_test.go b/tests/e2e/admin/switch_test.go index caac2f8..083f7b1 100644 --- a/tests/e2e/admin/switch_test.go +++ b/tests/e2e/admin/switch_test.go @@ -10,6 +10,7 @@ import ( e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" + "github.com/metal-stack/metal-lib/pkg/pointer" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -194,14 +195,35 @@ func Test_AdminSwitchCmd_Update(t *testing.T) { func Test_AdminSwitchCmd_ConnectedMachines(t *testing.T) { tests := []*e2e.Test[adminv2.SwitchServiceConnectedMachinesResponse, *apiv2.Switch]{ { - Name: "connected machines", - CmdArgs: []string{"admin", "switch", "connected-machines"}, + Name: "connected machines", + CmdArgs: []string{ + "admin", + "switch", + "connected-machines", + "--id", testresources.Switch1().Id, + "--machine-id", testresources.SwitchWithMachines1().Connections[0].Machine.Uuid, + "--partition", testresources.Switch1().Partition, + "--rack", pointer.SafeDeref(testresources.Switch1().Rack), + "--size", testresources.SwitchWithMachines1().Connections[0].Machine.Size.Id, + "--last-event-error-threshold=8h", + }, + AssertExhaustiveArgs: true, NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.SwitchServiceConnectedMachinesRequest{ - Query: &apiv2.SwitchQuery{}, - MachineQuery: &apiv2.MachineQuery{}, + Query: &apiv2.SwitchQuery{ + Partition: &testresources.Switch1().Partition, + Id: &testresources.Switch1().Id, + Rack: testresources.Switch1().Rack, + ConnectedMachineId: nil, // TODO: Clarify if this can be used (?) + }, + MachineQuery: &apiv2.MachineQuery{ + Uuid: &testresources.SwitchWithMachines1().Connections[0].Machine.Uuid, + Partition: &testresources.Switch1().Partition, + Size: &testresources.SwitchWithMachines1().Connections[0].Machine.Size.Id, + Rack: testresources.Switch1().Rack, + }, }, WantResponse: func() connect.AnyResponse { return connect.NewResponse(&adminv2.SwitchServiceConnectedMachinesResponse{ @@ -212,9 +234,9 @@ func Test_AdminSwitchCmd_ConnectedMachines(t *testing.T) { }, }), WantTable: new(` - ID NIC NAME IDENTIFIER PARTITION RACK SIZE PRODUCT SERIAL CHASSIS SERIAL - leaf01 fra-equ01 rack-1 - └─╴id1 Ethernet0 (up) oid:0x1000000000001 fra-equ01 rack-1 m1-small ps-1 cs-1 + ID NIC NAME IDENTIFIER PARTITION RACK SIZE PRODUCT SERIAL CHASSIS SERIAL + leaf01 fra-equ01 rack-1 + └─╴d1a30c48-f2a7-4b6b-955c-579d93c67677 Ethernet0 (up) oid:0x1000000000001 fra-equ01 rack-1 m1-small ps-1 cs-1 `), }, } diff --git a/tests/e2e/testresources/switch.go b/tests/e2e/testresources/switch.go index cfbc230..d8d5585 100644 --- a/tests/e2e/testresources/switch.go +++ b/tests/e2e/testresources/switch.go @@ -126,7 +126,7 @@ var ( { Nic: Switch1().Nics[0], Machine: &apiv2.Machine{ - Uuid: "id1", + Uuid: "d1a30c48-f2a7-4b6b-955c-579d93c67677", Partition: &apiv2.Partition{ Id: Switch1().Partition, },