File: cmd_set_system_info_params.go

package info (click to toggle)
golang-github-bougou-go-ipmi 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,880 kB
  • sloc: makefile: 38
file content (67 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ipmi

import (
	"context"
	"fmt"
)

// 22.14a Set System Info Parameters Command
type SetSystemInfoParamRequest struct {
	ParamSelector SystemInfoParamSelector
	ParamData     []byte
}

type SetSystemInfoParamResponse struct {
}

func (req *SetSystemInfoParamRequest) Pack() []byte {
	out := make([]byte, 1+len(req.ParamData))
	out[0] = byte(req.ParamSelector)
	packBytes(req.ParamData, out, 1)
	return out
}

func (req *SetSystemInfoParamRequest) Command() Command {
	return CommandSetSystemInfoParam
}

func (res *SetSystemInfoParamResponse) CompletionCodes() map[uint8]string {
	return map[uint8]string{
		0x80: "parameter not supported",
		0x81: "attempt to set the 'set in progress' value (in parameter #0) when not in the 'set complete' state.",
		0x82: "attempt to write read-only parameter",
	}
}

func (res *SetSystemInfoParamResponse) Unpack(msg []byte) error {
	return nil
}

func (res *SetSystemInfoParamResponse) Format() string {
	return ""
}

func (c *Client) SetSystemInfoParam(ctx context.Context, paramSelector SystemInfoParamSelector, paramData []byte) (response *SetSystemInfoParamResponse, err error) {
	request := &SetSystemInfoParamRequest{
		ParamSelector: paramSelector,
		ParamData:     paramData,
	}
	response = &SetSystemInfoParamResponse{}
	err = c.Exchange(ctx, request, response)
	return
}

func (c *Client) SetSystemInfoParamFor(ctx context.Context, param SystemInfoParameter) error {
	if isNilSystemInfoParamete(param) {
		return nil
	}

	paramSelector, _, _ := param.SystemInfoParameter()
	paramData := param.Pack()
	_, err := c.SetSystemInfoParam(ctx, paramSelector, paramData)
	if err != nil {
		return fmt.Errorf("SetSystemInfoParam for param (%s[%d]) failed, err: %w", paramSelector.String(), paramSelector, err)
	}

	return nil
}