From 8feb2db954bcb153a4912d2096e8e34f0771b395 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 31 Jan 2025 15:29:10 +0000 Subject: [PATCH] Fix properties --- src/primaite/game/agent/agent_log.py | 5 ++-- src/primaite/game/game.py | 26 ------------------- .../services/database/database_service.py | 7 ++--- .../system/services/dns/dns_client.py | 16 +++++++----- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/primaite/game/agent/agent_log.py b/src/primaite/game/agent/agent_log.py index 5d9dc848..ddf14489 100644 --- a/src/primaite/game/agent/agent_log.py +++ b/src/primaite/game/agent/agent_log.py @@ -65,8 +65,9 @@ class AgentLog: The logger is set to the DEBUG level, and is equipped with a handler that writes to a file and filters out JSON-like messages. """ - if not SIM_OUTPUT.save_agent_logs: - return + # TODO: uncomment this once we figure out why it's broken + # if not SIM_OUTPUT.save_agent_logs: + # return log_path = self._get_log_path() file_handler = logging.FileHandler(filename=log_path) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index b869cfd4..a8e23d56 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -406,32 +406,6 @@ class PrimaiteGame: if "service_install_duration" in defaults_config: new_service.install_duration = defaults_config["service_install_duration"] - # service-dependent options - if service_type == "DNSClient": - if "options" in service_cfg: - opt = service_cfg["options"] - if "dns_server" in opt: - new_service.dns_server = IPv4Address(opt["dns_server"]) - if service_type == "DNSServer": - if "options" in service_cfg: - opt = service_cfg["options"] - if "domain_mapping" in opt: - for domain, ip in opt["domain_mapping"].items(): - new_service.dns_register(domain, IPv4Address(ip)) - if service_type == "DatabaseService": - if "options" in service_cfg: - opt = service_cfg["options"] - new_service.password = opt.get("db_password", None) - if "backup_server_ip" in opt: - new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip"))) - if service_type == "FTPServer": - if "options" in service_cfg: - opt = service_cfg["options"] - new_service.server_password = opt.get("server_password") - if service_type == "NTPClient": - if "options" in service_cfg: - opt = service_cfg["options"] - new_service.ntp_server = IPv4Address(opt.get("ntp_server_ip")) if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: new_application = None diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index d65f05bd..1745b9d1 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -35,9 +35,6 @@ class DatabaseService(Service, identifier="DatabaseService"): config: "DatabaseService.ConfigSchema" = Field(default_factory=lambda: DatabaseService.ConfigSchema()) - password: Optional[str] = None - """Password that needs to be provided by clients if they want to connect to the DatabaseService.""" - backup_server_ip: IPv4Address = None """IP address of the backup server.""" @@ -60,6 +57,10 @@ class DatabaseService(Service, identifier="DatabaseService"): """Convenience property for accessing the password.""" return self.config.db_password + @password.setter + def password(self, val: str) -> None: + self.config.db_password = val + def install(self): """ Perform first-time setup of the DatabaseService. diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 1c64c9a9..825896e0 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -30,8 +30,6 @@ class DNSClient(Service, identifier="DNSClient"): config: "DNSClient.ConfigSchema" = Field(default_factory=lambda: DNSClient.ConfigSchema()) dns_cache: Dict[str, IPv4Address] = {} "A dict of known mappings between domain/URLs names and IPv4 addresses." - dns_server: Optional[IPv4Address] = None - "The DNS Server the client sends requests to." def __init__(self, **kwargs): kwargs["name"] = "DNSClient" @@ -43,11 +41,6 @@ class DNSClient(Service, identifier="DNSClient"): super().__init__(**kwargs) self.start() - @property - def dns_server(self) -> Optional[IPV4Address]: - """Convenience property for accessing the dns server configuration.""" - return self.config.dns_server - def describe_state(self) -> Dict: """ Describes the current state of the software. @@ -61,6 +54,15 @@ class DNSClient(Service, identifier="DNSClient"): state = super().describe_state() return state + @property + def dns_server(self) -> Optional[IPV4Address]: + """Convenience property for accessing the dns server configuration.""" + return self.config.dns_server + + @dns_server.setter + def dns_server(self, val: IPV4Address) -> None: + self.config.dns_server = val + def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address) -> bool: """ Adds a domain name to the DNS Client cache.