|
@@ -0,0 +1,50 @@
|
|
1
|
+#!/usr/bin/python
|
|
2
|
+#coding: utf-8
|
|
3
|
+import os
|
|
4
|
+import subprocess
|
|
5
|
+import requests
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
|
|
9
|
+
|
|
10
|
+def retrieve_config():
|
|
11
|
+ my_json_config = {"verdict":"oops"}
|
|
12
|
+ my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
|
|
13
|
+ print("MY_IP : %s"%(my_ip))
|
|
14
|
+ while my_json_config["verdict"] != "yes":
|
|
15
|
+ try:
|
|
16
|
+ resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
|
|
17
|
+ except:
|
|
18
|
+ print("Unable to join the bootstrap server")
|
|
19
|
+ try:
|
|
20
|
+ my_json_config = resp.json()
|
|
21
|
+ print("Extracted configs [succ] : %s"%(my_json_config))
|
|
22
|
+ except:
|
|
23
|
+ print("Unable to extract configs from bootstrap server's answer")
|
|
24
|
+ print("Extracted configs [fail] : %s"%(my_json_config))
|
|
25
|
+ print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
|
|
26
|
+ if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
|
|
27
|
+ my_config = config_json_to_string(my_json_config)
|
|
28
|
+ subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
|
|
29
|
+ else:
|
|
30
|
+ my_json_config = {"verdict":"oops"}
|
|
31
|
+
|
|
32
|
+def config_json_to_string(json_config):
|
|
33
|
+ config = ""
|
|
34
|
+ if "local_ip" in json_config:
|
|
35
|
+ config += "--local_ip "+json_config["local_ip"]
|
|
36
|
+ if "local_port" in json_config:
|
|
37
|
+ config += "--local_port "+str(json_config["local_port"])
|
|
38
|
+ if "local_name" in json_config:
|
|
39
|
+ config += "--local_name "+json_config["local_name"]
|
|
40
|
+ if "remote_ip" in json_config:
|
|
41
|
+ config += "--remote_ip "+json_config["remote_ip"]
|
|
42
|
+ if "remote_port" in json_config:
|
|
43
|
+ config += "--remote_port "+str(json_config["remote_port"])
|
|
44
|
+ if "remote_name" in json_config:
|
|
45
|
+ config += "--remote_name "+json_config["remote_name"]
|
|
46
|
+ if "send_period" in json_config:
|
|
47
|
+ config += "--send_period "+str(json_config["send_period"])
|
|
48
|
+ return config
|
|
49
|
+
|
|
50
|
+retrieve_config()
|