Refactor documentation structure and improve validation checks; update VM state handling and error management.
This commit is contained in:
+7
-2
@@ -141,7 +141,10 @@ class NetworkManager:
|
||||
result = self._runner.run(("ip", "-j", "-d", "link", "show"), capture=True)
|
||||
try:
|
||||
links = json.loads(result.stdout)
|
||||
if not isinstance(links, list) or any(not isinstance(link, dict) for link in links):
|
||||
if not isinstance(links, list) or any(
|
||||
not isinstance(link, dict) or not isinstance(link.get("ifname"), str)
|
||||
or not link["ifname"] for link in links
|
||||
):
|
||||
raise ValueError("invalid interface inventory")
|
||||
matches = [link for link in links if link.get("ifname") == name]
|
||||
if len(matches) > 1:
|
||||
@@ -155,7 +158,9 @@ class NetworkManager:
|
||||
if link is None:
|
||||
return None
|
||||
info = link.get("linkinfo", {})
|
||||
is_tap = info.get("info_kind") == "tun" and info.get("info_data", {}).get("type") == "tap"
|
||||
is_tap = (isinstance(info, dict) and info.get("info_kind") == "tun"
|
||||
and isinstance(info.get("info_data"), dict)
|
||||
and info["info_data"].get("type") == "tap")
|
||||
legacy = vm.ports is None and vm.tap_owned and not link.get("ifalias")
|
||||
if not is_tap or (link.get("ifalias") != f"uvm:{vm.id}" and not legacy):
|
||||
raise ConflictError(f"refusing to modify unowned TAP {vm.tap}")
|
||||
|
||||
Reference in New Issue
Block a user