Merge branch 'coretk' of https://github.com/coreemu/core into coretk

This commit is contained in:
bharnden 2019-11-22 12:52:45 -08:00
commit e20da62366
5 changed files with 91 additions and 72 deletions

View file

@ -8,8 +8,6 @@ from core.api.grpc import client, core_pb2
from coretk.dialogs.sessions import SessionsDialog
from coretk.interface import InterfaceManager
from coretk.nodeutils import NodeDraw, NodeUtils
from coretk.servicefileconfig import ServiceFileConfig
from coretk.servicenodeconfig import ServiceNodeConfig
OBSERVERS = {
"processes": "ps",
@ -49,6 +47,7 @@ class CoreClient:
self.master = app.master
self.interface_helper = None
self.services = {}
self.default_services = {}
self.emane_models = []
self.observer = None
@ -73,11 +72,12 @@ class CoreClient:
self.mobility_configs = {}
self.emane_model_configs = {}
self.emane_config = None
self.serviceconfig_manager = ServiceNodeConfig(app)
self.servicefileconfig_manager = ServiceFileConfig()
self.created_nodes = set()
self.created_links = set()
self.service_configs = {}
self.file_configs = {}
def set_observer(self, value):
self.observer = value
@ -138,6 +138,8 @@ class CoreClient:
self.wlan_configs.clear()
self.mobility_configs.clear()
self.emane_config = None
self.service_configs.clear()
self.file_configs.clear()
# get session data
response = self.client.get_session(self.session_id)
@ -269,9 +271,15 @@ class CoreClient:
dialog = SessionsDialog(self.app, self.app)
dialog.show()
response = self.client.get_service_defaults(self.session_id)
logging.debug("get service defaults: %s", response)
self.default_services = {
x.node_type: set(x.services) for x in response.defaults
}
def get_session_state(self):
response = self.client.get_session(self.session_id)
# logging.info("get session: %s", response)
logging.info("get session: %s", response)
return response.session.state
def edit_node(self, node_id, x, y):
@ -312,8 +320,7 @@ class CoreClient:
emane_model_configs = self.get_emane_model_configs_proto()
hooks = list(self.hooks.values())
service_configs = self.get_service_config_proto()
print(service_configs)
# service_file_configs = self.get_service_file_config_proto()
file_configs = self.get_service_file_config_proto()
self.created_links.clear()
self.created_nodes.clear()
if self.emane_config:
@ -331,8 +338,10 @@ class CoreClient:
wlan_configs,
mobility_configs,
service_configs,
file_configs,
)
logging.debug("Start session %s, result: %s", self.session_id, response.result)
print(self.client.get_session(self.session_id))
def stop_session(self):
response = self.client.stop_session(session_id=self.session_id)
@ -375,6 +384,9 @@ class CoreClient:
self.session_id, node_id, service_name, startups, validations, shutdowns
)
logging.debug("set node service %s", response)
response = self.client.get_node_service(self.session_id, node_id, service_name)
logging.debug("get node service : %s", response)
return response.service
def get_node_service_file(self, node_id, service_name, file_name):
response = self.client.get_node_service_file(
@ -395,10 +407,13 @@ class CoreClient:
:return: nothing
"""
node_protos = [x.core_node for x in self.canvas_nodes.values()]
link_protos = list(self.links.values())
self.client.set_session_state(self.session_id, core_pb2.SessionState.DEFINITION)
print(node_protos)
if self.get_session_state() != core_pb2.SessionState.DEFINITION:
self.client.set_session_state(
self.session_id, core_pb2.SessionState.DEFINITION
)
for node_proto in node_protos:
if node_proto.id not in self.created_nodes:
response = self.client.add_node(self.session_id, node_proto)
@ -421,6 +436,7 @@ class CoreClient:
self.created_links.add(
tuple([link_proto.node_one_id, link_proto.node_two_id])
)
print(self.app.core.client.get_session(self.app.core.session_id))
def close(self):
"""
@ -472,14 +488,6 @@ class CoreClient:
image=image,
emane=emane,
)
# set default service configurations
# TODO: need to deal with this and custom node cases
if node_type == core_pb2.NodeType.DEFAULT:
self.serviceconfig_manager.node_default_services_configuration(
node_id=node_id, node_model=model
)
logging.debug(
"adding node to core session: %s, coords: (%s, %s), name: %s",
self.session_id,
@ -607,34 +615,27 @@ class CoreClient:
def get_service_config_proto(self):
configs = []
for (
node_id,
service_configs,
) in self.serviceconfig_manager.configurations.items():
for service, config in service_configs.items():
if service in self.serviceconfig_manager.current_services[node_id]:
config = core_pb2.ServiceConfig(
node_id=node_id,
service=service,
startup=config.startup,
validate=config.validate,
shutdown=config.shutdown,
)
configs.append(config)
for node_id, services in self.service_configs.items():
for name, config in services.items():
config_proto = core_pb2.ServiceConfig(
node_id=node_id,
service=name,
startup=config.startup,
validate=config.validate,
shutdown=config.shutdown,
)
configs.append(config_proto)
return configs
def get_service_file_config_proto(self):
configs = []
for (
node_id,
service_file_configs,
) in self.servicefileconfig_manager.configurations.items():
for service, file_configs in service_file_configs.items():
for file, data in file_configs.items():
config = core_pb2.ServiceFileConfig(
for (node_id, file_configs) in self.file_configs.items():
for service, file_config in file_configs.items():
for file, data in file_config.items():
config_proto = core_pb2.ServiceFileConfig(
node_id=node_id, service=service, file=file, data=data
)
configs.append(config)
configs.append(config_proto)
return configs
def run(self, node_id):

View file

@ -12,18 +12,21 @@ from coretk.widgets import CheckboxList, ListboxScroll
class NodeService(Dialog):
def __init__(self, master, app, canvas_node, services=None):
super().__init__(master, app, "Node Services", modal=True)
self.app = app
self.canvas_node = canvas_node
self.node_id = canvas_node.core_node.id
self.groups = None
self.services = None
self.current = None
if services is None:
services = set(
app.core.serviceconfig_manager.current_services[self.node_id]
)
services = canvas_node.core_node.services
model = canvas_node.core_node.model
if len(services) == 0:
services = set(self.app.core.default_services[model])
else:
services = set(services)
self.current_services = services
self.service_manager = self.app.core.serviceconfig_manager
self.service_file_manager = self.app.core.servicefileconfig_manager
self.draw()
def draw(self):
@ -72,22 +75,15 @@ class NodeService(Dialog):
index = selection[0]
group = self.groups.listbox.get(index)
self.services.clear()
for service in sorted(self.app.core.services[group], key=lambda x: x.name):
checked = service.name in self.current_services
self.services.add(service.name, checked)
for name in sorted(self.app.core.services[group]):
checked = name in self.current_services
self.services.add(name, checked)
def service_clicked(self, name, var):
if var.get() and name not in self.current_services:
if self.service_manager.node_new_service_configuration(self.node_id, name):
self.current_services.add(name)
else:
for checkbutton in self.services.frame.winfo_children():
if name == checkbutton.cget("text"):
checkbutton.config(variable=tk.BooleanVar(value=False))
self.current_services.add(name)
elif not var.get() and name in self.current_services:
self.current_services.remove(name)
self.service_manager.current_services[self.node_id].remove(name)
self.current.listbox.delete(0, tk.END)
for name in sorted(self.current_services):
self.current.listbox.insert(tk.END, name)
@ -108,8 +104,15 @@ class NodeService(Dialog):
)
def click_save(self):
print("not implemented")
print(self.current_services)
if (
self.current_services
!= self.app.core.default_services[self.canvas_node.core_node.model]
):
self.canvas_node.core_node.services[:] = self.current_services
else:
if len(self.canvas_node.core_node.services) > 0:
self.canvas_node.core_node.services[:] = []
self.destroy()
def click_cancel(self):
self.current_services = None

View file

@ -14,7 +14,7 @@ class ServiceConfiguration(Dialog):
def __init__(self, master, app, service_name, node_id):
super().__init__(master, app, f"{service_name} service", modal=True)
self.app = app
self.service_manager = app.core.serviceconfig_manager
self.core = app.core
self.node_id = node_id
self.service_name = service_name
self.radiovar = tk.IntVar()
@ -50,18 +50,19 @@ class ServiceConfiguration(Dialog):
def load(self):
# create nodes and links in definition state for getting and setting service file
self.app.core.create_nodes_and_links()
# load data from local memory
if self.service_name in self.service_manager.configurations[self.node_id]:
service_config = self.service_manager.configurations[self.node_id][
service_configs = self.app.core.service_configs
if (
self.node_id in service_configs
and self.service_name in service_configs[self.node_id]
):
service_config = self.app.core.service_configs[self.node_id][
self.service_name
]
else:
self.service_manager.node_custom_service_configuration(
service_config = self.app.core.get_node_service(
self.node_id, self.service_name
)
service_config = self.service_manager.configurations[self.node_id][
self.service_name
]
self.dependencies = [x for x in service_config.dependencies]
self.executables = [x for x in service_config.executables]
self.metadata = service_config.meta
@ -78,9 +79,12 @@ class ServiceConfiguration(Dialog):
self.temp_service_files = {
x: self.original_service_files[x] for x in self.original_service_files
}
configs = self.app.core.servicefileconfig_manager.configurations
if self.node_id in configs and self.service_name in configs[self.node_id]:
for file, data in configs[self.node_id][self.service_name].items():
file_configs = self.app.core.file_configs
if (
self.node_id in file_configs
and self.service_name in file_configs[self.node_id]
):
for file, data in file_configs[self.node_id][self.service_name].items():
self.temp_service_files[file] = data
def draw(self):
@ -359,20 +363,31 @@ class ServiceConfiguration(Dialog):
entry.delete(0, tk.END)
def click_apply(self):
service_configs = self.app.core.service_configs
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")
self.service_manager.node_service_custom_configuration(
config = self.core.set_node_service(
self.node_id,
self.service_name,
startup_commands,
validate_commands,
shutdown_commands,
)
if self.node_id not in service_configs:
service_configs[self.node_id] = {}
if self.service_name not in service_configs[self.node_id]:
self.app.core.service_configs[self.node_id][self.service_name] = config
for file in self.modified_files:
self.app.core.servicefileconfig_manager.set_custom_service_file_config(
self.node_id, self.service_name, file, self.temp_service_files[file]
)
file_configs = self.app.core.file_configs
if self.node_id not in file_configs:
file_configs[self.node_id] = {}
if self.service_name not in file_configs[self.node_id]:
file_configs[self.node_id][self.service_name] = {}
file_configs[self.node_id][self.service_name][
file
] = self.temp_service_files[file]
self.app.core.set_node_service_file(
self.node_id, self.service_name, file, self.temp_service_files[file]
)