-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.go
75 lines (62 loc) · 1.42 KB
/
client.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
// Package devlink provides access to Linux's devlink interface.
//
// For more information on devlink, please see: https://lwn.net/Articles/674867/.
package devlink
import (
"io"
)
// A Client provides access to Linux devlink information.
type Client struct {
c osClient
}
// New creates a new Client.
func New() (*Client, error) {
c, err := newClient()
if err != nil {
return nil, err
}
return &Client{
c: c,
}, nil
}
// Close releases resources used by a Client.
func (c *Client) Close() error {
return c.c.Close()
}
// Devices retrieves all devlink devices on this system.
func (c *Client) Devices() ([]*Device, error) {
return c.c.Devices()
}
// Ports retrieves all devlink ports attached to devices on this system.
func (c *Client) Ports() ([]*Port, error) {
return c.c.Ports()
}
// An osClient is the operating system-specific implementation of Client.
type osClient interface {
io.Closer
Devices() ([]*Device, error)
Ports() ([]*Port, error)
}
// A Device is a devlink device.
type Device struct {
Bus string
Device string
}
//go:generate stringer -type=PortType -output=string.go
// A PortType is the operating mode of a devlink port.
type PortType int
// Possible PortType values.
const (
Unknown PortType = iota
Auto
Ethernet
InfiniBand
)
// A Port is a devlink port which is attached to a devlink device.
type Port struct {
Bus string
Device string
Port int
Type PortType
Name string
}