forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_system_guid.go
64 lines (53 loc) · 1.25 KB
/
cmd_get_system_guid.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
package ipmi
import (
"fmt"
"time"
"github.com/google/uuid"
)
// 22.14 Get System GUID Command
type GetSystemGUIDRequest struct {
// empty
}
type GetSystemGUIDResponse struct {
GUID [16]byte
}
func (req *GetSystemGUIDRequest) Command() Command {
return CommandGetSystemGUID
}
func (req *GetSystemGUIDRequest) Pack() []byte {
return nil
}
func (res *GetSystemGUIDResponse) Unpack(msg []byte) error {
if len(msg) < 16 {
return ErrUnpackedDataTooShort
}
b, _, _ := unpackBytes(msg, 0, 16)
res.GUID = array16(b)
return nil
}
func (*GetSystemGUIDResponse) CompletionCodes() map[uint8]string {
// no command-specific cc
return map[uint8]string{}
}
func (res *GetSystemGUIDResponse) Format() string {
uuidRFC4122MSB := make([]byte, 16)
for i := 0; i < 16; i++ {
uuidRFC4122MSB[i] = res.GUID[:][15-i]
}
u, err := uuid.FromBytes(uuidRFC4122MSB)
if err != nil {
return "Invalid UUID Bytes"
}
sec, nsec := u.Time().UnixTime()
return fmt.Sprintf(`System GUID : %s
Timestamp : %s`,
u.String(),
time.Unix(sec, nsec).Format(time.RFC3339),
)
}
func (c *Client) GetSystemGUID() (response *GetSystemGUIDResponse, err error) {
request := &GetSystemGUIDRequest{}
response = &GetSystemGUIDResponse{}
err = c.Exchange(request, response)
return
}