Add docker-ip-addr-manager initial app
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
def list_host_interfaces() -> list[str]:
|
||||
result = subprocess.run(
|
||||
["ip", "-o", "link", "show"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"Failed to list interfaces: {result.stderr.strip()}")
|
||||
|
||||
interfaces: list[str] = []
|
||||
seen = set()
|
||||
for line in result.stdout.splitlines():
|
||||
parts = line.split(":", maxsplit=2)
|
||||
if len(parts) < 2:
|
||||
continue
|
||||
name = parts[1].strip().split("@", maxsplit=1)[0]
|
||||
if not name or name in seen:
|
||||
continue
|
||||
seen.add(name)
|
||||
interfaces.append(name)
|
||||
|
||||
return interfaces
|
||||
Reference in New Issue
Block a user