Skip to content

Commit

Permalink
Return an error if no machine connected to switch port. (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored May 8, 2024
1 parent 14952c4 commit f9c3071
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
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

0 comments on commit f9c3071

Please sign in to comment.