Merge remote-tracking branch 'origin/V1.00' into V1.00

This commit is contained in:
waner 2026-04-28 13:47:13 +08:00
commit bba2d5f259
7 changed files with 81 additions and 21 deletions

View File

@ -76,6 +76,12 @@ public class NetworkConfigController {
}
@Operation(summary = "获取所有Bond名称", description = "获取系统中所有Bond连接名称")
@GetMapping("/bond/names")
public ApiResponse<List<String>> getBondNames() {
return ApiResponse.success(networkConfigService.getBondNames());
}
@Operation(summary = "创建Bond", description = "创建一个新的Bond聚合接口需指定名称、模式和从属接口")
@PostMapping("/bond/create")
@AuditedOperation(module = ModuleCode.NETWORK, action = ActionType.CREATE, summary = "创建Bond")

View File

@ -27,7 +27,7 @@ public class BondConfigRequest {
* 4: 802.3ad
*/
@Schema(
description = "Bond 模式0=balance-rr平衡轮询1=active-backup主备2=balance-xor平衡异或4=802.3ad动态链路聚合",
description = "Bond 模式0=balance-rr1=active-backup2=balance-xor4=802.3ad",
example = "1",
requiredMode = Schema.RequiredMode.REQUIRED
)

View File

@ -31,7 +31,7 @@ public class BondCreateRequest {
* 4: 802.3ad
*/
@Schema(
description = "Bond模式0=balance-rr平衡轮询1=active-backup主备2=balance-xor平衡异或4=802.3ad动态链路聚合",
description = "Bond模式0=balance-rr1=active-backup2=balance-xor4=802.3ad",
example = "1",
allowableValues = {"0", "1", "2", "4"},
requiredMode = Schema.RequiredMode.REQUIRED

View File

@ -18,7 +18,7 @@ public class BondTableResponse {
*/
@Schema(
description = "Bond模式",
example = "bond1-主备"
example = "balance-rr"
)
private String bondMode;
@ -28,7 +28,7 @@ public class BondTableResponse {
@Schema(
description = "地址类型IPV4 或 IPV6",
example = "IPV4",
allowableValues = {"IPV4", "IPV6", "-"}
allowableValues = {"IPV4", "IPV6"}
)
private String addressType;
@ -36,7 +36,7 @@ public class BondTableResponse {
* 地址
*/
@Schema(description = "IP地址", example = "192.168.10.100")
private String address;
private String ipAddress;
/**
* 前缀长度

View File

@ -17,9 +17,9 @@ public class NetworkTableResponse {
* 地址类型 IPV4IPV6-
*/
@Schema(
description = "地址类型IPV4、IPV6 或 -",
description = "地址类型IPV4、IPV6",
example = "IPV4",
allowableValues = {"IPV4", "IPV6", "-"}
allowableValues = {"IPV4", "IPV6"}
)
private String addressType;
@ -27,7 +27,7 @@ public class NetworkTableResponse {
* 地址 172.16.18.1
*/
@Schema(description = "IP地址", example = "172.16.18.1")
private String address;
private String ipAddress;
/**
* 前缀长度 2464
@ -46,8 +46,7 @@ public class NetworkTableResponse {
*/
@Schema(
description = "网卡状态Active=激活Inactive=未激活",
example = "Active",
allowableValues = {"Active", "Inactive"}
example = "Active"
)
private String status;
}

View File

@ -45,16 +45,14 @@ public class RouteTableResponse {
* 状态Active / Inactive
*/
@Schema(
description = "网口状态Active=激活Inactive=未激活",
example = "Active",
allowableValues = {"Active", "Inactive"}
description = "网卡状态Active=激活Inactive=未激活",
example = "Active"
)
private String status;
@Schema(
description = "网口状态Active=激活Inactive=未激活",
example = "Active",
allowableValues = {"Active", "Inactive"}
description = "地址类型IPv4 或 IPv6",
example = "IPv4"
)
private String addressType;

View File

@ -160,6 +160,63 @@ public class NetworkConfigService {
}
public List<String> getBondNames() {
List<String> result = new ArrayList<>();
List<String> lines = executeCommand(
"nmcli",
"-t",
"-f",
"NAME,TYPE",
"con",
"show"
);
for (String line : lines) {
if (line == null || line.trim().isEmpty()) {
continue;
}
String[] parts = line.split("(?<!\\\\):", -1);
if (parts.length < 2) {
continue;
}
String name = parts[0].replace("\\:", ":");
String type = parts[1];
if (!"bond".equals(type)) {
continue;
}
result.add(name);
}
result.sort(Comparator.comparingInt(this::getBondIndex));
return result;
}
private int getBondIndex(String bondName) {
try {
if (bondName == null) {
return Integer.MAX_VALUE;
}
String name = bondName.trim();
if (!name.matches("^bond\\d+$")) {
return Integer.MAX_VALUE;
}
return Integer.parseInt(name.substring(4));
} catch (Exception e) {
return Integer.MAX_VALUE;
}
}
public PageResult<NetworkTableResponse> getNetworkTablePage(NetworkTableQueryRequest req) {
List<NetworkTableResponse> resultList = new ArrayList<>();
String targetDeviceName = trim(req.getDeviceName());
@ -317,7 +374,7 @@ public class NetworkConfigService {
NetworkTableResponse emptyItem = new NetworkTableResponse();
emptyItem.setDeviceName(device);
// emptyItem.setAddressType("-");
// emptyItem.setAddress("-");
// emptyItem.setIpAddress("-");
// emptyItem.setPrefixLength("-");
// emptyItem.setGateway("-");
emptyItem.setStatus(mappedStatus);
@ -554,10 +611,10 @@ public class NetworkConfigService {
if (ipWithPrefix.contains("/")) {
String[] parts = ipWithPrefix.split("/");
item.setAddress(parts[0]);
item.setIpAddress(parts[0]);
item.setPrefixLength(parts[1]);
} else {
item.setAddress(ipWithPrefix);
item.setIpAddress(ipWithPrefix);
item.setPrefixLength("");
}
return item;
@ -1786,10 +1843,10 @@ public class NetworkConfigService {
if (normalizedIp.contains("/")) {
String[] parts = normalizedIp.split("/", 2);
item.setAddress(parts[0]);
item.setIpAddress(parts[0]);
item.setPrefixLength(parts[1]);
} else {
item.setAddress(normalizedIp);
item.setIpAddress(normalizedIp);
item.setPrefixLength("");
}