Update Docker_RUN.md and load_prefixes.py for improved BGP configuration and logging. Adjusted IP addresses in Docker_RUN.md for consistency and clarity. Enhanced load_prefixes.py with error logging and refined JSON message handling for better robustness during ExaBGP operations.
Build and Push Docker Image / build (push) Successful in 3m22s

This commit is contained in:
2025-07-11 17:58:56 +07:00
parent f76e70aeb3
commit 3c5740784b
2 changed files with 33 additions and 95 deletions
+19 -11
View File
@@ -32,6 +32,10 @@ def log_message(message: str):
# Если не можем записать в файл, просто выводим в stderr
print(f"Warning: Could not write to log file: {e}", file=sys.stderr, flush=True)
def log_error(message: str):
"""Запись ошибки в лог"""
log_message(f"ERROR: {message}")
def validate_prefix(prefix: str) -> bool:
"""Валидация IP префикса"""
try:
@@ -88,13 +92,10 @@ def announce_prefixes(prefixes: Set[str]):
router_id = os.environ.get('BGP_ROUTER_ID', '192.168.1.100')
for prefix in sorted(prefixes):
# Формат команды для ExaBGP
# Формат команды для ExaBGP (упрощенный)
command = {
"command": "announce route",
"neighbor": {
"ip": neighbor_ip,
"description": "RouterOS peer"
},
"neighbor": neighbor_ip,
"attribute": {
"origin": "igp",
"as-path": [local_as],
@@ -115,10 +116,7 @@ def withdraw_prefixes(prefixes: Set[str]):
for prefix in sorted(prefixes):
command = {
"command": "withdraw route",
"neighbor": {
"ip": neighbor_ip,
"description": "RouterOS peer"
},
"neighbor": neighbor_ip,
"nlri": prefix
}
@@ -161,12 +159,22 @@ def main():
if not line:
break
line = line.strip()
if not line: # Пропуск пустых строк
continue
# Обработка команд от ExaBGP
try:
data = json.loads(line.strip())
data = json.loads(line)
log_message(f"Received command: {data}")
except json.JSONDecodeError:
log_message(f"Invalid JSON received: {line.strip()}")
# Не все сообщения от ExaBGP являются JSON
# Это может быть обычное текстовое сообщение
if line.startswith('[') and line.endswith(']'):
# Это может быть лог сообщение от ExaBGP
log_message(f"Received log message: {line}")
else:
log_message(f"Received non-JSON message: {line}")
except KeyboardInterrupt:
log_message("Received interrupt signal")