#915 - Created app dirs and set as constants in the top-level init.
- renamed _config_values_main to training_config.py and renamed the ConfigValuesMain class to TrainingConfig. Moved training_config.py to src/primaite/config/training_config.py - Renamed all training config yaml file keys to make creating an instance of TrainingConfig easier. Moved action_type and num_steps over to the training config. - Decoupled the training config and lay down config. - Refactored main.py so that it can be ran from CLI and can take a training config path and a lay down config path. - refactored all outputs so that they save to the session dir. - Added some necessary setup scripts that handle creating app dirs, fronting example config files to the user, fronting demo notebooks to the user, performing clean-up in between installations etc. - Added functions that attempt to retrieve the file path of users example config files that have been fronted by the primaite setup. - Added logging config and a getLogger function in the top-level init. - Refactored all logs entries logged to use a logger using the primaite logging config. - Added basic typer CLI for doing things like setup, viewing logs, viewing primaite version, running a basic session. - Updated test to use new features and config structures. - Began updating docs. More to do here.
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
|
||||
"""The config class."""
|
||||
|
||||
|
||||
class ConfigValuesMain(object):
|
||||
"""Class to hold main config values."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init."""
|
||||
# Generic
|
||||
self.agent_identifier = "" # the agent in use
|
||||
self.num_episodes = 0 # number of episodes to train over
|
||||
self.num_steps = 0 # number of steps in an episode
|
||||
self.time_delay = 0 # delay between steps (ms) - applies to generic agents only
|
||||
self.config_filename_use_case = "" # the filename for the Use Case config file
|
||||
self.session_type = "" # the session type to run (TRAINING or EVALUATION)
|
||||
|
||||
# Environment
|
||||
self.observation_space_high_value = (
|
||||
0 # The high value for the observation space
|
||||
)
|
||||
|
||||
# Reward values
|
||||
# Generic
|
||||
self.all_ok = 0
|
||||
# Node Hardware State
|
||||
self.off_should_be_on = 0
|
||||
self.off_should_be_resetting = 0
|
||||
self.on_should_be_off = 0
|
||||
self.on_should_be_resetting = 0
|
||||
self.resetting_should_be_on = 0
|
||||
self.resetting_should_be_off = 0
|
||||
self.resetting = 0
|
||||
# Node Software or Service State
|
||||
self.good_should_be_patching = 0
|
||||
self.good_should_be_compromised = 0
|
||||
self.good_should_be_overwhelmed = 0
|
||||
self.patching_should_be_good = 0
|
||||
self.patching_should_be_compromised = 0
|
||||
self.patching_should_be_overwhelmed = 0
|
||||
self.patching = 0
|
||||
self.compromised_should_be_good = 0
|
||||
self.compromised_should_be_patching = 0
|
||||
self.compromised_should_be_overwhelmed = 0
|
||||
self.compromised = 0
|
||||
self.overwhelmed_should_be_good = 0
|
||||
self.overwhelmed_should_be_patching = 0
|
||||
self.overwhelmed_should_be_compromised = 0
|
||||
self.overwhelmed = 0
|
||||
# Node File System State
|
||||
self.good_should_be_repairing = 0
|
||||
self.good_should_be_restoring = 0
|
||||
self.good_should_be_corrupt = 0
|
||||
self.good_should_be_destroyed = 0
|
||||
self.repairing_should_be_good = 0
|
||||
self.repairing_should_be_restoring = 0
|
||||
self.repairing_should_be_corrupt = 0
|
||||
self.repairing_should_be_destroyed = (
|
||||
0 # Repairing does not fix destroyed state - you need to restore
|
||||
)
|
||||
self.repairing = 0
|
||||
self.restoring_should_be_good = 0
|
||||
self.restoring_should_be_repairing = 0
|
||||
self.restoring_should_be_corrupt = (
|
||||
0 # Not the optimal method (as repair will fix corruption)
|
||||
)
|
||||
self.restoring_should_be_destroyed = 0
|
||||
self.restoring = 0
|
||||
self.corrupt_should_be_good = 0
|
||||
self.corrupt_should_be_repairing = 0
|
||||
self.corrupt_should_be_restoring = 0
|
||||
self.corrupt_should_be_destroyed = 0
|
||||
self.corrupt = 0
|
||||
self.destroyed_should_be_good = 0
|
||||
self.destroyed_should_be_repairing = 0
|
||||
self.destroyed_should_be_restoring = 0
|
||||
self.destroyed_should_be_corrupt = 0
|
||||
self.destroyed = 0
|
||||
self.scanning = 0
|
||||
# IER status
|
||||
self.red_ier_running = 0
|
||||
self.green_ier_blocked = 0
|
||||
|
||||
# Patching / Reset
|
||||
self.os_patching_duration = 0 # The time taken to patch the OS
|
||||
self.node_reset_duration = 0 # The time taken to reset a node (hardware)
|
||||
self.service_patching_duration = 0 # The time taken to patch a service
|
||||
self.file_system_repairing_limit = 0 # The time take to repair a file
|
||||
self.file_system_restoring_limit = 0 # The time take to restore a file
|
||||
self.file_system_scanning_limit = 0 # The time taken to scan the file system
|
||||
@@ -81,6 +81,7 @@ class ActionType(Enum):
|
||||
|
||||
NODE = 0
|
||||
ACL = 1
|
||||
ANY = 2
|
||||
|
||||
|
||||
class ObservationType(Enum):
|
||||
|
||||
91
src/primaite/common/training_config.py
Normal file
91
src/primaite/common/training_config.py
Normal file
@@ -0,0 +1,91 @@
|
||||
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
|
||||
"""The config class."""
|
||||
from dataclasses import dataclass
|
||||
|
||||
from primaite.common.enums import ActionType
|
||||
|
||||
|
||||
@dataclass()
|
||||
class TrainingConfig:
|
||||
"""Class to hold main config values."""
|
||||
|
||||
# Generic
|
||||
agent_identifier: str # The Red Agent algo/class to be used
|
||||
action_type: ActionType # type of action to use (NODE/ACL/ANY)
|
||||
num_episodes: int # number of episodes to train over
|
||||
num_steps: int # number of steps in an episode
|
||||
time_delay: int # delay between steps (ms) - applies to generic agents only
|
||||
# file
|
||||
session_type: str # the session type to run (TRAINING or EVALUATION)
|
||||
load_agent: str # Determine whether to load an agent from file
|
||||
agent_load_file: str # File path and file name of agent if you're loading one in
|
||||
|
||||
# Environment
|
||||
observation_space_high_value: int # The high value for the observation space
|
||||
|
||||
# Reward values
|
||||
# Generic
|
||||
all_ok: int
|
||||
# Node Hardware State
|
||||
off_should_be_on: int
|
||||
off_should_be_resetting: int
|
||||
on_should_be_off: int
|
||||
on_should_be_resetting: int
|
||||
resetting_should_be_on: int
|
||||
resetting_should_be_off: int
|
||||
resetting: int
|
||||
# Node Software or Service State
|
||||
good_should_be_patching: int
|
||||
good_should_be_compromised: int
|
||||
good_should_be_overwhelmed: int
|
||||
patching_should_be_good: int
|
||||
patching_should_be_compromised: int
|
||||
patching_should_be_overwhelmed: int
|
||||
patching: int
|
||||
compromised_should_be_good: int
|
||||
compromised_should_be_patching: int
|
||||
compromised_should_be_overwhelmed: int
|
||||
compromised: int
|
||||
overwhelmed_should_be_good: int
|
||||
overwhelmed_should_be_patching: int
|
||||
overwhelmed_should_be_compromised: int
|
||||
overwhelmed: int
|
||||
# Node File System State
|
||||
good_should_be_repairing: int
|
||||
good_should_be_restoring: int
|
||||
good_should_be_corrupt: int
|
||||
good_should_be_destroyed: int
|
||||
repairing_should_be_good: int
|
||||
repairing_should_be_restoring: int
|
||||
repairing_should_be_corrupt: int
|
||||
repairing_should_be_destroyed: int # Repairing does not fix destroyed state - you need to restore
|
||||
|
||||
repairing: int
|
||||
restoring_should_be_good: int
|
||||
restoring_should_be_repairing: int
|
||||
restoring_should_be_corrupt: int # Not the optimal method (as repair will fix corruption)
|
||||
|
||||
restoring_should_be_destroyed: int
|
||||
restoring: int
|
||||
corrupt_should_be_good: int
|
||||
corrupt_should_be_repairing: int
|
||||
corrupt_should_be_restoring: int
|
||||
corrupt_should_be_destroyed: int
|
||||
corrupt: int
|
||||
destroyed_should_be_good: int
|
||||
destroyed_should_be_repairing: int
|
||||
destroyed_should_be_restoring: int
|
||||
destroyed_should_be_corrupt: int
|
||||
destroyed: int
|
||||
scanning: int
|
||||
# IER status
|
||||
red_ier_running: int
|
||||
green_ier_blocked: int
|
||||
|
||||
# Patching / Reset
|
||||
os_patching_duration: int # The time taken to patch the OS
|
||||
node_reset_duration: int # The time taken to reset a node (hardware)
|
||||
service_patching_duration: int # The time taken to patch a service
|
||||
file_system_repairing_limit: int # The time take to repair a file
|
||||
file_system_restoring_limit: int # The time take to restore a file
|
||||
file_system_scanning_limit: int # The time taken to scan the file system
|
||||
Reference in New Issue
Block a user