refactor(dns): route nmcli through run_command

This commit is contained in:
sankalp committed 2026-08-02 13:37:09 +05:45
1 parent 2025cca857
commit 25bd696bf2
1 file changed
+6 -16
+6 -16
View File
@@ -1,8 +1,9 @@
import subprocess
import threading
from fabric.utils import GLib, logger
from utils.functions import run_command
DEFAULT_PROVIDERS = [
{"label": "Cloudflare", "primary": "1.1.1.1", "secondary": "1.0.0.1"},
{"label": "Google", "primary": "8.8.8.8", "secondary": "8.8.4.4"},
@@ -14,23 +15,12 @@ DEFAULT_PROVIDERS = [
def _nmcli(*args, timeout=15):
"""Run nmcli and return (returncode, stdout, stderr)."""
try:
r = subprocess.run(
["nmcli", *args],
capture_output=True,
text=True,
timeout=timeout,
)
return r.returncode, r.stdout.strip(), r.stderr.strip()
except FileNotFoundError:
result = run_command(["nmcli", *args], timeout=timeout)
if result.returncode == 127:
logger.warning("[Dns] nmcli not found")
return 127, "", "nmcli not found"
except subprocess.TimeoutExpired:
elif result.returncode == -1:
logger.warning("[Dns] nmcli timed out")
return -1, "", "timeout"
except Exception as e:
logger.error(f"[Dns] nmcli failed: {e}")
return 1, "", str(e)
return result.returncode, result.stdout.strip(), result.stderr.strip()
def _active_connection_name():