Skip to content

Commit

Permalink
remove soft-reset mode
Browse files Browse the repository at this point in the history
rename reload mode to reboot

Signed-off-by: Pau Capdevila <[email protected]>
  • Loading branch information
pau-hedgehog committed Jan 2, 2025
1 parent 91bebff commit 9e3a681
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
14 changes: 7 additions & 7 deletions cmd/hhfab/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,16 +873,16 @@ func Run(ctx context.Context) error {
},
&cli.StringFlag{
Name: "mode",
Usage: "restart mode: reload, soft-reset, or hard-reset",
Value: "reload",
Usage: "restart mode: reboot or hard-reset",
Value: "reboot",
},
&cli.StringFlag{
Name: "username",
Usage: "required for reload mode (if empty, user is prompted)",
Usage: "required for reboot mode (if empty, user is prompted)",
},
&cli.StringFlag{
Name: "password",
Usage: "required for reload mode (if empty, user is prompted)",
Usage: "required for reboot mode (if empty, user is prompted)",
},
yesFlag,
},
Expand All @@ -896,7 +896,7 @@ func Run(ctx context.Context) error {
}

mode := c.String("mode")
validModes := map[string]bool{"reload": true, "soft-reset": true, "hard-reset": true}
validModes := map[string]bool{"reboot": true, "hard-reset": true}
if !validModes[mode] {
return fmt.Errorf("invalid mode: %s", mode) //nolint:goerr113
}
Expand All @@ -907,7 +907,7 @@ func Run(ctx context.Context) error {

username := c.String("username")
password := c.String("password")
if mode == "reload" && (username == "" || password == "") {
if mode == "reboot" && (username == "" || password == "") {
fmt.Print("Enter username: ")
if _, err := fmt.Scanln(&username); err != nil {
return fmt.Errorf("failed to read username: %w", err)
Expand All @@ -921,7 +921,7 @@ func Run(ctx context.Context) error {
fmt.Println()

if username == "" || password == "" {
return fmt.Errorf("credentials required for reload mode") //nolint:goerr113
return fmt.Errorf("credentials required for reboot mode") //nolint:goerr113
}
}

Expand Down
19 changes: 5 additions & 14 deletions pkg/hhfab/vlabhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,16 @@ func (c *Config) SwitchReinstall(ctx context.Context, name, mode, user, password
cmd.Stdin = os.Stdin
var args []string

if mode == "reload" {
if mode == "reboot" {
args = []string{sw.Name, user, password}
}
if mode == "soft-reset" || mode == "hard-reset" {
if mode == "hard-reset" {
args = []string{sw.Name}
}

if verbose {
_, err := exec.LookPath("byobu")
if err == nil {
// byobu exists, use it to run the command
if _, err := exec.LookPath("byobu"); err == nil && name == AllSwitches {
// use byobu to show progress in separate tabs
byobuCmd := fmt.Sprintf("byobu new-window -d -n %s '%s %s'", sw.Name, cmdName, strings.Join(args, " "))
cmd = exec.CommandContext(ctx, "sh", "-c", byobuCmd)
cmd.Stdout = os.Stdout
Expand Down Expand Up @@ -371,14 +370,6 @@ func (c *Config) SwitchReinstall(ctx context.Context, name, mode, user, password
_ = c.VLABPower(ctx, sw.Name, "CYCLE", pduConf)
}
}

if mode == "soft-reset" {
for _, sw := range targets {
time.Sleep(1 * time.Second)
slog.Info("Executing soft-reset on", "switch", sw.Name+"...")
_ = hhfctl.SwitchPowerReset(ctx, sw.Name)
}
}
wg.Wait()

if len(errs) > 0 {
Expand Down Expand Up @@ -459,7 +450,7 @@ func (c *Config) VLABPower(ctx context.Context, name string, action string, pduC

continue
}
slog.Info("Performing power", "action", action, "on switch", swName, "psu", psuName)
slog.Debug("Performing power", "action", action, "on switch", swName, "psu", psuName)
if err := netio.ControlOutlet(ctx, pduIP, creds.User, creds.Password, outletID, action); err != nil {
return fmt.Errorf("failed to power %s switch %s %s: %w", action, swName, psuName, err)
}
Expand Down

0 comments on commit 9e3a681

Please sign in to comment.