Python functions as REST objects, with clustering, load balancing and state replication; no containers or orchestration.

0 downloads

dbbasic-object-primitive/cluster_shell_helper.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-primitive.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-primitive.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-primitive.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Dan Q Consolidate duplicate QUICKSTARTs on the top-level file 503f830 7 months ago History
cluster_shell_helper.py · 1.3 KB · 44 lines
1#!/usr/bin/env python3
2"""
3Helper script to output cluster configuration in shell-friendly format
4Usage: eval "$(python cluster_shell_helper.py)"
5"""
6
7import sys
8from cluster_config import get_config
9
10
11def 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
43if __name__ == "__main__":
44 main()