From 58b51adbb4e652771b042a8b1c700b0969700214 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 23 Mar 2023 08:37:04 +0000 Subject: [PATCH] kexec-installer: don't die on missing json keys --- nix/kexec-installer/restore_routes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nix/kexec-installer/restore_routes.py b/nix/kexec-installer/restore_routes.py index 9578f10..8649a7b 100644 --- a/nix/kexec-installer/restore_routes.py +++ b/nix/kexec-installer/restore_routes.py @@ -14,7 +14,7 @@ def filter_interfaces(network: list[dict[str, Any]]) -> list[dict[str, Any]]: continue addr_info = [] has_dynamic_address = False - for addr in net["addr_info"]: + for addr in net.get("addr_info", []): # no link-local ipv4/ipv6 if addr.get("scope") == "link": continue @@ -50,16 +50,16 @@ def generate_networkd_units( name = f"{interface['ifname']}.network" addresses = [ f"Address = {addr['local']}/{addr['prefixlen']}" - for addr in interface["addr_info"] + for addr in interface.get("addr_info", []) ] route_sections = [] for route in routes: - if route["dev"] != interface["ifname"]: + if route.get("dev", "nodev") != interface.get("ifname", "noif"): continue route_section = "[Route]\n" - if route["dst"] != "default": + if route.get("dst") != "default": # can be skipped for default routes route_section += f"Destination = {route['dst']}\n" gateway = route.get("gateway")