From 081840e0e8a76bd16df81657e92a6a7dc6080d28 Mon Sep 17 00:00:00 2001 From: clore Date: Sun, 8 Dec 2024 10:53:17 +0000 Subject: [PATCH] purge bridge interfaces in migration to xfs --- lib/networking.py | 19 ++++++++++++++++++- lib/xfs.py | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/networking.py b/lib/networking.py index 10be4df..43992b0 100644 --- a/lib/networking.py +++ b/lib/networking.py @@ -6,6 +6,7 @@ import ipaddress import socket import psutil import sys +import os config = config_module.config log = logging_lib.log @@ -95,4 +96,20 @@ def is_ip_in_network(ip: str, network: str) -> bool: except ValueError as e: # If there's an error with the input values, print the error and return False log.debug(f"NETWORKING | is_ip_in_network() | Error: {e}") - return False \ No newline at end of file + return False + +def purge_clore_interfaces(): + network_interfaces = get_network_interfaces_with_subnet() + if type(network_interfaces) != dict: + log.error("Failed to load network interfaces, restarting...") + os._exit(1) + + clore_subnets = [ "172.17.0.1/16" ] # I can include the docker default subnet here + for clore_default_network in config.clore_default_networks: + clore_subnets.append(clore_default_network["subnet"]) + + for network_interface in network_interfaces.keys(): + if network_interface == "docker0" or network_interface[:3] == "br-": + subnet = network_interfaces[network_interface] + if subnet in clore_subnets or network_interface == "docker0": + utils.run_command(f"ip link delete {network_interface}") \ No newline at end of file diff --git a/lib/xfs.py b/lib/xfs.py index 50ad490..4d7a0ac 100644 --- a/lib/xfs.py +++ b/lib/xfs.py @@ -2,6 +2,7 @@ from lib import ensure_packages_installed from lib import logging as logging_lib from lib import docker_interface +from lib import networking from lib import utils import asyncio @@ -70,6 +71,9 @@ def migrate(): code, stdout, stderr = utils.run_command( f"systemctl stop docker && rm -rf {DOCKER_ROOT} && fallocate -l {str(data_img_size)}M {DOCKER_DATA_IMG} && mkfs.xfs {DOCKER_DATA_IMG}" ) + + networking.purge_clore_interfaces() + if code == 0: docker_config_success = configure_docker_daemon() if code == 0 and docker_config_success: