Add NetworkManager.GetAllDevices
This commit is contained in:
parent
3400f94b66
commit
ab586e0f32
1 changed files with 22 additions and 2 deletions
|
@ -11,6 +11,7 @@ const (
|
|||
NetworkManagerObjectPath = "/org/freedesktop/NetworkManager"
|
||||
|
||||
NetworkManagerGetDevices = NetworkManagerInterface + ".GetDevices"
|
||||
NetworkManagerGetAllDevices = NetworkManagerInterface + ".GetAllDevices"
|
||||
NetworkManagerActivateConnection = NetworkManagerInterface + ".ActivateConnection"
|
||||
NetworkManagerAddAndActivateConnection = NetworkManagerInterface + ".AddAndActivateConnection"
|
||||
NetworkManagerPropertyState = NetworkManagerInterface + ".State"
|
||||
|
@ -18,10 +19,12 @@ const (
|
|||
)
|
||||
|
||||
type NetworkManager interface {
|
||||
|
||||
// GetDevices gets the list of network devices.
|
||||
// Get the list of realized network devices.
|
||||
GetDevices() []Device
|
||||
|
||||
// Get the list of all network devices.
|
||||
GetAllDevices() []Device
|
||||
|
||||
// GetState returns the overall networking state as determined by the
|
||||
// NetworkManager daemon, based on the state of network devices under it's
|
||||
// management.
|
||||
|
@ -79,6 +82,23 @@ func (n *networkManager) GetDevices() []Device {
|
|||
return devices
|
||||
}
|
||||
|
||||
func (n *networkManager) GetAllDevices() []Device {
|
||||
var devicePaths []dbus.ObjectPath
|
||||
|
||||
n.call(&devicePaths, NetworkManagerGetAllDevices)
|
||||
devices := make([]Device, len(devicePaths))
|
||||
|
||||
var err error
|
||||
for i, path := range devicePaths {
|
||||
devices[i], err = DeviceFactory(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
return devices
|
||||
}
|
||||
|
||||
func (n *networkManager) GetState() NmState {
|
||||
return NmState(n.getUint32Property(NetworkManagerPropertyState))
|
||||
}
|
||||
|
|
Reference in a new issue