2024-10-17 12:22:30 +01:00
|
|
|
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
|
|
|
|
from abc import abstractmethod
|
|
|
|
|
from typing import ClassVar, Dict
|
|
|
|
|
|
|
|
|
|
from primaite.game.agent.actions.manager import AbstractAction
|
|
|
|
|
from primaite.interface.request import RequestFormat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeAbstractAction(AbstractAction):
|
|
|
|
|
"""
|
|
|
|
|
Abstract base class for node actions.
|
|
|
|
|
|
|
|
|
|
Any action which applies to a node and uses node_name as its only parameter can inherit from this base class.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(AbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Base Configuration schema for Node actions."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
node_name: str
|
|
|
|
|
|
|
|
|
|
verb: ClassVar[str]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def form_request(cls, config: ConfigSchema) -> RequestFormat:
|
|
|
|
|
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
|
|
|
|
|
return ["network", "node", config.node_name, cls.verb]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeOSScanAction(NodeAbstractAction, identifier="node_os_scan"):
|
|
|
|
|
"""Action which scans a node's OS."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeOSScanAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "scan"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeShutdownAction(NodeAbstractAction, identifier="node_shutdown"):
|
|
|
|
|
"""Action which shuts down a node."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeShutdownAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "shutdown"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeStartupAction(NodeAbstractAction, identifier="node_startup"):
|
|
|
|
|
"""Action which starts up a node."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeStartupAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "startup"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeResetAction(NodeAbstractAction, identifier="node_reset"):
|
|
|
|
|
"""Action which resets a node."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeResetAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "reset"
|