init work on database
This commit is contained in:
@@ -87,6 +87,14 @@ class FileSystemFileType(str, Enum):
|
|||||||
GZ = 31
|
GZ = 31
|
||||||
"Gzip compressed file."
|
"Gzip compressed file."
|
||||||
|
|
||||||
|
# Database file types
|
||||||
|
MDF = 32
|
||||||
|
"MS SQL Server primary database file"
|
||||||
|
NDF = 33
|
||||||
|
"MS SQL Server secondary database file"
|
||||||
|
LDF = 34
|
||||||
|
"MS SQL Server transaction log"
|
||||||
|
|
||||||
|
|
||||||
file_type_sizes_KB = {
|
file_type_sizes_KB = {
|
||||||
FileSystemFileType.UNKNOWN: 0,
|
FileSystemFileType.UNKNOWN: 0,
|
||||||
|
|||||||
41
src/primaite/simulator/system/services/database.py
Normal file
41
src/primaite/simulator/system/services/database.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
from primaite.simulator.file_system.file_system_file_type import FileSystemFileType
|
||||||
|
from primaite.simulator.network.hardware.base import Node
|
||||||
|
from primaite.simulator.system.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseService(Service):
|
||||||
|
"""TODO."""
|
||||||
|
|
||||||
|
def __init__(self, parent_node: Node, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self._setup_files_on_node()
|
||||||
|
|
||||||
|
def _setup_files_on_node(
|
||||||
|
self,
|
||||||
|
db_size: int = 1000,
|
||||||
|
use_secondary_db_file: bool = False,
|
||||||
|
secondary_db_size: int = 300,
|
||||||
|
folder_name: str = "database",
|
||||||
|
):
|
||||||
|
"""Set up files that are required by the database on the parent host.
|
||||||
|
|
||||||
|
:param db_size: Initial file size of the main database file, defaults to 1000
|
||||||
|
:type db_size: int, optional
|
||||||
|
:param use_secondary_db_file: Whether to use a secondary database file, defaults to False
|
||||||
|
:type use_secondary_db_file: bool, optional
|
||||||
|
:param secondary_db_size: Size of the secondary db file, defaults to None
|
||||||
|
:type secondary_db_size: int, optional
|
||||||
|
:param folder_name: Name of the folder which will be setup to hold the db files, defaults to "database"
|
||||||
|
:type folder_name: str, optional
|
||||||
|
"""
|
||||||
|
folder = self.parent.file_system.create_folder(folder_name)
|
||||||
|
self.parent.file_system.create_file("db_primary_store", db_size, FileSystemFileType.MDF, folder=folder)
|
||||||
|
self.parent.file_system.create_file("db_transaction_log", "1", FileSystemFileType.LDF, folder=folder)
|
||||||
|
if use_secondary_db_file:
|
||||||
|
self.parent.file_system.create_file(
|
||||||
|
"db_secondary_store", secondary_db_size, FileSystemFileType.NDF, folder=folder
|
||||||
|
)
|
||||||
|
|
||||||
|
# todo next:
|
||||||
|
# create session? (maybe not)
|
||||||
|
# add actions for setting service state to compromised? (probably definitely)
|
||||||
@@ -2,6 +2,7 @@ from abc import abstractmethod
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
|
from primaite.simulator.network.hardware.base import Node
|
||||||
from primaite.simulator.system.software import IOSoftware
|
from primaite.simulator.system.software import IOSoftware
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +33,17 @@ class Service(IOSoftware):
|
|||||||
operating_state: ServiceOperatingState
|
operating_state: ServiceOperatingState
|
||||||
"The current operating state of the Service."
|
"The current operating state of the Service."
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def __init__(self, parent_node: Node, **kwargs):
|
||||||
|
"""Create the service on a node.
|
||||||
|
|
||||||
|
:param parent_node: The node on which this service runs.
|
||||||
|
:type parent_node: Node
|
||||||
|
"""
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.parent: Node = parent_node
|
||||||
|
self.parent.software_manager.add_service(self)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def describe_state(self) -> Dict:
|
def describe_state(self) -> Dict:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user