fix:网络配置
This commit is contained in:
parent
392428d2f0
commit
a4da5e65b5
@ -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")
|
||||
|
||||
@ -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-rr,1=active-backup,2=balance-xor,4=802.3ad",
|
||||
example = "1",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED
|
||||
)
|
||||
|
||||
@ -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-rr,1=active-backup,2=balance-xor,4=802.3ad",
|
||||
example = "1",
|
||||
allowableValues = {"0", "1", "2", "4"},
|
||||
requiredMode = Schema.RequiredMode.REQUIRED
|
||||
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
* 前缀长度
|
||||
|
||||
@ -17,9 +17,9 @@ public class NetworkTableResponse {
|
||||
* 地址类型,如 IPV4、IPV6、-
|
||||
*/
|
||||
@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;
|
||||
|
||||
/**
|
||||
* 前缀长度,如 24、64
|
||||
@ -46,8 +46,7 @@ public class NetworkTableResponse {
|
||||
*/
|
||||
@Schema(
|
||||
description = "网卡状态:Active=激活,Inactive=未激活",
|
||||
example = "Active",
|
||||
allowableValues = {"Active", "Inactive"}
|
||||
example = "Active"
|
||||
)
|
||||
private String status;
|
||||
}
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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("");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user