Merge branch 'feature/1816_Database-Service-(Network-and-User-Interaction)' into feature/1752-dns-server-and-client

This commit is contained in:
Czar Echavez
2023-09-11 09:50:16 +01:00
13 changed files with 246 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ from primaite.simulator.network.transmission.transport_layer import Port
from primaite.simulator.system.applications.application import Application, ApplicationOperatingState
from primaite.simulator.system.core.sys_log import SysLog
from primaite.simulator.system.services.service import Service, ServiceOperatingState
from primaite.simulator.system.software import IOSoftware, SoftwareType
from primaite.simulator.system.software import IOSoftware
if TYPE_CHECKING:
from primaite.simulator.system.core.session_manager import SessionManager
@@ -37,6 +37,11 @@ class SoftwareManager:
self.file_system: FileSystem = file_system
def get_open_ports(self) -> List[Port]:
"""
Get a list of open ports.
:return: A list of all open ports on the Node.
"""
open_ports = [Port.ARP]
for software in self.port_protocol_mapping.values():
if software.operating_state in {ApplicationOperatingState.RUNNING, ServiceOperatingState.RUNNING}:
@@ -45,6 +50,11 @@ class SoftwareManager:
return open_ports
def install(self, software_class: Type[IOSoftwareClass]):
"""
Install an Application or Service.
:param software_class: The software class.
"""
if software_class in self._software_class_to_name_map:
self.sys_log.info(f"Cannot install {software_class} as it is already installed")
return
@@ -59,6 +69,11 @@ class SoftwareManager:
software.operating_state = ApplicationOperatingState.CLOSED
def uninstall(self, software_name: str):
"""
Uninstall an Application or Service.
:param software_name: The software name.
"""
if software_name in self.software:
software = self.software.pop(software_name) # noqa
del software