Skip to content

Commit

Permalink
add machine power cycle command (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwennrich authored Jul 21, 2021
1 parent e1941de commit b6fb130
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 49 deletions.
26 changes: 25 additions & 1 deletion cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,23 @@ Power on will therefore not work if the machine is in the powering off phase.`,
machinePowerResetCmd = &cobra.Command{
Use: "reset <machine ID>",
Short: "power reset a machine",
Long: "reset the machine power. This will ensure a power cycle.",
Long: "(hard) reset the machine power.",
RunE: func(cmd *cobra.Command, args []string) error {
return machinePowerReset(driver, args)
},
PreRun: bindPFlags,
}

machinePowerCycleCmd = &cobra.Command{
Use: "cycle <machine ID>",
Short: "power cycle a machine",
Long: "(soft) cycle the machine power.",
RunE: func(cmd *cobra.Command, args []string) error {
return machinePowerCycle(driver, args)
},
PreRun: bindPFlags,
}

machineUpdateCmd = &cobra.Command{
Use: "update",
Aliases: []string{"firmware-update"},
Expand Down Expand Up @@ -431,6 +441,7 @@ func init() {
machinePowerCmd.AddCommand(machinePowerOnCmd)
machinePowerCmd.AddCommand(machinePowerOffCmd)
machinePowerCmd.AddCommand(machinePowerResetCmd)
machinePowerCmd.AddCommand(machinePowerCycleCmd)
machinePowerCmd.AddCommand(machineBootBiosCmd)
machinePowerCmd.AddCommand(machineBootDiskCmd)
machinePowerCmd.AddCommand(machineBootPxeCmd)
Expand Down Expand Up @@ -804,6 +815,19 @@ func machinePowerReset(driver *metalgo.Driver, args []string) error {
return printer.Print(resp.Machine)
}

func machinePowerCycle(driver *metalgo.Driver, args []string) error {
machineID, err := getMachineID(args)
if err != nil {
return err
}

resp, err := driver.MachinePowerCycle(machineID)
if err != nil {
return err
}
return printer.Print(resp.Machine)
}

func machineUpdateBios(driver *metalgo.Driver, args []string) error {
m, vendor, board, err := firmwareData(args)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.12.0
github.com/metal-stack/masterdata-api v0.8.7
github.com/metal-stack/metal-go v0.15.1
github.com/metal-stack/metal-go v0.15.2
github.com/metal-stack/metal-lib v0.8.0
github.com/metal-stack/updater v1.1.3
github.com/metal-stack/v v1.0.3
Expand Down
Loading

0 comments on commit b6fb130

Please sign in to comment.