Exemplo n.º 1
0
    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")
        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 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:
                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])
        except grpc.RpcError as e:
            show_grpc_error(e)
        self.destroy()
Exemplo n.º 2
0
 def __init__(
     self,
     master: Any,
     app: "Application",
     node: core_pb2.Node,
     model: str,
     interface: int = None,
 ):
     super().__init__(master,
                      app,
                      f"{node.name} {model} Configuration",
                      modal=True)
     self.node = node
     self.model = f"emane_{model}"
     self.interface = interface
     self.config_frame = None
     self.has_error = False
     try:
         self.config = self.app.core.get_emane_model_config(
             self.node.id, self.model, self.interface)
         self.draw()
     except grpc.RpcError as e:
         show_grpc_error(e, self.app, self.app)
         self.has_error = True
         self.destroy()
Exemplo n.º 3
0
    def click_apply(self):
        current_listbox = self.master.current.listbox
        if not self.is_custom():
            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

        try:
            node_config = self.service_configs.setdefault(self.node_id, {})
            service_config = node_config.setdefault(self.service_name, {})
            if self.config_frame:
                self.config_frame.parse_config()
                service_config["config"] = {
                    x.name: x.value
                    for x in self.config.values()
                }
            templates_config = service_config.setdefault("templates", {})
            for file in self.modified_files:
                templates_config[file] = self.temp_service_files[file]
            all_current = current_listbox.get(0, tk.END)
            current_listbox.itemconfig(all_current.index(self.service_name),
                                       bg="green")
        except grpc.RpcError as e:
            show_grpc_error(e, self.top, self.app)
        self.destroy()
Exemplo n.º 4
0
 def click_pause(self):
     self.set_pause()
     session_id = self.app.core.session_id
     try:
         self.app.core.client.mobility_action(session_id, self.node.id,
                                              MobilityAction.PAUSE)
     except grpc.RpcError as e:
         show_grpc_error(e, self.top, self.app)
Exemplo n.º 5
0
 def click_stop(self):
     self.set_stop()
     session_id = self.app.core.session_id
     try:
         self.app.core.client.mobility_action(session_id, self.node.id,
                                              MobilityAction.STOP)
     except grpc.RpcError as e:
         show_grpc_error(e)
Exemplo n.º 6
0
 def get_sessions(self):
     try:
         response = self.app.core.client.get_sessions()
         logging.info("sessions: %s", response)
         return response.sessions
     except grpc.RpcError as e:
         show_grpc_error(e)
         self.destroy()
Exemplo n.º 7
0
 def get_config(self):
     try:
         session_id = self.app.core.session_id
         response = self.app.core.client.get_session_options(session_id)
         return response.config
     except grpc.RpcError as e:
         show_grpc_error(e)
         self.destroy()
Exemplo n.º 8
0
Arquivo: node.py Projeto: lyma/core
 def on_enter(self, event: tk.Event):
     if self.app.core.is_runtime() and self.app.core.observer:
         self.tooltip.text.set("waiting...")
         self.tooltip.on_enter(event)
         try:
             output = self.app.core.run(self.core_node.id)
             self.tooltip.text.set(output)
         except grpc.RpcError as e:
             show_grpc_error(e, self.app, self.app)
Exemplo n.º 9
0
 def get_sessions(self) -> Iterable[core_pb2.SessionSummary]:
     try:
         response = self.app.core.client.get_sessions()
         logging.info("sessions: %s", response)
         return response.sessions
     except grpc.RpcError as e:
         show_grpc_error(e, self.app, self.app)
         self.has_error = True
         self.destroy()
Exemplo n.º 10
0
 def save(self):
     config = self.config_frame.parse_config()
     try:
         session_id = self.app.core.session_id
         response = self.app.core.client.set_session_options(
             session_id, config)
         logging.info("saved session config: %s", response)
     except grpc.RpcError as e:
         show_grpc_error(e, self.top, self.app)
     self.destroy()
Exemplo n.º 11
0
 def __init__(self, master, app, canvas_node):
     super().__init__(master,
                      app,
                      f"{canvas_node.core_node.name} Wlan Configuration",
                      modal=True)
     self.canvas_node = canvas_node
     self.node = canvas_node.core_node
     self.config_frame = None
     try:
         self.config = self.app.core.get_wlan_config(self.node.id)
     except grpc.RpcError as e:
         show_grpc_error(e)
         self.destroy()
     self.draw()
Exemplo n.º 12
0
 def __init__(self, master, app, node, model, interface=None):
     super().__init__(master, app, f"{node.name} {model} Configuration", modal=True)
     self.node = node
     self.model = f"emane_{model}"
     self.interface = interface
     self.config_frame = None
     try:
         self.config = self.app.core.get_emane_model_config(
             self.node.id, self.model, self.interface
         )
     except grpc.RpcError as e:
         show_grpc_error(e)
         self.destroy()
     self.draw()
Exemplo n.º 13
0
    def click_apply(self):
        current_listbox = self.master.current.listbox
        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

        try:
            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,
                    startups=startup_commands,
                    validations=validate_commands,
                    shutdowns=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] = {}
                if self.service_name not in self.file_configs[self.node_id]:
                    self.file_configs[self.node_id][self.service_name] = {}
                self.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])
            all_current = current_listbox.get(0, tk.END)
            current_listbox.itemconfig(all_current.index(self.service_name),
                                       bg="green")
        except grpc.RpcError as e:
            show_grpc_error(e, self.top, self.app)
        self.destroy()
Exemplo n.º 14
0
 def __init__(self, master: "Application", app: "Application",
              canvas_node: "CanvasNode"):
     super().__init__(master,
                      app,
                      f"{canvas_node.core_node.name} Wlan Configuration",
                      modal=True)
     self.canvas_node = canvas_node
     self.node = canvas_node.core_node
     self.config_frame = None
     self.has_error = False
     try:
         self.config = self.app.core.get_wlan_config(self.node.id)
         self.draw()
     except grpc.RpcError as e:
         show_grpc_error(e, self.app, self.app)
         self.has_error = True
         self.destroy()
Exemplo n.º 15
0
    def load(self):
        try:
            self.core.create_nodes_and_links()
            service = self.core.config_services[self.service_name]
            self.dependencies = service.dependencies[:]
            self.executables = service.executables[:]
            self.directories = service.directories[:]
            self.templates = service.files[:]
            self.startup_commands = service.startup[:]
            self.validation_commands = service.validate[:]
            self.shutdown_commands = service.shutdown[:]
            self.validation_mode = service.validation_mode
            self.validation_time = service.validation_timer
            self.validation_period.set(service.validation_period)

            response = self.core.client.get_config_service_defaults(
                self.service_name)
            self.original_service_files = response.templates
            self.temp_service_files = dict(self.original_service_files)

            self.modes = sorted(x.name for x in response.modes)
            self.mode_configs = {x.name: x.config for x in response.modes}

            node_configs = self.service_configs.get(self.node_id, {})
            service_config = node_configs.get(self.service_name, {})

            self.config = response.config
            self.default_config = {
                x.name: x.value
                for x in self.config.values()
            }
            custom_config = service_config.get("config")
            if custom_config:
                for key, value in custom_config.items():
                    self.config[key].value = value
            logging.info("default config: %s", self.default_config)

            custom_templates = service_config.get("templates", {})
            for file, data in custom_templates.items():
                self.modified_files.add(file)
                self.temp_service_files[file] = data
        except grpc.RpcError as e:
            self.has_error = True
            show_grpc_error(e, self.app, self.app)
Exemplo n.º 16
0
    def click_apply(self):
        if (not self.is_custom_command() and not self.is_custom_service_file()
                and not self.has_new_files()
                and not self.is_custom_directory()):
            self.service_configs.get(self.node_id,
                                     {}).pop(self.service_name, None)
            self.current_service_color("")
            self.destroy()
            return

        try:
            if (self.is_custom_command() or self.has_new_files()
                    or self.is_custom_directory()):
                startup, validate, shutdown = self.get_commands()
                config = self.core.set_node_service(
                    self.node_id,
                    self.service_name,
                    dirs=self.temp_directories,
                    files=list(self.filename_combobox["values"]),
                    startups=startup,
                    validations=validate,
                    shutdowns=shutdown,
                )
                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] = {}
                if self.service_name not in self.file_configs[self.node_id]:
                    self.file_configs[self.node_id][self.service_name] = {}
                self.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])
            self.current_service_color("green")
        except grpc.RpcError as e:
            show_grpc_error(e, self.top, self.app)
        self.destroy()
Exemplo n.º 17
0
    def load(self) -> bool:
        try:
            self.app.core.create_nodes_and_links()
            default_config = self.app.core.get_node_service(
                self.node_id, self.service_name)
            self.default_startup = default_config.startup[:]
            self.default_validate = default_config.validate[:]
            self.default_shutdown = default_config.shutdown[:]
            custom_configs = self.service_configs
            if (self.node_id in custom_configs
                    and self.service_name in custom_configs[self.node_id]):
                service_config = custom_configs[self.node_id][
                    self.service_name]
            else:
                service_config = default_config

            self.dependencies = service_config.dependencies[:]
            self.executables = service_config.executables[:]
            self.metadata = service_config.meta
            self.filenames = service_config.configs[:]
            self.startup_commands = service_config.startup[:]
            self.validation_commands = service_config.validate[:]
            self.shutdown_commands = service_config.shutdown[:]
            self.validation_mode = service_config.validation_mode
            self.validation_time = service_config.validation_timer
            self.original_service_files = {
                x: self.app.core.get_node_service_file(self.node_id,
                                                       self.service_name, x)
                for x in self.filenames
            }
            self.temp_service_files = dict(self.original_service_files)
            file_configs = self.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
        except grpc.RpcError as e:
            self.has_error = True
            show_grpc_error(e, self.master, self.app)
Exemplo n.º 18
0
 def __init__(self, master: "Application", app: "Application",
              canvas_node: "CanvasNode"):
     super().__init__(master,
                      app,
                      f"{canvas_node.core_node.name} Wlan Configuration",
                      modal=True)
     self.canvas_node = canvas_node
     self.node = canvas_node.core_node
     self.config_frame = None
     self.range_entry = None
     self.has_error = False
     self.canvas = app.canvas
     self.ranges = {}
     self.positive_int = self.app.master.register(self.validate_and_update)
     try:
         self.config = self.app.core.get_wlan_config(self.node.id)
         self.init_draw_range()
         self.draw()
     except grpc.RpcError as e:
         show_grpc_error(e, self.app, self.app)
         self.has_error = True
         self.destroy()
Exemplo n.º 19
0
 def load(self):
     try:
         self.app.core.create_nodes_and_links()
         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:
             service_config = self.app.core.get_node_service(
                 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
         self.filenames = [x for x in service_config.configs]
         self.startup_commands = [x for x in service_config.startup]
         self.validation_commands = [x for x in service_config.validate]
         self.shutdown_commands = [x for x in service_config.shutdown]
         self.validation_mode = service_config.validation_mode
         self.validation_time = service_config.validation_timer
         self.original_service_files = {
             x: self.app.core.get_node_service_file(self.node_id,
                                                    self.service_name, x)
             for x in self.filenames
         }
         self.temp_service_files = {
             x: self.original_service_files[x]
             for x in self.original_service_files
         }
         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
     except grpc.RpcError as e:
         show_grpc_error(e)
Exemplo n.º 20
0
    def setup(self):
        """
        Query sessions, if there exist any, prompt whether to join one
        """
        try:
            self.client.connect()
            # get service information
            response = self.client.get_services()
            for service in response.services:
                group_services = self.services.setdefault(service.group, set())
                group_services.add(service.name)

            # get config service informations
            response = self.client.get_config_services()
            for service in response.services:
                self.config_services[service.name] = service
                group_services = self.config_services_groups.setdefault(
                    service.group, set()
                )
                group_services.add(service.name)

            # if there are no sessions, create a new session, else join a session
            response = self.client.get_sessions()
            sessions = response.sessions
            if len(sessions) == 0:
                self.create_new_session()
            else:
                dialog = SessionsDialog(self.app, self.app, True)
                dialog.show()
            response = self.client.get_service_defaults(self.session_id)
            self.default_services = {
                x.node_type: set(x.services) for x in response.defaults
            }
        except grpc.RpcError as e:
            show_grpc_error(e, self.app, self.app)
            self.app.close()