pygui: avoid issue when joining opened xml that has a node with no ip4 address
This commit is contained in:
parent
39fd11efb3
commit
9ed42cfba8
1 changed files with 7 additions and 2 deletions
|
@ -12,7 +12,9 @@ if TYPE_CHECKING:
|
||||||
from core.gui.graph.node import CanvasNode
|
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}")
|
net = netaddr.IPNetwork(f"{interface.ip4}/{interface.ip4mask}")
|
||||||
ip_value = net.value
|
ip_value = net.value
|
||||||
cidr_value = net.cidr.value
|
cidr_value = net.cidr.value
|
||||||
|
@ -108,7 +110,8 @@ class InterfaceManager:
|
||||||
self.used_subnets.pop(subnets.key(), None)
|
self.used_subnets.pop(subnets.key(), None)
|
||||||
else:
|
else:
|
||||||
index = get_index(interface)
|
index = get_index(interface)
|
||||||
subnets.used_indexes.discard(index)
|
if index is not None:
|
||||||
|
subnets.used_indexes.discard(index)
|
||||||
self.current_subnets = None
|
self.current_subnets = None
|
||||||
|
|
||||||
def joined(self, links: List["core_pb2.Link"]) -> None:
|
def joined(self, links: List["core_pb2.Link"]) -> None:
|
||||||
|
@ -123,6 +126,8 @@ class InterfaceManager:
|
||||||
for interface in interfaces:
|
for interface in interfaces:
|
||||||
subnets = self.get_subnets(interface)
|
subnets = self.get_subnets(interface)
|
||||||
index = get_index(interface)
|
index = get_index(interface)
|
||||||
|
if index is None:
|
||||||
|
continue
|
||||||
subnets.used_indexes.add(index)
|
subnets.used_indexes.add(index)
|
||||||
if subnets.key() not in self.used_subnets:
|
if subnets.key() not in self.used_subnets:
|
||||||
self.used_subnets[subnets.key()] = subnets
|
self.used_subnets[subnets.key()] = subnets
|
||||||
|
|
Loading…
Reference in a new issue