-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdev_utils.go
More file actions
36 lines (31 loc) · 734 Bytes
/
dev_utils.go
File metadata and controls
36 lines (31 loc) · 734 Bytes
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
package nm
import (
"fmt"
)
func (dt DeviceType) String() string {
if dt == Unknown {
return "Unknown"
} else if dt == Wired {
return "Wired"
} else if dt == Wireless {
return "Wireless"
}
return fmt.Sprintf("Unknown (%d)", dt)
}
func (dev *Device) devTypeGet(name string) (interface{}, error) {
iface := ""
if dev.typ == Wired {
iface = NM_DEV_WIRED_IFACE
} else if dev.typ == Wireless {
iface = NM_DEV_WIRELESS_IFACE
} else {
return nil, fmt.Errorf("Unknown device type: %s", dev.typ)
}
return dev.Get(iface, "HwAddress")
}
func (dev *Device) mustBe(typ DeviceType) error {
if dev.typ == typ {
return nil
}
return fmt.Errorf("This function only applys to %s devices, this is a %s", typ, dev.typ)
}