SimCore
Shared transport-layer plumbing for the ADR-029 Train/IL/CTC RBC simulators
Loading...
Searching...
No Matches
simcore.sim_config Namespace Reference

Functions

 load ()
 require (config, *keys)

Variables

str DEFAULT_CONFIG_PATH = "/app/config.json"

Detailed Description

JSON-file sim configuration loader. Replaces the old per-variable
os.environ reads (RBC_WEST_HOST, RBC_WEST_TRAIN_PORT, RBC_TRAIN_INDEX,
...) that used to be set directly in docker-compose.yml's own
`environment:` block for each service.

One JSON file per sim INSTANCE, not per sim type - train-west and
train-east need different values (trainIndex, which RBC ports) even
though they run the exact same Docker image (safeapi-sim:latest, see
docker-compose.yml's own header on why one image is reused for every
instance) - so the file is supplied at container-start time via a
bind-mounted path (SIM_CONFIG_PATH env var, default
DEFAULT_CONFIG_PATH), not baked into the image. See
sims/config/*.json for the actual per-instance files and
docker-compose.yml's own `volumes:` entries for how each gets mounted.

Schema (fields present depend on sim type - train/il have `trainIndex`,
ctc does not; see each sim's own header for its exact expected keys):
  {
    "siteTag": "WEST",                          # display tag only, log prefix
    "trainIndex": 0,                             # train/il only - 0 or 1
    "rbcWest": {"host": "c-west", "port": 15004},
    "rbcEast": {"host": "c-east", "port": 15014},
    "controlServer": {"bindHost": "0.0.0.0", "port": 9100},
    "simPeriodSeconds": 2.0                       # train only
  }

Function Documentation

◆ load()

load ( )
@return the parsed JSON config dict from SIM_CONFIG_PATH (env,
default DEFAULT_CONFIG_PATH). Raises with the path included on a
missing file or invalid JSON, so a bad config fails loudly and
specifically at startup rather than as a generic KeyError somewhere
inside main() once a sim tries to use a field that was never
there.

Definition at line 34 of file sim_config.py.

◆ require()

require ( config,
* keys )
@return config[keys[0]][keys[1]]... - raises a clear KeyError
(naming the full dotted path and the config file it came from) if
any level is missing, rather than Python's own bare KeyError(key)
for just the last, most confusing level.

Definition at line 55 of file sim_config.py.

Variable Documentation

◆ DEFAULT_CONFIG_PATH

str simcore.sim_config.DEFAULT_CONFIG_PATH = "/app/config.json"

Definition at line 31 of file sim_config.py.