Skip to content

Commit

Permalink
Add switch migrate command
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Sep 12, 2024
1 parent 4b7b53c commit 8fb9e0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
25 changes: 24 additions & 1 deletion cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ Operational steps to replace a switch:
},
ValidArgsFunction: c.comp.SwitchListCompletion,
}
switchMigrateCmd := &cobra.Command{
Use: "migrate <oldSwitchID> <newSwitchID>",
Short: "migrate machine connections and other configuration from one switch to another",
ValidArgsFunction: c.comp.SwitchListCompletion,
RunE: func(cmd *cobra.Command, args []string) error {
return w.switchMigrate(args)
},
}
switchSSHCmd := &cobra.Command{
Use: "ssh <switchID>",
Short: "connect to the switch via ssh",
Expand Down Expand Up @@ -197,7 +205,7 @@ Operational steps to replace a switch:

switchPortCmd.AddCommand(switchPortUpCmd, switchPortDownCmd, switchPortDescribeCmd)

return genericcli.NewCmds(cmdsConfig, switchDetailCmd, switchMachinesCmd, switchReplaceCmd, switchSSHCmd, switchConsoleCmd, switchPortCmd)
return genericcli.NewCmds(cmdsConfig, switchDetailCmd, switchMachinesCmd, switchReplaceCmd, switchMigrateCmd, switchSSHCmd, switchConsoleCmd, switchPortCmd)
}

func (c switchCmd) Get(id string) (*models.V1SwitchResponse, error) {
Expand Down Expand Up @@ -376,6 +384,21 @@ func (c *switchCmd) switchReplace(args []string) error {
return c.describePrinter.Print(uresp)
}

func (c switchCmd) switchMigrate(args []string) error {
if count := len(args); count != 2 {
return fmt.Errorf("invalid number of arguments were provided; 2 are required, %d were passed", count)
}

resp, err := c.client.SwitchOperations().MigrateSwitch(switch_operations.NewMigrateSwitchParams().WithBody(&models.V1SwitchMigrateRequest{
OldSwitchID: pointer.Pointer(args[0]),
NewSwitchID: pointer.Pointer(args[1]),
}), nil)
if err != nil {
return err
}
return c.describePrinter.Print(resp)
}

func (c *switchCmd) switchSSH(args []string) error {
id, err := genericcli.GetExactlyOneArg(args)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/go-openapi/strfmt v0.23.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/metal-stack/metal-go v0.34.0
github.com/metal-stack/metal-go v0.34.2-0.20240912085352-09f83415a452
github.com/metal-stack/metal-lib v0.17.1
github.com/metal-stack/updater v1.2.2
github.com/metal-stack/v v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ
github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/metal-stack/metal-go v0.34.0 h1:X4Wlt2OAhsu3Lq+rHSWnWeASmX6CYvOxnL6DxmjnzbU=
github.com/metal-stack/metal-go v0.34.0/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/metal-go v0.34.2-0.20240912085352-09f83415a452 h1:p3UTyorRtrRbk6FJfd65uSQ4e76VkVSe9KmQFSI8UWU=
github.com/metal-stack/metal-go v0.34.2-0.20240912085352-09f83415a452/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/metal-lib v0.17.1 h1:JLa4wJ62dgxtY9UOLF+QDk10/i/W5vhzrv8RsundDUY=
github.com/metal-stack/metal-lib v0.17.1/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s=
github.com/metal-stack/security v0.8.1 h1:4zmVUxZvDWShVvVIxM3XhIv7pTmPe9DvACRIHW6YTsk=
Expand Down

0 comments on commit 8fb9e0c

Please sign in to comment.