Skip to content

Commit

Permalink
expose ipmi.PowerCycleMachine (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwennrich authored Jul 21, 2021
1 parent ec42cc2 commit d0085a7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/metalcore/initConsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func (s *Server) initConsumer() error {
s.EventHandler().PowerOffMachine(evt.Cmd.TargetMachineID)
case domain.MachineResetCmd:
s.EventHandler().PowerResetMachine(evt.Cmd.TargetMachineID)
case domain.MachineCycleCmd:
s.EventHandler().PowerCycleMachine(evt.Cmd.TargetMachineID)
case domain.MachineBiosCmd:
s.EventHandler().PowerBootBiosMachine(evt.Cmd.TargetMachineID)
case domain.MachineDiskCmd:
Expand Down
19 changes: 19 additions & 0 deletions internal/event/powerControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ func (h *eventHandler) PowerResetMachine(machineID string) {
}
}

func (h *eventHandler) PowerCycleMachine(machineID string) {
ipmiCfg, err := h.APIClient().IPMIConfig(machineID)
if err != nil {
zapup.MustRootLogger().Error("Unable to read IPMI connection details",
zap.String("machine", machineID),
zap.Error(err),
)
return
}

err = ipmi.PowerCycleMachine(ipmiCfg)
if err != nil {
zapup.MustRootLogger().Error("Unable to power cycle machine",
zap.String("machine", machineID),
zap.Error(err),
)
}
}

func (h *eventHandler) PowerOnChassisIdentifyLED(machineID, description string) {
ipmiCfg, err := h.APIClient().IPMIConfig(machineID)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
MachineOnCmd MachineCommand = "ON"
MachineOffCmd MachineCommand = "OFF"
MachineResetCmd MachineCommand = "RESET"
MachineCycleCmd MachineCommand = "CYCLE"
MachineBiosCmd MachineCommand = "BIOS"
MachineDiskCmd MachineCommand = "DISK"
MachinePxeCmd MachineCommand = "PXE"
Expand Down Expand Up @@ -89,6 +90,7 @@ type EventHandler interface {
PowerOnMachine(machineID string)
PowerOffMachine(machineID string)
PowerResetMachine(machineID string)
PowerCycleMachine(machineID string)
PowerBootBiosMachine(machineID string)
PowerBootDiskMachine(machineID string)
PowerBootPxeMachine(machineID string)
Expand Down
2 changes: 2 additions & 0 deletions test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (h *noopEventHandler) PowerOffMachine(machineID string) {}

func (h *noopEventHandler) PowerResetMachine(machineID string) {}

func (h *noopEventHandler) PowerCycleMachine(machineID string) {}

func (h *noopEventHandler) PowerBootBiosMachine(machineID string) {}

func (h *noopEventHandler) PowerBootDiskMachine(machineID string) {}
Expand Down

0 comments on commit d0085a7

Please sign in to comment.