forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_device_guid.go
59 lines (46 loc) · 1.12 KB
/
cmd_get_device_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
package ipmi
import (
"fmt"
"github.com/google/uuid"
)
// 20.8 Get Device GUID Command
type GetDeviceGUIDRequest struct {
// empty
}
type GetDeviceGUIDResponse struct {
GUID [16]byte
}
func (req *GetDeviceGUIDRequest) Command() Command {
return CommandGetDeviceGUID
}
func (req *GetDeviceGUIDRequest) Pack() []byte {
return []byte{}
}
func (res *GetDeviceGUIDResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetDeviceGUIDResponse) Unpack(msg []byte) error {
if len(msg) < 16 {
return ErrUnpackedDataTooShort
}
guid, _, _ := unpackBytes(msg, 0, 16)
res.GUID = array16(guid)
return nil
}
func (res *GetDeviceGUIDResponse) 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"
}
return fmt.Sprintf(`GUID: %s`, u.String())
}
func (c *Client) GetDeviceGUID() (response *GetDeviceGUIDResponse, err error) {
request := &GetDeviceGUIDRequest{}
response = &GetDeviceGUIDResponse{}
err = c.Exchange(request, response)
return
}