File: cmd_get_sel_info.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 (102 lines) | stat: -rw-r--r-- 3,009 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
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
package ipmi

import (
	"context"
	"fmt"
	"time"
)

// GetSELInfoRequest (31.2) command returns the number of entries in the SEL.
type GetSELInfoRequest struct {
	// empty
}

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 ErrUnpackedDataTooShortWith(len(msg), 14)
	}
	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 "" +
		"SEL Information\n" +
		fmt.Sprintf("Version                      : %s (v1.5, v2 compliant)\n", version) +
		fmt.Sprintf("Entries                      : %d\n", res.Entries) +
		fmt.Sprintf("Free Space                   : %d bytes\n", res.FreeBytes) +
		fmt.Sprintf("Percent Used                 : %.2f%%\n", usedPct) +
		fmt.Sprintf("Last Add Time                : %s\n", res.RecentAdditionTime.Format(timeFormat)) +
		fmt.Sprintf("Last Del Time                : %s\n", res.RecentEraseTime.Format(timeFormat)) +
		fmt.Sprintf("Overflow                     : %v\n", res.OperationSupport.Overflow) +
		fmt.Sprintf("Delete SEL supported         : %v\n", res.OperationSupport.DeleteSEL) +
		fmt.Sprintf("Partial Add SEL supported    : %v\n", res.OperationSupport.PartialAddSEL) +
		fmt.Sprintf("Reserve SEL supported        : %v\n", res.OperationSupport.ReserveSEL) +
		fmt.Sprintf("Get SEL Alloc Info supported : %v\n", res.OperationSupport.GetSELAllocInfo)
}

func (c *Client) GetSELInfo(ctx context.Context) (response *GetSELInfoResponse, err error) {
	request := &GetSELInfoRequest{}
	response = &GetSELInfoResponse{}
	err = c.Exchange(ctx, request, response)
	return
}