Skip to content

Commit

Permalink
Add --now to chassis boot (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustydb authored Oct 23, 2023
2 parents 7cbb0b3 + eed7071 commit 37383ec
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/cli/bios/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
func NewGetCommand() *cobra.Command {
c := &cobra.Command{
Use: "get [key[,keyN]]",
Short: "Gets BIOS settings by key-name, or get every key.",
Short: "Gets BIOS settings by key-name, or get every key",
Long: `Gets BIOS settings.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/bios/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
func NewSetCommand() *cobra.Command {
c := &cobra.Command{
Use: "set attribute=value[,keyN=valueN]",
Short: "Sets BIOS attributes.",
Short: "Sets BIOS attributes",
Long: `Sets BIOS attributes if the attribute is found and the value is valid.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand Down
11 changes: 10 additions & 1 deletion pkg/cmd/cli/boot/chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
func NewChassisCommand() *cobra.Command {
c := &cobra.Command{
Use: "boot [flags] host [...host]",
Short: "Set next boot device.",
Short: "Set next boot device",
Long: `Overrides the next boot device for a one-time override. Only sets UEFI boot modes.`,
Run: func(c *cobra.Command, args []string) {
v := viper.GetViper()
Expand All @@ -63,5 +63,14 @@ func NewChassisCommand() *cobra.Command {
),
)

c.PersistentFlags().BoolP(
"now",
"n",
false,
fmt.Sprintln(
"Reset the server(s) immediately after applying the boot override.",
),
)

return c
}
15 changes: 10 additions & 5 deletions pkg/cmd/cli/boot/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package boot
import (
"github.com/Cray-HPE/gru/pkg/cmd"
"github.com/Cray-HPE/gru/pkg/cmd/cli"
"github.com/Cray-HPE/gru/pkg/cmd/cli/power"
"github.com/Cray-HPE/gru/pkg/set"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -39,7 +40,7 @@ import (
func NewBootBiosOverrideCommand() *cobra.Command {
c := &cobra.Command{
Use: "bios host [...host]",
Short: "Boot to BIOS.",
Short: "Boot to BIOS",
Long: `Override the next boot with the BIOS option.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand All @@ -50,6 +51,10 @@ func NewBootBiosOverrideCommand() *cobra.Command {

content := set.Async(issueOverride, hosts, redfish.BiosSetupBootSourceOverrideTarget)
cli.MapPrint(content)
if v.GetBool("now") {
content = set.Async(power.Issue, hosts, redfish.ForceRestartResetType)
cli.MapPrint(content)
}
},
}
return c
Expand All @@ -59,7 +64,7 @@ func NewBootBiosOverrideCommand() *cobra.Command {
func NewBootPxeOverrideCommand() *cobra.Command {
c := &cobra.Command{
Use: "pxe host [...host]",
Short: "Boot with PXE.",
Short: "Boot with PXE",
Long: `Override the next boot with the PXE option.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand All @@ -74,7 +79,7 @@ func NewBootPxeOverrideCommand() *cobra.Command {
func NewBootHddOverrideCommand() *cobra.Command {
c := &cobra.Command{
Use: "hdd host [...host]",
Short: "Boot from the HDD.",
Short: "Boot from the HDD",
Long: `Override the next boot with the HDD option.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand All @@ -89,7 +94,7 @@ func NewBootHddOverrideCommand() *cobra.Command {
func NewBootUEFIHttpOverrideCommand() *cobra.Command {
c := &cobra.Command{
Use: "http host [...host]",
Short: "Boot with HTTP.",
Short: "Boot with HTTP",
Long: `Override the next boot with the HTTP option.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand All @@ -104,7 +109,7 @@ func NewBootUEFIHttpOverrideCommand() *cobra.Command {
func NewBootNoneOverrideCommand() *cobra.Command {
c := &cobra.Command{
Use: "none host [...host]",
Short: "Clear the boot override.",
Short: "Clear the boot override",
Long: `Clears a boot override.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/chassis/chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewCommand() *cobra.Command {
c := &cobra.Command{
Use: "chassis",
DisableFlagsInUseLine: true,
Short: "Chassis control.",
Short: "Chassis control",
Long: `Interact with a host's chassis.`,
Hidden: false,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/disks/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
func NewShowCommand() *cobra.Command {
c := &cobra.Command{
Use: "disks [flags] host [...host]",
Short: "Disk device information.",
Short: "Disk device information",
Long: `Show available disk devices.`,
Run: func(c *cobra.Command, args []string) {
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
func NewCommand() *cobra.Command {
c := &cobra.Command{
Use: "get",
Short: "Shortcut for getting certain information from RedFish.",
Short: "Shortcut for getting certain information from RedFish",
Long: `Shortcut for getting certain information from RedFish.`,
Run: func(c *cobra.Command, args []string) {
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/power/cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
func NewPowerCycleCommand() *cobra.Command {
c := &cobra.Command{
Use: "cycle",
Short: "Power cycle the target machine(s).",
Short: "Power cycle the target machine(s)",
Long: `Performs an ACPI shutdown and startup to power cycle the target machine(s).
Also allows bypassing the OS shutdown, forcing a warm boot.`,
Run: func(c *cobra.Command, args []string) {
Expand All @@ -57,7 +57,7 @@ Also allows bypassing the OS shutdown, forcing a warm boot.`,
resetType = redfish.ForceRestartResetType
}

content := set.Async(issue, hosts, resetType)
content := set.Async(Issue, hosts, resetType)
cli.MapPrint(content)
},
Hidden: false,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/power/nmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import (
func NewPowerNMICommand() *cobra.Command {
c := &cobra.Command{
Use: "nmi",
Short: "Issue an NMI to the target machine(s).",
Short: "Issue an NMI to the target machine(s)",
Long: `Issue a non-maskable interrupt, triggering a crash/core dump.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
content := set.Async(issue, hosts, redfish.NmiResetType)
content := set.Async(Issue, hosts, redfish.NmiResetType)
cli.MapPrint(content)
},
Hidden: false,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/power/off.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
func NewPowerOffCommand() *cobra.Command {
c := &cobra.Command{
Use: "off",
Short: "Power off the target machine(s).",
Short: "Power off the target machine(s)",
Long: `Powers off the target machine(s) with an ACPI shutdown.
Permits forcing a shutdown (without waiting for the OS),
as well as a power-button emulated shutdown.`,
Expand All @@ -61,7 +61,7 @@ as well as a power-button emulated shutdown.`,
resetType = redfish.PushPowerButtonResetType
}

content := set.Async(issue, hosts, resetType)
content := set.Async(Issue, hosts, resetType)
cli.MapPrint(content)
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/power/on.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import (
func NewPowerOnCommand() *cobra.Command {
c := &cobra.Command{
Use: "on",
Short: "Power on the target machine(s).",
Short: "Power on the target machine(s)",
Long: `Powers on the target machines (cold boot).`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
content := set.Async(issue, hosts, redfish.OnResetType)
content := set.Async(Issue, hosts, redfish.OnResetType)
cli.MapPrint(content)
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/power/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type State struct {
Error error `json:"error,omitempty"`
}

// issue issues an action against a host.
func issue(host string, action interface{}) interface{} {
// Issue issues an action against a host.
func Issue(host string, action interface{}) interface{} {
sc := StateChange{}
c, err := auth.Connection(host)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/power/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import (
func NewPowerResetCommand() *cobra.Command {
c := &cobra.Command{
Use: "reset",
Short: "Power reset the target machine(s).",
Short: "Power reset the target machine(s)",
Long: `Forcefully restart the target machine(s) without a graceful shutdown.`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
content := set.Async(issue, hosts, redfish.ForceRestartResetType)
content := set.Async(Issue, hosts, redfish.ForceRestartResetType)
cli.MapPrint(content)
},
Hidden: false,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/power/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
func NewPowerStatusCommand() *cobra.Command {
c := &cobra.Command{
Use: "status",
Short: "Power status for the target machine(s).",
Short: "Power status for the target machine(s)",
Long: `Prints the current power status reported by the blade management controller for the target machine(s).`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/show/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewCommand() *cobra.Command {
c := &cobra.Command{
Use: "show",
DisableFlagsInUseLine: true,
Short: "Curated server information.",
Short: "Curated server information",
Long: `Print pre-defined classes of information from one or more BMCs.`,
Run: func(c *cobra.Command, args []string) {
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/system/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
func NewShowCommand() *cobra.Command {
c := &cobra.Command{
Use: "system [flags] host [...host]",
Short: "System information.",
Short: "System information",
Long: `Show the Server Manufacturer, Server Model, System Version, and Firmware Version for the given server(s).`,
Run: func(c *cobra.Command, args []string) {
hosts := cli.ParseHosts(args)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/gru/gru.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ the YAML file may provide these per host.
"c",
fmt.Sprintf("./%s.yml", name),
fmt.Sprintln(
"Configuration file containing BMC credentials, necessary if USERNAME and PASSWORD are not defined in the environment.",
"Configuration file containing BMC credentials, necessary if USERNAME and PASSWORD are not defined in the environment",
name,
),
)
c.PersistentFlags().Bool(
"insecure",
false,
"Ignore untrusted or insecure certificates.",
"Ignore untrusted or insecure certificates",
)
c.PersistentFlags().BoolP(
"json",
"j",
false,
"Output results in JSON.",
"Output results in JSON",
)
c.AddCommand(
chassis.NewCommand(),
Expand Down

0 comments on commit 37383ec

Please sign in to comment.