mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-03 03:01:40 +00:00
Make NMDeviceInfo a record
This commit is contained in:
@@ -77,21 +77,22 @@ public class NetworkManager {
|
|||||||
var ethernetDevices = NetworkUtils.getAllWiredInterfaces();
|
var ethernetDevices = NetworkUtils.getAllWiredInterfaces();
|
||||||
for (NMDeviceInfo deviceInfo : ethernetDevices) {
|
for (NMDeviceInfo deviceInfo : ethernetDevices) {
|
||||||
activeConnections.put(
|
activeConnections.put(
|
||||||
deviceInfo.devName, NetworkUtils.getActiveConnection(deviceInfo.devName));
|
deviceInfo.devName(), NetworkUtils.getActiveConnection(deviceInfo.devName()));
|
||||||
monitorDevice(deviceInfo.devName, 5000);
|
monitorDevice(deviceInfo.devName(), 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
var physicalDevices = NetworkUtils.getAllActiveWiredInterfaces();
|
var physicalDevices = NetworkUtils.getAllActiveWiredInterfaces();
|
||||||
var config = ConfigManager.getInstance().getConfig().getNetworkConfig();
|
var config = ConfigManager.getInstance().getConfig().getNetworkConfig();
|
||||||
if (physicalDevices.stream().noneMatch(it -> (it.devName.equals(config.networkManagerIface)))) {
|
if (physicalDevices.stream()
|
||||||
|
.noneMatch(it -> (it.devName().equals(config.networkManagerIface)))) {
|
||||||
try {
|
try {
|
||||||
// if the configured interface isn't in the list of available ones, select one that is
|
// if the configured interface isn't in the list of available ones, select one that is
|
||||||
var iFace = physicalDevices.stream().findFirst().orElseThrow();
|
var iFace = physicalDevices.stream().findFirst().orElseThrow();
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"The configured interface doesn't match any available interface. Applying configuration to "
|
"The configured interface doesn't match any available interface. Applying configuration to "
|
||||||
+ iFace.devName);
|
+ iFace.devName());
|
||||||
// update NetworkConfig with found interface
|
// update NetworkConfig with found interface
|
||||||
config.networkManagerIface = iFace.devName;
|
config.networkManagerIface = iFace.devName();
|
||||||
ConfigManager.getInstance().requestSave();
|
ConfigManager.getInstance().requestSave();
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
// if there are no available interfaces, go with the one from settings
|
// if there are no available interfaces, go with the one from settings
|
||||||
|
|||||||
@@ -53,26 +53,16 @@ public class NetworkUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NMDeviceInfo {
|
/**
|
||||||
|
* Contains data about network devices retrieved from "nmcli device show"
|
||||||
|
*
|
||||||
|
* @param connName The human-readable name used by "nmcli con"
|
||||||
|
* @param devName The underlying device name, used by dhclient
|
||||||
|
* @param nmType The NetworkManager device type
|
||||||
|
*/
|
||||||
|
public static record NMDeviceInfo(String connName, String devName, NMType nmType) {
|
||||||
public NMDeviceInfo(String c, String d, String type) {
|
public NMDeviceInfo(String c, String d, String type) {
|
||||||
connName = c;
|
this(c, d, NMType.typeForString(type));
|
||||||
devName = d;
|
|
||||||
nmType = NMType.typeForString(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String connName; // Human-readable name used by "nmcli con"
|
|
||||||
public final String devName; // underlying device, used by dhclient
|
|
||||||
public final NMType nmType;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "NMDeviceInfo [connName="
|
|
||||||
+ connName
|
|
||||||
+ ", devName="
|
|
||||||
+ devName
|
|
||||||
+ ", nmType="
|
|
||||||
+ nmType
|
|
||||||
+ "]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user