forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_sel_info.go
112 lines (96 loc) · 2.66 KB
/
cmd_get_sel_info.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
package ipmi
import (
"fmt"
"time"
)
// GetSELInfoRequest (31.2) command returns the number of entries in the SEL.
type GetSELInfoRequest struct {
// no request data
}
type GetSELInfoResponse struct {
SELVersion uint8
Entries uint16
FreeBytes uint16
RecentAdditionTime time.Time
RecentEraseTime time.Time
OperationSupport SELOperationSupport
}
type SELOperationSupport struct {
Overflow bool
DeleteSEL bool
PartialAddSEL bool
ReserveSEL bool
GetSELAllocInfo bool
}
func (req *GetSELInfoRequest) Command() Command {
return CommandGetSELInfo
}
func (req *GetSELInfoRequest) Pack() []byte {
// empty request data
return []byte{}
}
func (res *GetSELInfoResponse) Unpack(msg []byte) error {
if len(msg) < 14 {
return ErrUnpackedDataTooShort
}
res.SELVersion, _, _ = unpackUint8(msg, 0)
res.Entries, _, _ = unpackUint16L(msg, 1)
res.FreeBytes, _, _ = unpackUint16L(msg, 3)
addTS, _, _ := unpackUint32L(msg, 5)
res.RecentAdditionTime = parseTimestamp(addTS)
eraseTS, _, _ := unpackUint32L(msg, 9)
res.RecentEraseTime = parseTimestamp(eraseTS)
b := msg[13]
res.OperationSupport = SELOperationSupport{
Overflow: isBit7Set(b),
DeleteSEL: isBit3Set(b),
PartialAddSEL: isBit2Set(b),
ReserveSEL: isBit1Set(b),
GetSELAllocInfo: isBit0Set(b),
}
return nil
}
func (r *GetSELInfoResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{
0x81: "cannot execute command, SEL erase in progress",
}
}
func (res *GetSELInfoResponse) Format() string {
var version string
if res.SELVersion == 0x51 {
version = "1.5"
}
var usedBytes int = int(res.Entries) * 16
totalBytes := usedBytes + int(res.FreeBytes)
var usedPct float64 = 100 * float64(usedBytes) / float64(totalBytes)
return fmt.Sprintf(`SEL Information
Version : %s (v1.5, v2 compliant)
Entries : %d
Free Space : %d bytes
Percent Used : %.2f%%
Last Add Time : %s
Last Del Time : %s
Overflow : %v
Delete SEL supported: : %v
Partial Add SEL supported: : %v
Reserve SEL supported : %v
Get SEL Alloc Info supported : %v`,
version,
res.Entries,
res.FreeBytes,
usedPct,
res.RecentAdditionTime,
res.RecentEraseTime,
res.OperationSupport.Overflow,
res.OperationSupport.DeleteSEL,
res.OperationSupport.PartialAddSEL,
res.OperationSupport.ReserveSEL,
res.OperationSupport.GetSELAllocInfo,
)
}
func (c *Client) GetSELInfo() (response *GetSELInfoResponse, err error) {
request := &GetSELInfoRequest{}
response = &GetSELInfoResponse{}
err = c.Exchange(request, response)
return
}