-
Notifications
You must be signed in to change notification settings - Fork 26
/
cmd_get_dcmi_config_params.go
138 lines (110 loc) · 3.54 KB
/
cmd_get_dcmi_config_params.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package ipmi
import (
"context"
"fmt"
)
// [DCMI specification v1.5] 6.1.3 Get DCMI Configuration Parameters Command
type GetDCMIConfigParamsRequest struct {
ParamSelector DCMIConfigParamSelector
SetSelector uint8 // use 00h for parameters that only have one set
}
type GetDCMIConfigParamsResponse struct {
MajorVersion uint8
MinorVersion uint8
ParamRevision uint8
ParamData []byte
}
func (req *GetDCMIConfigParamsRequest) Pack() []byte {
out := make([]byte, 3)
packUint8(GroupExtensionDCMI, out, 0)
packUint8(uint8(req.ParamSelector), out, 1)
packUint8(req.SetSelector, out, 2)
return out
}
func (req *GetDCMIConfigParamsRequest) Command() Command {
return CommandGetDCMIConfigParams
}
func (res *GetDCMIConfigParamsResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetDCMIConfigParamsResponse) Unpack(msg []byte) error {
if len(msg) < 5 {
return ErrUnpackedDataTooShortWith(len(msg), 5)
}
if err := CheckDCMIGroupExenstionMatch(msg[0]); err != nil {
return err
}
res.MajorVersion, _, _ = unpackUint8(msg, 1)
res.MinorVersion, _, _ = unpackUint8(msg, 2)
res.ParamRevision, _, _ = unpackUint8(msg, 3)
res.ParamData, _, _ = unpackBytes(msg, 4, len(msg)-4)
return nil
}
func (res *GetDCMIConfigParamsResponse) Format() string {
return ""
}
func (c *Client) GetDCMIConfigParams(ctx context.Context, paramSelector DCMIConfigParamSelector, setSelector uint8) (response *GetDCMIConfigParamsResponse, err error) {
request := &GetDCMIConfigParamsRequest{
ParamSelector: paramSelector,
SetSelector: setSelector,
}
response = &GetDCMIConfigParamsResponse{}
err = c.Exchange(ctx, request, response)
return
}
func (c *Client) GetDCMIConfigParamsFor(ctx context.Context, param DCMIConfigParameter) error {
paramSelector, setSelector := param.DCMIConfigParameter()
request := &GetDCMIConfigParamsRequest{ParamSelector: paramSelector, SetSelector: setSelector}
response := &GetDCMIConfigParamsResponse{}
if err := c.Exchange(ctx, request, response); err != nil {
return err
}
if err := param.Unpack(response.ParamData); err != nil {
return fmt.Errorf("unpack param (%s[%d]) failed, err: %w", paramSelector.String(), paramSelector, err)
}
return nil
}
func (c *Client) GetDCMIConfig(ctx context.Context) (*DCMIConfig, error) {
dcmiConfig := &DCMIConfig{
ActivateDHCP: &DCMIConfigParam_ActivateDHCP{},
DiscoveryConfiguration: &DCMIConfigParam_DiscoveryConfiguration{},
DHCPTiming1: &DCMIConfigParam_DHCPTiming1{},
DHCPTiming2: &DCMIConfigParam_DHCPTiming2{},
DHCPTiming3: &DCMIConfigParam_DHCPTiming3{},
}
if err := c.GetDCMIConfigFor(ctx, dcmiConfig); err != nil {
return nil, err
}
return dcmiConfig, nil
}
func (c *Client) GetDCMIConfigFor(ctx context.Context, dcmiConfig *DCMIConfig) error {
if dcmiConfig == nil {
return nil
}
if dcmiConfig.ActivateDHCP != nil {
if err := c.GetDCMIConfigParamsFor(ctx, dcmiConfig.ActivateDHCP); err != nil {
return err
}
}
if dcmiConfig.DiscoveryConfiguration != nil {
if err := c.GetDCMIConfigParamsFor(ctx, dcmiConfig.DiscoveryConfiguration); err != nil {
return err
}
}
if dcmiConfig.DHCPTiming1 != nil {
if err := c.GetDCMIConfigParamsFor(ctx, dcmiConfig.DHCPTiming1); err != nil {
return err
}
}
if dcmiConfig.DHCPTiming2 != nil {
if err := c.GetDCMIConfigParamsFor(ctx, dcmiConfig.DHCPTiming2); err != nil {
return err
}
}
if dcmiConfig.DHCPTiming3 != nil {
if err := c.GetDCMIConfigParamsFor(ctx, dcmiConfig.DHCPTiming3); err != nil {
return err
}
}
return nil
}