copy service config from other node
This commit is contained in:
parent
54994f4c96
commit
41ae67b559
3 changed files with 85 additions and 22 deletions
|
@ -933,3 +933,6 @@ class CoreClient:
|
|||
config = self.emane_model_configs.get(_from)
|
||||
if config:
|
||||
self.emane_model_configs[_to] = config
|
||||
|
||||
def get_service_commands(self):
|
||||
self.create_nodes_and_links()
|
||||
|
|
|
@ -42,9 +42,27 @@ class CopyServiceConfigDialog(Dialog):
|
|||
treeid, "end", text=service, tags="service"
|
||||
)
|
||||
tree_ids[service] = serviceid
|
||||
print(config)
|
||||
# for filename, data in config.items():
|
||||
# self.tree.insert(serviceid, "end", text=filename)
|
||||
cmdup = config.startup[:]
|
||||
cmddown = config.shutdown[:]
|
||||
cmdval = config.validate[:]
|
||||
self.tree.insert(
|
||||
serviceid,
|
||||
"end",
|
||||
text=f"cmdup=({str(cmdup)[1:-1]})",
|
||||
tags=("cmd", "up"),
|
||||
)
|
||||
self.tree.insert(
|
||||
serviceid,
|
||||
"end",
|
||||
text=f"cmddown=({str(cmddown)[1:-1]})",
|
||||
tags=("cmd", "down"),
|
||||
)
|
||||
self.tree.insert(
|
||||
serviceid,
|
||||
"end",
|
||||
text=f"cmdval=({str(cmdval)[1:-1]})",
|
||||
tags=("cmd", "val"),
|
||||
)
|
||||
if files:
|
||||
for service, configs in files.items():
|
||||
if service in tree_ids:
|
||||
|
@ -83,6 +101,29 @@ class CopyServiceConfigDialog(Dialog):
|
|||
if self.parent.filename_combobox.get() == filename:
|
||||
self.parent.service_file_data.text.delete(1.0, "end")
|
||||
self.parent.service_file_data.text.insert("end", data)
|
||||
if "cmd" in item["tags"]:
|
||||
nid, service = self.get_node_service(selected)
|
||||
if service == self.master.service_name:
|
||||
cmds = self.service_configs[nid][service]
|
||||
if "up" in item["tags"]:
|
||||
self.master.append_commands(
|
||||
self.master.startup_commands,
|
||||
self.master.startup_commands_listbox,
|
||||
cmds.startup,
|
||||
)
|
||||
elif "down" in item["tags"]:
|
||||
self.master.append_commands(
|
||||
self.master.shutdown_commands,
|
||||
self.master.shutdown_commands_listbox,
|
||||
cmds.shutdown,
|
||||
)
|
||||
|
||||
elif "val" in item["tags"]:
|
||||
self.master.append_commands(
|
||||
self.master.validate_commands,
|
||||
self.master.validate_commands_listbox,
|
||||
cmds.validate,
|
||||
)
|
||||
self.destroy()
|
||||
|
||||
def click_view(self):
|
||||
|
@ -94,6 +135,17 @@ class CopyServiceConfigDialog(Dialog):
|
|||
data = self.file_configs[nid][service][item["text"]]
|
||||
dialog = ViewConfigDialog(self, self.app, self.node_id, data)
|
||||
dialog.show()
|
||||
if "cmd" in item["tags"]:
|
||||
nid, service = self.get_node_service(selected)
|
||||
cmds = self.service_configs[nid][service]
|
||||
if "up" in item["tags"]:
|
||||
data = f"({str(cmds.startup[:])[1:-1]})"
|
||||
elif "down" in item["tags"]:
|
||||
data = f"({str(cmds.shutdown[:])[1:-1]})"
|
||||
elif "val" in item["tags"]:
|
||||
data = f"({str(cmds.validate[:])[1:-1]})"
|
||||
dialog = ViewConfigDialog(self, self.app, self.node_id, data)
|
||||
dialog.show()
|
||||
|
||||
def get_node_service(self, selected):
|
||||
service_tree_id = self.tree.parent(selected[0])
|
||||
|
@ -115,7 +167,7 @@ class ViewConfigDialog(Dialog):
|
|||
frame = ttk.Frame(self.top, padding=FRAME_PAD)
|
||||
frame.grid(row=0, column=0)
|
||||
label = ttk.Label(frame, text="File: ")
|
||||
label.grid(row=0, column=0, sticky="ew")
|
||||
label.grid(row=0, column=0, sticky="ew", padx=PADX)
|
||||
|
||||
self.service_data = CodeText(self.top)
|
||||
self.service_data.grid(row=1, column=0, sticky="nsew")
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"Service configuration dialog"
|
||||
import logging
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
|
@ -399,26 +398,29 @@ class ServiceConfigDialog(Dialog):
|
|||
|
||||
def click_apply(self):
|
||||
current_listbox = self.master.current.listbox
|
||||
if not self.is_custom_service():
|
||||
if not self.is_custom_service_config() and not self.is_custom_service_file():
|
||||
if self.node_id in self.service_configs:
|
||||
self.service_configs[self.node_id].pop(self.service_name, None)
|
||||
current_listbox.itemconfig(current_listbox.curselection()[0], bg="")
|
||||
self.destroy()
|
||||
return
|
||||
startup_commands = self.startup_commands_listbox.get(0, "end")
|
||||
shutdown_commands = self.shutdown_commands_listbox.get(0, "end")
|
||||
validate_commands = self.validate_commands_listbox.get(0, "end")
|
||||
|
||||
try:
|
||||
config = self.core.set_node_service(
|
||||
self.node_id,
|
||||
self.service_name,
|
||||
startup_commands,
|
||||
validate_commands,
|
||||
shutdown_commands,
|
||||
)
|
||||
if self.node_id not in self.service_configs:
|
||||
self.service_configs[self.node_id] = {}
|
||||
self.service_configs[self.node_id][self.service_name] = config
|
||||
if self.is_custom_service_config():
|
||||
startup_commands = self.startup_commands_listbox.get(0, "end")
|
||||
shutdown_commands = self.shutdown_commands_listbox.get(0, "end")
|
||||
validate_commands = self.validate_commands_listbox.get(0, "end")
|
||||
config = self.core.set_node_service(
|
||||
self.node_id,
|
||||
self.service_name,
|
||||
startup_commands,
|
||||
validate_commands,
|
||||
shutdown_commands,
|
||||
)
|
||||
if self.node_id not in self.service_configs:
|
||||
self.service_configs[self.node_id] = {}
|
||||
self.service_configs[self.node_id][self.service_name] = config
|
||||
|
||||
for file in self.modified_files:
|
||||
if self.node_id not in self.file_configs:
|
||||
self.file_configs[self.node_id] = {}
|
||||
|
@ -452,7 +454,7 @@ class ServiceConfigDialog(Dialog):
|
|||
else:
|
||||
self.modified_files.discard(filename)
|
||||
|
||||
def is_custom_service(self):
|
||||
def is_custom_service_config(self):
|
||||
startup_commands = self.startup_commands_listbox.get(0, "end")
|
||||
shutdown_commands = self.shutdown_commands_listbox.get(0, "end")
|
||||
validate_commands = self.validate_commands_listbox.get(0, "end")
|
||||
|
@ -460,9 +462,11 @@ class ServiceConfigDialog(Dialog):
|
|||
set(self.default_startup) != set(startup_commands)
|
||||
or set(self.default_validate) != set(validate_commands)
|
||||
or set(self.default_shutdown) != set(shutdown_commands)
|
||||
or len(self.modified_files) > 0
|
||||
)
|
||||
|
||||
def is_custom_service_file(self):
|
||||
return len(self.modified_files) > 0
|
||||
|
||||
def click_defaults(self):
|
||||
if self.node_id in self.service_configs:
|
||||
self.service_configs[self.node_id].pop(self.service_name, None)
|
||||
|
@ -483,6 +487,10 @@ class ServiceConfigDialog(Dialog):
|
|||
self.shutdown_commands_listbox.insert(tk.END, cmd)
|
||||
|
||||
def click_copy(self):
|
||||
logging.info("not implemented")
|
||||
dialog = CopyServiceConfigDialog(self, self.app, self.node_id)
|
||||
dialog.show()
|
||||
|
||||
def append_commands(self, commands, listbox, to_add):
|
||||
for cmd in to_add:
|
||||
commands.append(cmd)
|
||||
listbox.insert(tk.END, cmd)
|
||||
|
|
Loading…
Reference in a new issue