fixed RouterOS API issues
This commit is contained in:
parent
3683dde410
commit
a23b915f61
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
|
|
@ -35,6 +36,33 @@ public final class ROS extends AbstractComponent<ROS.ROSConfig> {
|
|||
subscription = context.getEventsHandler().getNetworkManagerUpdateEvent().add(bundle -> updateSubnets(bundle.getSubnets()));
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getRoutesByGatewayAndVRF(ApiConnection connection, String gateway, String vrf)
|
||||
throws MikrotikApiException {
|
||||
|
||||
List<Map<String, String>> allRoutes = new ArrayList<>();
|
||||
int offset = 0;
|
||||
final int LIMIT = 100;
|
||||
|
||||
// while (true) {
|
||||
// // Формируем запрос с пагинацией. Каждый параметр - отдельный аргумент.
|
||||
// List<Map<String, String>> chunk = connection.execute(
|
||||
// "/ip/route/print",
|
||||
// "gateway=" + gateway,
|
||||
// "routing-table=" + vrf,
|
||||
// ".proplist=.id,dst-address,static", // Указываем нужные поля
|
||||
// "limit=" + offset + "," + LIMIT
|
||||
// );
|
||||
//
|
||||
// if (chunk == null || chunk.isEmpty()) {
|
||||
// break; // Выходим из цикла, если данных больше нет
|
||||
// }
|
||||
//
|
||||
// allRoutes.addAll(chunk);
|
||||
// offset += LIMIT; // Переходим к следующей порции
|
||||
// }
|
||||
return allRoutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronises FRR instances with the provided subnet list.
|
||||
*/
|
||||
|
|
@ -46,9 +74,9 @@ public final class ROS extends AbstractComponent<ROS.ROSConfig> {
|
|||
connection.login(entry.username, entry.password);
|
||||
SystemLogger.message("Fetching existing subnets...", CTX);
|
||||
var existingSubnets = new HashMap<String, IPv4Subnet>();
|
||||
var result = connection.execute("/ip/route/print where gateway=" + entry.gateway + " and routing-table=" + entry.VRF);
|
||||
var result = connection.execute("/ip/route/print .proplist=.id,dst-address,static,gateway where static=true and routing-table=" + entry.VRF);
|
||||
result.forEach(row -> {
|
||||
if (row.containsKey("static") && row.get("static").equals("true")) {
|
||||
if (row.containsKey("static") && row.get("gateway").contains(entry.gateway)) {
|
||||
existingSubnets.put(row.get(".id"), new IPv4Subnet(row.get("dst-address")));
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue