askrobots / dbbasic-object-primitive
Public
Python functions as REST objects, with clustering, load balancing and state replication; no containers or orchestration.
cluster_shell_helper.py · 1.3 KB · 44 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | Helper script to output cluster configuration in shell-friendly format |
| 4 | Usage: eval "$(python cluster_shell_helper.py)" |
| 5 | """ |
| 6 | |
| 7 | import sys |
| 8 | from cluster_config import get_config |
| 9 | |
| 10 | |
| 11 | def main(): |
| 12 | config = get_config() |
| 13 | |
| 14 | # Output bash arrays and variables |
| 15 | master = config.get_master() |
| 16 | workers = config.get_workers() |
| 17 | |
| 18 | if not master: |
| 19 | print("echo 'ERROR: No master station configured'", file=sys.stderr) |
| 20 | sys.exit(1) |
| 21 | |
| 22 | # Master info |
| 23 | print(f"export MASTER_ID='{master['station_id']}'") |
| 24 | print(f"export MASTER_HOST='{master['host']}'") |
| 25 | print(f"export MASTER_PORT='{master['port']}'") |
| 26 | print(f"export MASTER_USER='{master['user']}'") |
| 27 | print(f"export MASTER_SSH='{master['user']}@{master['host']}'") |
| 28 | print() |
| 29 | |
| 30 | # Worker arrays (bash doesn't handle complex data structures well) |
| 31 | # Output each worker's info as separate variables |
| 32 | for i, worker in enumerate(workers, 1): |
| 33 | print(f"export WORKER{i}_ID='{worker['station_id']}'") |
| 34 | print(f"export WORKER{i}_HOST='{worker['host']}'") |
| 35 | print(f"export WORKER{i}_PORT='{worker['port']}'") |
| 36 | print(f"export WORKER{i}_USER='{worker['user']}'") |
| 37 | print(f"export WORKER{i}_SSH='{worker['user']}@{worker['host']}'") |
| 38 | print() |
| 39 | |
| 40 | print(f"export WORKER_COUNT={len(workers)}") |
| 41 | |
| 42 | |
| 43 | if __name__ == "__main__": |
| 44 | main() |