startred custom node dialog, update node services dialog to use service data retrieved from grpc
This commit is contained in:
parent
2d1f5edf79
commit
1c36c5e291
5 changed files with 110 additions and 84 deletions
|
@ -42,15 +42,15 @@ def check_directory():
|
||||||
for background in LOCAL_BACKGROUND_PATH.glob("*"):
|
for background in LOCAL_BACKGROUND_PATH.glob("*"):
|
||||||
new_background = BACKGROUNDS_PATH.joinpath(background.name)
|
new_background = BACKGROUNDS_PATH.joinpath(background.name)
|
||||||
shutil.copy(background, new_background)
|
shutil.copy(background, new_background)
|
||||||
with CONFIG_PATH.open("w") as f:
|
config = {"servers": [{"name": "example", "address": "127.0.0.1", "port": 50051}]}
|
||||||
yaml.dump(
|
save_config(config)
|
||||||
{"servers": [{"name": "example", "address": "127.0.0.1", "port": 50051}]},
|
|
||||||
f,
|
|
||||||
Dumper=IndentDumper,
|
|
||||||
default_flow_style=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def read_config():
|
def read_config():
|
||||||
with CONFIG_PATH.open("r") as f:
|
with CONFIG_PATH.open("r") as f:
|
||||||
return yaml.load(f, Loader=yaml.SafeLoader)
|
return yaml.load(f, Loader=yaml.SafeLoader)
|
||||||
|
|
||||||
|
|
||||||
|
def save_config(config):
|
||||||
|
with CONFIG_PATH.open("w") as f:
|
||||||
|
yaml.dump(config, f, Dumper=IndentDumper, default_flow_style=False)
|
||||||
|
|
|
@ -74,6 +74,7 @@ class CoreClient:
|
||||||
self.app = app
|
self.app = app
|
||||||
self.master = app.master
|
self.master = app.master
|
||||||
self.interface_helper = None
|
self.interface_helper = None
|
||||||
|
self.services = {}
|
||||||
|
|
||||||
# distributed server data
|
# distributed server data
|
||||||
self.servers = {}
|
self.servers = {}
|
||||||
|
@ -188,9 +189,16 @@ class CoreClient:
|
||||||
:return: existing sessions
|
:return: existing sessions
|
||||||
"""
|
"""
|
||||||
self.client.connect()
|
self.client.connect()
|
||||||
response = self.client.get_sessions()
|
|
||||||
|
# get service information
|
||||||
|
response = self.client.get_services()
|
||||||
|
for service in response.services:
|
||||||
|
group_services = self.services.setdefault(service.group, [])
|
||||||
|
group_services.append(service)
|
||||||
|
|
||||||
# if there are no sessions, create a new session, else join a session
|
# if there are no sessions, create a new session, else join a session
|
||||||
|
response = self.client.get_sessions()
|
||||||
|
logging.info("current sessions: %s", response)
|
||||||
sessions = response.sessions
|
sessions = response.sessions
|
||||||
if len(sessions) == 0:
|
if len(sessions) == 0:
|
||||||
self.create_new_session()
|
self.create_new_session()
|
||||||
|
|
|
@ -1,24 +1,12 @@
|
||||||
import logging
|
import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
# from core.api.grpc import core_pb2
|
|
||||||
from coretk.coretoolbarhelp import CoreToolbarHelp
|
from coretk.coretoolbarhelp import CoreToolbarHelp
|
||||||
|
from coretk.dialogs.customnodes import CustomNodesDialog
|
||||||
from coretk.graph import GraphMode
|
from coretk.graph import GraphMode
|
||||||
from coretk.images import ImageEnum, Images
|
from coretk.images import ImageEnum, Images
|
||||||
from coretk.tooltip import CreateToolTip
|
from coretk.tooltip import CreateToolTip
|
||||||
|
|
||||||
# from enum import Enum
|
|
||||||
|
|
||||||
|
|
||||||
# class SessionStateEnum(Enum):
|
|
||||||
# NONE = "none"
|
|
||||||
# DEFINITION = "definition"
|
|
||||||
# CONFIGURATION = "configuration"
|
|
||||||
# RUNTIME = "runtime"
|
|
||||||
# DATACOLLECT = "datacollect"
|
|
||||||
# SHUTDOWN = "shutdown"
|
|
||||||
# INSTANTIATION = "instantiation"
|
|
||||||
|
|
||||||
|
|
||||||
class CoreToolbar(object):
|
class CoreToolbar(object):
|
||||||
"""
|
"""
|
||||||
|
@ -245,11 +233,12 @@ class CoreToolbar(object):
|
||||||
self.canvas.draw_node_image = Images.get(ImageEnum.OVS)
|
self.canvas.draw_node_image = Images.get(ImageEnum.OVS)
|
||||||
self.canvas.draw_node_name = "OVS"
|
self.canvas.draw_node_name = "OVS"
|
||||||
|
|
||||||
# TODO what graph node is this
|
|
||||||
def pick_editnode(self, main_button):
|
def pick_editnode(self, main_button):
|
||||||
self.network_layer_option_menu.destroy()
|
self.network_layer_option_menu.destroy()
|
||||||
main_button.configure(image=Images.get(ImageEnum.EDITNODE))
|
main_button.configure(image=Images.get(ImageEnum.EDITNODE))
|
||||||
logging.debug("Pick editnode option")
|
logging.debug("Pick editnode option")
|
||||||
|
dialog = CustomNodesDialog(self.app, self.app)
|
||||||
|
dialog.show()
|
||||||
|
|
||||||
def draw_network_layer_options(self, network_layer_button):
|
def draw_network_layer_options(self, network_layer_button):
|
||||||
"""
|
"""
|
||||||
|
|
82
coretk/coretk/dialogs/customnodes.py
Normal file
82
coretk/coretk/dialogs/customnodes.py
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import tkinter as tk
|
||||||
|
|
||||||
|
from coretk.dialogs.dialog import Dialog
|
||||||
|
|
||||||
|
|
||||||
|
class CustomNodesDialog(Dialog):
|
||||||
|
def __init__(self, master, app):
|
||||||
|
super().__init__(master, app, "Custom Nodes", modal=True)
|
||||||
|
self.save_button = None
|
||||||
|
self.delete_button = None
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self.columnconfigure(0, weight=1)
|
||||||
|
self.rowconfigure(0, weight=1)
|
||||||
|
self.draw_node_config()
|
||||||
|
self.draw_node_buttons()
|
||||||
|
self.draw_buttons()
|
||||||
|
|
||||||
|
def draw_node_config(self):
|
||||||
|
frame = tk.Frame(self)
|
||||||
|
frame.grid(sticky="nsew")
|
||||||
|
frame.columnconfigure(0, weight=1)
|
||||||
|
frame.rowconfigure(0, weight=1)
|
||||||
|
|
||||||
|
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
||||||
|
scrollbar.grid(row=0, column=1, sticky="ns")
|
||||||
|
|
||||||
|
listbox = tk.Listbox(frame)
|
||||||
|
listbox.grid(
|
||||||
|
row=0,
|
||||||
|
column=0,
|
||||||
|
selectmode=tk.SINGLE,
|
||||||
|
yscrollcommand=scrollbar.set,
|
||||||
|
sticky="nsew",
|
||||||
|
)
|
||||||
|
|
||||||
|
scrollbar.config(command=listbox.yview)
|
||||||
|
|
||||||
|
frame = tk.Frame(frame)
|
||||||
|
frame.grid(row=0, column=2, sticky="nsew")
|
||||||
|
frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
def draw_node_buttons(self):
|
||||||
|
frame = tk.Frame(self)
|
||||||
|
frame.grid(pady=2, sticky="ew")
|
||||||
|
for i in range(3):
|
||||||
|
frame.columnconfigure(i, weight=1)
|
||||||
|
|
||||||
|
button = tk.Button(frame, text="Create", command=self.click_create)
|
||||||
|
button.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
|
self.save_button = tk.Button(
|
||||||
|
frame, text="Save", state=tk.DISABLED, command=self.click_save
|
||||||
|
)
|
||||||
|
self.save_button.grid(row=0, column=1, sticky="ew")
|
||||||
|
|
||||||
|
self.delete_button = tk.Button(
|
||||||
|
frame, text="Delete", state=tk.DISABLED, command=self.click_delete
|
||||||
|
)
|
||||||
|
self.delete_button.grid(row=0, column=2, sticky="ew")
|
||||||
|
|
||||||
|
def draw_buttons(self):
|
||||||
|
frame = tk.Frame(self)
|
||||||
|
frame.grid(sticky="ew")
|
||||||
|
for i in range(2):
|
||||||
|
frame.columnconfigure(i, weight=1)
|
||||||
|
|
||||||
|
button = tk.Button(frame, text="Save Configuration")
|
||||||
|
button.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
|
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
||||||
|
button.grid(row=0, column=1, sticky="ew")
|
||||||
|
|
||||||
|
def click_create(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def click_save(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def click_delete(self):
|
||||||
|
pass
|
|
@ -6,58 +6,6 @@ from tkinter import messagebox
|
||||||
|
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
|
|
||||||
CORE_DEFAULT_GROUPS = ["EMANE", "FRR", "ProtoSvc", "Quagga", "Security", "Utility"]
|
|
||||||
DEFAULT_GROUP_RADIO_VALUE = {
|
|
||||||
"EMANE": 1,
|
|
||||||
"FRR": 2,
|
|
||||||
"ProtoSvc": 3,
|
|
||||||
"Quagga": 4,
|
|
||||||
"Security": 5,
|
|
||||||
"Utility": 6,
|
|
||||||
}
|
|
||||||
DEFAULT_GROUP_SERVICES = {
|
|
||||||
"EMANE": ["transportd"],
|
|
||||||
"FRR": [
|
|
||||||
"FRRBable",
|
|
||||||
"FRRBGP",
|
|
||||||
"FRROSPFv2",
|
|
||||||
"FRROSPFv3",
|
|
||||||
"FRRpimd",
|
|
||||||
"FRRRIP",
|
|
||||||
"FRRRIPNG",
|
|
||||||
"FRRzebra",
|
|
||||||
],
|
|
||||||
"ProtoSvc": ["MGEN_Sink", "MgenActor", "SMF"],
|
|
||||||
"Quagga": [
|
|
||||||
"Babel",
|
|
||||||
"BGP",
|
|
||||||
"OSPFv2",
|
|
||||||
"OSPFv3",
|
|
||||||
"OSPFv3MDR",
|
|
||||||
"RIP",
|
|
||||||
"RIPNG",
|
|
||||||
"Xpimd",
|
|
||||||
"zebra",
|
|
||||||
],
|
|
||||||
"Security": ["Firewall", "IPsec", "NAT", "VPNClient", "VPNServer"],
|
|
||||||
"Utility": [
|
|
||||||
"atd",
|
|
||||||
"DefaultMulticastRoute",
|
|
||||||
"DefaultRoute",
|
|
||||||
"DHCP",
|
|
||||||
"DHCPClient",
|
|
||||||
"FTP",
|
|
||||||
"HTTP",
|
|
||||||
"IPForward ",
|
|
||||||
"pcap",
|
|
||||||
"radvd",
|
|
||||||
"SSH",
|
|
||||||
"StaticRoute",
|
|
||||||
"ucarp",
|
|
||||||
"UserDefined",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class NodeServicesDialog(Dialog):
|
class NodeServicesDialog(Dialog):
|
||||||
def __init__(self, master, app, canvas_node):
|
def __init__(self, master, app, canvas_node):
|
||||||
|
@ -66,6 +14,7 @@ class NodeServicesDialog(Dialog):
|
||||||
self.core_groups = []
|
self.core_groups = []
|
||||||
self.service_to_config = None
|
self.service_to_config = None
|
||||||
self.config_frame = None
|
self.config_frame = None
|
||||||
|
self.services_list = None
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
@ -110,7 +59,7 @@ class NodeServicesDialog(Dialog):
|
||||||
listbox.grid(row=1, column=0, sticky="nsew")
|
listbox.grid(row=1, column=0, sticky="nsew")
|
||||||
listbox.bind("<<ListboxSelect>>", self.handle_group_change)
|
listbox.bind("<<ListboxSelect>>", self.handle_group_change)
|
||||||
|
|
||||||
for group in CORE_DEFAULT_GROUPS:
|
for group in sorted(self.app.core.services):
|
||||||
listbox.insert(tk.END, group)
|
listbox.insert(tk.END, group)
|
||||||
|
|
||||||
scrollbar.config(command=listbox.yview)
|
scrollbar.config(command=listbox.yview)
|
||||||
|
@ -127,7 +76,7 @@ class NodeServicesDialog(Dialog):
|
||||||
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
||||||
scrollbar.grid(row=1, column=1, sticky="ns")
|
scrollbar.grid(row=1, column=1, sticky="ns")
|
||||||
|
|
||||||
listbox = tk.Listbox(
|
self.services_list = tk.Listbox(
|
||||||
frame,
|
frame,
|
||||||
selectmode=tk.SINGLE,
|
selectmode=tk.SINGLE,
|
||||||
yscrollcommand=scrollbar.set,
|
yscrollcommand=scrollbar.set,
|
||||||
|
@ -135,10 +84,10 @@ class NodeServicesDialog(Dialog):
|
||||||
highlightthickness=0.5,
|
highlightthickness=0.5,
|
||||||
bd=0,
|
bd=0,
|
||||||
)
|
)
|
||||||
listbox.grid(row=1, column=0, sticky="nsew")
|
self.services_list.grid(row=1, column=0, sticky="nsew")
|
||||||
listbox.bind("<<ListboxSelect>>", self.handle_service_change)
|
self.services_list.bind("<<ListboxSelect>>", self.handle_service_change)
|
||||||
|
|
||||||
scrollbar.config(command=listbox.yview)
|
scrollbar.config(command=self.services_list.yview)
|
||||||
|
|
||||||
def draw_current_services(self):
|
def draw_current_services(self):
|
||||||
frame = tk.Frame(self.config_frame)
|
frame = tk.Frame(self.config_frame)
|
||||||
|
@ -188,11 +137,9 @@ class NodeServicesDialog(Dialog):
|
||||||
self.display_group_services(s)
|
self.display_group_services(s)
|
||||||
|
|
||||||
def display_group_services(self, group_name):
|
def display_group_services(self, group_name):
|
||||||
group_services_frame = self.config_frame.grid_slaves(row=0, column=1)[0]
|
self.services_list.delete(0, tk.END)
|
||||||
listbox = group_services_frame.grid_slaves(row=1, column=0)[0]
|
for service in sorted(self.app.core.services[group_name], key=lambda x: x.name):
|
||||||
listbox.delete(0, tk.END)
|
self.services_list.insert(tk.END, service.name)
|
||||||
for s in DEFAULT_GROUP_SERVICES[group_name]:
|
|
||||||
listbox.insert(tk.END, s)
|
|
||||||
|
|
||||||
def handle_service_change(self, event):
|
def handle_service_change(self, event):
|
||||||
print("select group service")
|
print("select group service")
|
||||||
|
|
Loading…
Add table
Reference in a new issue