Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return an error if no machine connected to switch port. #244

Merged
merged 1 commit into from
May 8, 2024
Merged
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
8 changes: 6 additions & 2 deletions cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Operational steps to replace a switch:
}

switchPortUpCmd := &cobra.Command{
Use: "up <machine ID>",
Use: "up <switch ID>",
Short: "sets the given switch port state up",
Long: "sets the port status to UP so the connected machine will be able to connect to the switch.",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -182,7 +182,7 @@ Operational steps to replace a switch:
}

switchPortDownCmd := &cobra.Command{
Use: "down <machine ID>",
Use: "down <switch ID>",
Short: "sets the given switch port state down",
Long: "sets the port status to DOWN so the connected machine will not be able to connect to the switch.",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -482,6 +482,10 @@ func (c *switchCmd) dumpPortState(rsp *models.V1SwitchResponse, portid string) e
}
}

if state.Actual.Nic == nil {
return fmt.Errorf("no machine connected to port %s on switch %s", portid, *rsp.ID)
}

return c.describePrinter.Print(state)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/metalctl_switch_port_down.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sets the given switch port state down
sets the port status to DOWN so the connected machine will not be able to connect to the switch.

```
metalctl switch port down <machine ID> [flags]
metalctl switch port down <switch ID> [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/metalctl_switch_port_up.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sets the given switch port state up
sets the port status to UP so the connected machine will be able to connect to the switch.

```
metalctl switch port up <machine ID> [flags]
metalctl switch port up <switch ID> [flags]
```

### Options
Expand Down
Loading