From 75b351d35866e71eeccfbd2f7d21587d4b97a472 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Tue, 10 Oct 2023 17:37:12 +0200 Subject: [PATCH] Add set-config parameter --- cmd/power.go | 73 +++++++++++++++++++++++++ cmd/setConfig.go | 48 ++++++++++++++++ pkg/drivers/jumpstarter-board/config.go | 17 ++++++ pkg/harness/device.go | 1 + 4 files changed, 139 insertions(+) create mode 100644 cmd/power.go create mode 100644 cmd/setConfig.go diff --git a/cmd/power.go b/cmd/power.go new file mode 100644 index 0000000..5ce099c --- /dev/null +++ b/cmd/power.go @@ -0,0 +1,73 @@ +/* +Copyright © 2023 Miguel Angel Ajo Pelayo %s=%s ... ", device_id, k, v) + color.Unset() + + err = device.SetConfig(k, v) + handleErrorAsFatal(err) + + color.Set(COLOR_CMD_INFO) + fmt.Println("done") + color.Unset() + }, +} + +func init() { + rootCmd.AddCommand(setConfig) + setConfig.Flags().StringP("driver", "d", "", "Only list devices for the specified driver") +} diff --git a/pkg/drivers/jumpstarter-board/config.go b/pkg/drivers/jumpstarter-board/config.go index c4c4391..7b38434 100644 --- a/pkg/drivers/jumpstarter-board/config.go +++ b/pkg/drivers/jumpstarter-board/config.go @@ -86,6 +86,23 @@ func (d *JumpstarterDevice) readConfig() error { return nil } +func (d *JumpstarterDevice) SetConfig(k, v string) error { + k = strings.ToLower(k) + if err := d.ensureSerial(); err != nil { + return fmt.Errorf("SetConfig(%v, %v): %w", k, v, err) + } + + if err := d.exitConsole(); err != nil { + return fmt.Errorf("SetConfig(%v, %v): %w", k, v, err) + } + + if err := d.sendAndExpect("set-config "+k+" "+v, "Set "+k+" to "+v); err != nil { + return fmt.Errorf("SetConfig(%v, %v) %w", k, v, err) + } + + return nil +} + func (d *JumpstarterDevice) SetName(name string) error { if err := d.ensureSerial(); err != nil { return fmt.Errorf("SetName(%v): %w", name, err) diff --git a/pkg/harness/device.go b/pkg/harness/device.go index 55fe0c5..7d8edbe 100644 --- a/pkg/harness/device.go +++ b/pkg/harness/device.go @@ -22,6 +22,7 @@ type Device interface { SetName(name string) error // set the name of the device, should be stored in config or flashed to device SetUsbConsole(name string) error // set the substring of an out of band console name for this device SetTags(tags []string) error + SetConfig(k, v string) error Serial() (string, error) SetDiskImage(path string, offset uint64) error AttachStorage(connect bool) error