bmc

package
v0.0.0-...-f615581 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTimeOuts holds the default redfish and ssh timeouts.
	DefaultTimeOuts = TimeOuts{
		Redfish: defaultTimeOut,
		SSH:     defaultTimeOut,
	}
)

Functions

This section is empty.

Types

type BMC

type BMC struct {
	// contains filtered or unexported fields
}

BMC is the holder struct for BMC access through redfish & ssh.

func New

func New(host string) *BMC

New returns a BMC struct with the specified host. The host should be nonempty. WithRedfishUser and WithSSHUser must be called before connecting to Redfish or over SSH, respectively. The SSH port and timeouts are set to DefaultSSHPort and DefaultTimeOuts, with indices defaulting to 0.

func (*BMC) CloseSerialConsole

func (bmc *BMC) CloseSerialConsole() error

CloseSerialConsole closes the serial console's underlying ssh session.

func (*BMC) IsSecureBootEnabled

func (bmc *BMC) IsSecureBootEnabled() (bool, error)

IsSecureBootEnabled returns whether the SecureBoot feature is enabled using the BMC's RedFish API endpoint.

func (*BMC) OpenSerialConsole

func (bmc *BMC) OpenSerialConsole(openConsoleCliCmd string) (io.Reader, io.WriteCloser, error)

OpenSerialConsole opens the serial console port. The console is tunneled in an underlying (CLI) ssh session that is opened in the BMC's ssh server. If openConsoleCliCmd is provided, it will be sent to the BMC's cli. Otherwise, a best effort will be made to run the appropriate cli command based on the system manufacturer. This method requires both a Redfish and SSH user configured.

func (*BMC) PowerUsage

func (bmc *BMC) PowerUsage() (float32, error)

PowerUsage returns the current power usage of the chassis in watts using the Redfish API. This method uses the first chassis with a power link and the power control index for the BMC client.

func (*BMC) RunCLICommand

func (bmc *BMC) RunCLICommand(
	cmd string, combineOutput bool, timeout time.Duration) (stdout string, stderr string, err error)

RunCLICommand runs a CLI command in the BMC's console over SSH. This method will block until the command has finished, and its output is copied to stdout and/or stderr if applicable. If combineOutput is true, stderr content is merged in stdout. The timeout param is used to avoid the caller to be stuck forever in case something goes wrong or the command is stuck.

func (*BMC) SecureBootDisable

func (bmc *BMC) SecureBootDisable() error

SecureBootDisable disables the SecureBoot feature using the BMC's RedFish API endpoint.

func (*BMC) SecureBootEnable

func (bmc *BMC) SecureBootEnable() error

SecureBootEnable enables the SecureBoot feature using the BMC's RedFish API endpoint.

func (*BMC) SetSystemBootOrderReferences

func (bmc *BMC) SetSystemBootOrderReferences(bootOrderReferences []string) error

SetSystemBootOrderReferences sets the boot order references of the current system using the redfish API. The boot order references are not updated until the system is resetted, meaning that a following call to SystemBootOrderReferences() won't reflect the change until the system has been actually resetted.

func (*BMC) SystemBootOptions

func (bmc *BMC) SystemBootOptions() (map[string]string, error)

SystemBootOptions uses the redfish api to get the current system's boot options and returns a map references to display names, e.g.:

  • "Boot0000":"PXE Device 1: Embedded NIC 1 Port 1 Partition 1"
  • "Boot0003":"RAID Controller in SL 3: Red Hat Enterprise Linux]"

func (*BMC) SystemBootOrderReferences

func (bmc *BMC) SystemBootOrderReferences() ([]string, error)

SystemBootOrderReferences returns the current system's boot order (references) in an ordered slice using redfish API.

func (*BMC) SystemForceReset

func (bmc *BMC) SystemForceReset() error

SystemForceReset performs a (non-graceful) forced system reset using Redfish API.

func (*BMC) SystemGracefulShutdown

func (bmc *BMC) SystemGracefulShutdown() error

SystemGracefulShutdown performs a graceful shutdown using the Redfish API.

func (*BMC) SystemManufacturer

func (bmc *BMC) SystemManufacturer() (string, error)

SystemManufacturer gets system's manufacturer from the BMC's RedFish API endpoint.

func (*BMC) SystemPowerCycle

func (bmc *BMC) SystemPowerCycle() error

SystemPowerCycle performs a power cycle in the system using the Redfish API. If PowerCycle reset type is not supported, alternate PowerOff + On reset actions will be performed as fallback mechanism. Use bmc.SystemResetAction(redfish.PowerCycleResetType) if this fallback mechanism is not needed/wanted.

func (*BMC) SystemPowerOff

func (bmc *BMC) SystemPowerOff() error

SystemPowerOff performs a non-graceful power off of the system using the Redfish API.

func (*BMC) SystemPowerOn

func (bmc *BMC) SystemPowerOn() error

SystemPowerOn powers on the system using the Redfish API.

func (*BMC) SystemPowerState

func (bmc *BMC) SystemPowerState() (string, error)

SystemPowerState returns the system's current power state using the Redfish API. Returned string can be one of On/Off/Paused/PoweringOn/PoweringOff.

func (*BMC) SystemResetAction

func (bmc *BMC) SystemResetAction(action redfish.ResetType) error

SystemResetAction performs the specified reset action against the system.

func (*BMC) WaitForSystemPowerState

func (bmc *BMC) WaitForSystemPowerState(powerState redfish.PowerState, timeout time.Duration) error

WaitForSystemPowerState waits up to timeout until the BMC returns the provided system power state.

func (*BMC) WithRedfishPowerControlIndex

func (bmc *BMC) WithRedfishPowerControlIndex(index int) *BMC

WithRedfishPowerControlIndex provides the index of the PowerControl object to use from the Power link on the Chassis service in the Redfish API. The order of the PowerControl objects is deterministic.

func (*BMC) WithRedfishSystemIndex

func (bmc *BMC) WithRedfishSystemIndex(index int) *BMC

WithRedfishSystemIndex provies the index of the system to use in the Redfish API. Note that the order of the systems is nondeterministic.

func (*BMC) WithRedfishTimeout

func (bmc *BMC) WithRedfishTimeout(timeout time.Duration) *BMC

WithRedfishTimeout provides the timeout to use when connecting to the Redfish API. It should not be zero or negative.

func (*BMC) WithRedfishUser

func (bmc *BMC) WithRedfishUser(username, password string) *BMC

WithRedfishUser provides the credentials to access the Redfish API. Neither the username nor password should be empty.

func (*BMC) WithSSHPort

func (bmc *BMC) WithSSHPort(port uint16) *BMC

WithSSHPort provides the port to use when connecting to the BMC over SSH. It should not be zero.

func (*BMC) WithSSHTimeout

func (bmc *BMC) WithSSHTimeout(timeout time.Duration) *BMC

WithSSHTimeout provides the timeout to use when connecting to the BMC over SSH. It should not be zero or negative.

func (*BMC) WithSSHUser

func (bmc *BMC) WithSSHUser(username, password string) *BMC

WithSSHUser provides the credentials to use when connecting to the BMC over SSH. Neither the username nor the password should be empty.

type TimeOuts

type TimeOuts struct {
	// Redfish timeout for the redfish api access.
	Redfish time.Duration
	// SSH timeout for the ssh access.
	SSH time.Duration
}

TimeOuts holds the configured timeouts for Redfish and SSH acccess.

type User

type User struct {
	// Name holds the user's name
	Name string
	// Password holds the user's password
	Password string
}

User holds the Name and Password for a user (ssh/redfish).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL