From 8fb9e0c0aa2f4fa1f0991bdd1dffc1126eb3b4bc Mon Sep 17 00:00:00 2001 From: iljarotar Date: Thu, 12 Sep 2024 11:24:33 +0200 Subject: [PATCH] Add switch migrate command --- cmd/switch.go | 25 ++++++++++++++++++++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/cmd/switch.go b/cmd/switch.go index 5892782..1d2950d 100644 --- a/cmd/switch.go +++ b/cmd/switch.go @@ -139,6 +139,14 @@ Operational steps to replace a switch: }, ValidArgsFunction: c.comp.SwitchListCompletion, } + switchMigrateCmd := &cobra.Command{ + Use: "migrate ", + 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 ", Short: "connect to the switch via ssh", @@ -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) { @@ -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 { diff --git a/go.mod b/go.mod index 2e45f52..d7e9053 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 3402422..92282de 100644 --- a/go.sum +++ b/go.sum @@ -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=