Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions cmd/admin/v2/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id>",
Expand Down
11 changes: 10 additions & 1 deletion cmd/completion/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
34 changes: 34 additions & 0 deletions docs/admin/metalctlv2_admin_housekeeping.md
Original file line number Diff line number Diff line change
@@ -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

35 changes: 35 additions & 0 deletions docs/admin/metalctlv2_admin_housekeeping_machine-liveliness.md
Original file line number Diff line number Diff line change
@@ -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

35 changes: 35 additions & 0 deletions docs/admin/metalctlv2_admin_housekeeping_machine-resurrect.md
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions docs/admin/metalctlv2_admin_switch_connected-machines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 29 additions & 7 deletions tests/e2e/admin/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 (?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iljarotar I am not sure about this? And should there really be two queries in this request?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think we should remove the ConnectedMachineId from the query.

},
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{
Expand All @@ -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
`),
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/testresources/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Loading