mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
Make NMDeviceInfo a record
This commit is contained in:
@@ -77,21 +77,22 @@ public class NetworkManager {
|
||||
var ethernetDevices = NetworkUtils.getAllWiredInterfaces();
|
||||
for (NMDeviceInfo deviceInfo : ethernetDevices) {
|
||||
activeConnections.put(
|
||||
deviceInfo.devName, NetworkUtils.getActiveConnection(deviceInfo.devName));
|
||||
monitorDevice(deviceInfo.devName, 5000);
|
||||
deviceInfo.devName(), NetworkUtils.getActiveConnection(deviceInfo.devName()));
|
||||
monitorDevice(deviceInfo.devName(), 5000);
|
||||
}
|
||||
|
||||
var physicalDevices = NetworkUtils.getAllActiveWiredInterfaces();
|
||||
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 {
|
||||
// if the configured interface isn't in the list of available ones, select one that is
|
||||
var iFace = physicalDevices.stream().findFirst().orElseThrow();
|
||||
logger.warn(
|
||||
"The configured interface doesn't match any available interface. Applying configuration to "
|
||||
+ iFace.devName);
|
||||
+ iFace.devName());
|
||||
// update NetworkConfig with found interface
|
||||
config.networkManagerIface = iFace.devName;
|
||||
config.networkManagerIface = iFace.devName();
|
||||
ConfigManager.getInstance().requestSave();
|
||||
} catch (NoSuchElementException e) {
|
||||
// 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) {
|
||||
connName = c;
|
||||
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
|
||||
+ "]";
|
||||
this(c, d, NMType.typeForString(type));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user