Each command defined in the IPMI specification is a pair of request/response messages.
These IPMI commands are implemented as methods of the ipmi.Client
struct in this library.
ipmitool
as example, some ipmitool
cmdline are realized by calling just one underlying IPMI command,
but many others are not. Like ipmitool sdr list
, it's a loop of GetSDR
IPMI command.
So this library also implements some methods that are not IPMI commands defined
in IPMI sepcification, but just some common helpers, like GetSDRs
to get all SDRs.
For a IPMI Command DoSomething
:
- Must define
DoSomethingRequest
which conforms to theipmi.Request
interface, it holds the request message data. - Must define
DoSomethingResponse
which conforms to theipmi.Response
interface, it holds the response message data. - Must define
DoSomething
method onipmi.Client
For DoSomething
method, you can pass DoSomethingRequest
directly as the input parameter, like:
func (c *Client) DoSomething(request *DoSomethingRequest) (response *DoSomethingResponse, err error) {
response := &DoSomethingResponse{}
err := c.Exchange(request, response)
return
}
or, you can pass some plain parametes, and construct the DoSomethingRequest
in method body, like:
func (c *Client) DoSomething(param1 string, param2 string) (response *DoSomethingResponse, err error) {
request := &DoSomethingRequest{
// construct by using input params
}
response := &DoSomethingResponse{}
err := c.Exchange(request, response)
return
}
Calling Exchange
method of ipmi.Client
will fullfil all other complex underlying works.
type Request interface {
// Pack encodes the object to data bytes
Pack() []byte
// Command return the IPMI command info (NetFn/Cmd).
// All IPMI specification specified commands are already predefined in this file.
Command() Command
}
type Response interface {
// Unpack decodes the object from data bytes
Unpack(data []byte) error
// CompletionCodes returns a map of command-specific completion codes
CompletionCodes() map[uint8]string
// Format return a formatted human friendly string
Format() string
}