This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright © 2023 Miguel Angel Ajo Pelayo <[email protected] | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/fatih/color" | ||
"github.com/redhat-et/jumpstarter/pkg/harness" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// powerCmd represents the listDevices command | ||
var powerCmd = &cobra.Command{ | ||
Use: "power", | ||
Short: "Powers control for devices", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cobra.MinimumNArgs(2)(cmd, args); err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
|
||
action := args[0] | ||
device_id := args[1] | ||
|
||
driver := cmd.Flag("driver").Value.String() | ||
console, _ := cmd.Flags().GetBool("console") | ||
reset, _ := cmd.Flags().GetBool("reset") | ||
attach_storage, _ := cmd.Flags().GetBool("attach-storage") | ||
|
||
device, err := harness.FindDevice(driver, device_id) | ||
handleErrorAsFatal(err) | ||
|
||
color.Set(COLOR_CMD_INFO) | ||
fmt.Printf("🔌 Power action %s on %s ... ", action, device_id) | ||
color.Unset() | ||
|
||
err = device.Power(action) | ||
handleErrorAsFatal(err) | ||
|
||
color.Set(COLOR_CMD_INFO) | ||
fmt.Println("done") | ||
color.Unset() | ||
|
||
if attach_storage { | ||
color.Set(COLOR_CMD_INFO) | ||
fmt.Printf("💾 Attaching storage for %s ... ", device_id) | ||
color.Unset() | ||
err = device.AttachStorage(true) | ||
handleErrorAsFatal(err) | ||
color.Set(COLOR_CMD_INFO) | ||
fmt.Println("done") | ||
color.Unset() | ||
} | ||
|
||
if reset { | ||
resetDevice(device, args[0]) | ||
} | ||
|
||
if console { | ||
serialConsole(device) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(powerCmd) | ||
powerCmd.Flags().StringP("driver", "d", "", "Only list devices for the specified driver") | ||
powerCmd.Flags().BoolP("console", "c", false, "Open console terminal after powering on") | ||
powerCmd.Flags().BoolP("reset", "r", false, "Reset device after power up") | ||
powerCmd.Flags().BoolP("attach-storage", "a", false, "Attach storage before powering on") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright © 2023 Miguel Angel Ajo Pelayo <[email protected] | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/fatih/color" | ||
"github.com/redhat-et/jumpstarter/pkg/harness" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// powerCmd represents the listDevices command | ||
var setConfig = &cobra.Command{ | ||
Use: "set-config", | ||
Short: "Changes a device config parameter", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cobra.MinimumNArgs(3)(cmd, args); err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
|
||
device_id := args[0] | ||
k := strings.ToLower(args[1]) | ||
v := args[2] | ||
|
||
driver := cmd.Flag("driver").Value.String() | ||
device, err := harness.FindDevice(driver, device_id) | ||
handleErrorAsFatal(err) | ||
color.Set(COLOR_CMD_INFO) | ||
fmt.Printf("✍ Changing device setting for %s > %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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters