updates in new gui to allow empty ip4/ip6 addresses, fixed display issues related to empty addresses
This commit is contained in:
parent
d076229973
commit
be37f0f279
2 changed files with 45 additions and 26 deletions
|
@ -21,10 +21,9 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
|
|
||||||
def check_ip6(parent, name: str, value: str) -> bool:
|
def check_ip6(parent, name: str, value: str) -> bool:
|
||||||
title = f"IP6 Error for {name}"
|
|
||||||
if not value:
|
if not value:
|
||||||
messagebox.showerror(title, "Empty Value", parent=parent)
|
return True
|
||||||
return False
|
title = f"IP6 Error for {name}"
|
||||||
values = value.split("/")
|
values = value.split("/")
|
||||||
if len(values) != 2:
|
if len(values) != 2:
|
||||||
messagebox.showerror(
|
messagebox.showerror(
|
||||||
|
@ -47,10 +46,9 @@ def check_ip6(parent, name: str, value: str) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def check_ip4(parent, name: str, value: str) -> bool:
|
def check_ip4(parent, name: str, value: str) -> bool:
|
||||||
title = f"IP4 Error for {name}"
|
|
||||||
if not value:
|
if not value:
|
||||||
messagebox.showerror(title, "Empty Value", parent=parent)
|
return True
|
||||||
return False
|
title = f"IP4 Error for {name}"
|
||||||
values = value.split("/")
|
values = value.split("/")
|
||||||
if len(values) != 2:
|
if len(values) != 2:
|
||||||
messagebox.showerror(
|
messagebox.showerror(
|
||||||
|
@ -255,14 +253,20 @@ class NodeConfigDialog(Dialog):
|
||||||
|
|
||||||
label = ttk.Label(tab, text="IPv4")
|
label = ttk.Label(tab, text="IPv4")
|
||||||
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
||||||
ip4 = tk.StringVar(value=f"{interface.ip4}/{interface.ip4mask}")
|
ip4_net = ""
|
||||||
|
if interface.ip4:
|
||||||
|
ip4_net = f"{interface.ip4}/{interface.ip4mask}"
|
||||||
|
ip4 = tk.StringVar(value=ip4_net)
|
||||||
entry = ttk.Entry(tab, textvariable=ip4)
|
entry = ttk.Entry(tab, textvariable=ip4)
|
||||||
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
||||||
row += 1
|
row += 1
|
||||||
|
|
||||||
label = ttk.Label(tab, text="IPv6")
|
label = ttk.Label(tab, text="IPv6")
|
||||||
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
||||||
ip6 = tk.StringVar(value=f"{interface.ip6}/{interface.ip6mask}")
|
ip6_net = ""
|
||||||
|
if interface.ip6:
|
||||||
|
ip6_net = f"{interface.ip6}/{interface.ip6mask}"
|
||||||
|
ip6 = tk.StringVar(value=ip6_net)
|
||||||
entry = ttk.Entry(tab, textvariable=ip6)
|
entry = ttk.Entry(tab, textvariable=ip6)
|
||||||
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
||||||
|
|
||||||
|
@ -312,23 +316,36 @@ class NodeConfigDialog(Dialog):
|
||||||
# update node interface data
|
# update node interface data
|
||||||
for interface in self.canvas_node.interfaces:
|
for interface in self.canvas_node.interfaces:
|
||||||
data = self.interfaces[interface.id]
|
data = self.interfaces[interface.id]
|
||||||
if check_ip4(self, interface.name, data.ip4.get()):
|
|
||||||
ip4, ip4mask = data.ip4.get().split("/")
|
# validate ip4
|
||||||
interface.ip4 = ip4
|
ip4_net = data.ip4.get()
|
||||||
interface.ip4mask = int(ip4mask)
|
if not check_ip4(self, interface.name, ip4_net):
|
||||||
else:
|
|
||||||
error = True
|
error = True
|
||||||
data.ip4.set(f"{interface.ip4}/{interface.ip4mask}")
|
data.ip4.set(f"{interface.ip4}/{interface.ip4mask}")
|
||||||
break
|
break
|
||||||
if check_ip6(self, interface.name, data.ip6.get()):
|
if ip4_net:
|
||||||
ip6, ip6mask = data.ip6.get().split("/")
|
ip4, ip4mask = ip4_net.split("/")
|
||||||
interface.ip6 = ip6
|
ip4mask = int(ip4mask)
|
||||||
interface.ip6mask = int(ip6mask)
|
|
||||||
interface.mac = data.mac.get()
|
|
||||||
else:
|
else:
|
||||||
|
ip4, ip4mask = "", 0
|
||||||
|
interface.ip4 = ip4
|
||||||
|
interface.ip4mask = ip4mask
|
||||||
|
|
||||||
|
# validate ip6
|
||||||
|
ip6_net = data.ip6.get()
|
||||||
|
if not check_ip6(self, interface.name, ip6_net):
|
||||||
error = True
|
error = True
|
||||||
data.ip6.set(f"{interface.ip6}/{interface.ip6mask}")
|
data.ip6.set(f"{interface.ip6}/{interface.ip6mask}")
|
||||||
break
|
break
|
||||||
|
if ip6_net:
|
||||||
|
ip6, ip6mask = ip6_net.split("/")
|
||||||
|
ip6mask = int(ip6mask)
|
||||||
|
else:
|
||||||
|
ip6, ip6mask = "", 0
|
||||||
|
interface.ip6 = ip6
|
||||||
|
interface.ip6mask = ip6mask
|
||||||
|
|
||||||
|
interface.mac = data.mac.get()
|
||||||
|
|
||||||
# redraw
|
# redraw
|
||||||
if not error:
|
if not error:
|
||||||
|
|
|
@ -110,18 +110,20 @@ class CanvasEdge:
|
||||||
def create_labels(self):
|
def create_labels(self):
|
||||||
label_one = None
|
label_one = None
|
||||||
if self.link.HasField("interface_one"):
|
if self.link.HasField("interface_one"):
|
||||||
label_one = (
|
label_one = self.create_label(self.link.interface_one)
|
||||||
f"{self.link.interface_one.ip4}/{self.link.interface_one.ip4mask}\n"
|
|
||||||
f"{self.link.interface_one.ip6}/{self.link.interface_one.ip6mask}\n"
|
|
||||||
)
|
|
||||||
label_two = None
|
label_two = None
|
||||||
if self.link.HasField("interface_two"):
|
if self.link.HasField("interface_two"):
|
||||||
label_two = (
|
label_two = self.create_label(self.link.interface_two)
|
||||||
f"{self.link.interface_two.ip4}/{self.link.interface_two.ip4mask}\n"
|
|
||||||
f"{self.link.interface_two.ip6}/{self.link.interface_two.ip6mask}\n"
|
|
||||||
)
|
|
||||||
return label_one, label_two
|
return label_one, label_two
|
||||||
|
|
||||||
|
def create_label(self, interface):
|
||||||
|
label = ""
|
||||||
|
if interface.ip4:
|
||||||
|
label = f"{interface.ip4}/{interface.ip4mask}"
|
||||||
|
if interface.ip6:
|
||||||
|
label = f"{label}\n{interface.ip6}/{interface.ip6mask}"
|
||||||
|
return label
|
||||||
|
|
||||||
def draw_labels(self):
|
def draw_labels(self):
|
||||||
x1, y1, x2, y2 = self.get_coordinates()
|
x1, y1, x2, y2 = self.get_coordinates()
|
||||||
label_one, label_two = self.create_labels()
|
label_one, label_two = self.create_labels()
|
||||||
|
|
Loading…
Reference in a new issue