From 84cc1bcea6039e5cfd9cbf8a1faf7a9217d86adb Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 8 May 2024 11:15:17 +0200 Subject: [PATCH] Return an error if no machine connected to switch port. --- cmd/switch.go | 8 ++++++-- docs/metalctl_switch_port_down.md | 2 +- docs/metalctl_switch_port_up.md | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/switch.go b/cmd/switch.go index 3628e47..d9fb46f 100644 --- a/cmd/switch.go +++ b/cmd/switch.go @@ -172,7 +172,7 @@ Operational steps to replace a switch: } switchPortUpCmd := &cobra.Command{ - Use: "up ", + Use: "up ", 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 { @@ -182,7 +182,7 @@ Operational steps to replace a switch: } switchPortDownCmd := &cobra.Command{ - Use: "down ", + Use: "down ", 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 { @@ -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) } diff --git a/docs/metalctl_switch_port_down.md b/docs/metalctl_switch_port_down.md index 5c3fa5e..6ed196f 100644 --- a/docs/metalctl_switch_port_down.md +++ b/docs/metalctl_switch_port_down.md @@ -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 [flags] +metalctl switch port down [flags] ``` ### Options diff --git a/docs/metalctl_switch_port_up.md b/docs/metalctl_switch_port_up.md index fcca5dc..32129a5 100644 --- a/docs/metalctl_switch_port_up.md +++ b/docs/metalctl_switch_port_up.md @@ -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 [flags] +metalctl switch port up [flags] ``` ### Options