refactor(dns): route nmcli through run_command
This commit is contained in:
1 file changed
+6
-16
+6
-16
@@ -1,8 +1,9 @@
|
|||||||
import subprocess
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from fabric.utils import GLib, logger
|
from fabric.utils import GLib, logger
|
||||||
|
|
||||||
|
from utils.functions import run_command
|
||||||
|
|
||||||
DEFAULT_PROVIDERS = [
|
DEFAULT_PROVIDERS = [
|
||||||
{"label": "Cloudflare", "primary": "1.1.1.1", "secondary": "1.0.0.1"},
|
{"label": "Cloudflare", "primary": "1.1.1.1", "secondary": "1.0.0.1"},
|
||||||
{"label": "Google", "primary": "8.8.8.8", "secondary": "8.8.4.4"},
|
{"label": "Google", "primary": "8.8.8.8", "secondary": "8.8.4.4"},
|
||||||
@@ -14,23 +15,12 @@ DEFAULT_PROVIDERS = [
|
|||||||
|
|
||||||
def _nmcli(*args, timeout=15):
|
def _nmcli(*args, timeout=15):
|
||||||
"""Run nmcli and return (returncode, stdout, stderr)."""
|
"""Run nmcli and return (returncode, stdout, stderr)."""
|
||||||
try:
|
result = run_command(["nmcli", *args], timeout=timeout)
|
||||||
r = subprocess.run(
|
if result.returncode == 127:
|
||||||
["nmcli", *args],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
timeout=timeout,
|
|
||||||
)
|
|
||||||
return r.returncode, r.stdout.strip(), r.stderr.strip()
|
|
||||||
except FileNotFoundError:
|
|
||||||
logger.warning("[Dns] nmcli not found")
|
logger.warning("[Dns] nmcli not found")
|
||||||
return 127, "", "nmcli not found"
|
elif result.returncode == -1:
|
||||||
except subprocess.TimeoutExpired:
|
|
||||||
logger.warning("[Dns] nmcli timed out")
|
logger.warning("[Dns] nmcli timed out")
|
||||||
return -1, "", "timeout"
|
return result.returncode, result.stdout.strip(), result.stderr.strip()
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"[Dns] nmcli failed: {e}")
|
|
||||||
return 1, "", str(e)
|
|
||||||
|
|
||||||
|
|
||||||
def _active_connection_name():
|
def _active_connection_name():
|
||||||
|
|||||||
Reference in new issue
Block a user