From 9ed42cfba894c760b70a5711e46c55dec7ee5473 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Wed, 10 Jun 2020 11:04:33 -0700 Subject: [PATCH] pygui: avoid issue when joining opened xml that has a node with no ip4 address --- daemon/core/gui/interface.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/daemon/core/gui/interface.py b/daemon/core/gui/interface.py index 437bd37c..1973fe99 100644 --- a/daemon/core/gui/interface.py +++ b/daemon/core/gui/interface.py @@ -12,7 +12,9 @@ if TYPE_CHECKING: from core.gui.graph.node import CanvasNode -def get_index(interface: "core_pb2.Interface") -> int: +def get_index(interface: "core_pb2.Interface") -> Optional[int]: + if not interface.ip4: + return None net = netaddr.IPNetwork(f"{interface.ip4}/{interface.ip4mask}") ip_value = net.value cidr_value = net.cidr.value @@ -108,7 +110,8 @@ class InterfaceManager: self.used_subnets.pop(subnets.key(), None) else: index = get_index(interface) - subnets.used_indexes.discard(index) + if index is not None: + subnets.used_indexes.discard(index) self.current_subnets = None def joined(self, links: List["core_pb2.Link"]) -> None: @@ -123,6 +126,8 @@ class InterfaceManager: for interface in interfaces: subnets = self.get_subnets(interface) index = get_index(interface) + if index is None: + continue subnets.used_indexes.add(index) if subnets.key() not in self.used_subnets: self.used_subnets[subnets.key()] = subnets