mise a jour
This commit is contained in:
parent
d95742b4c7
commit
edf85fb28b
1 changed files with 26 additions and 7 deletions
|
@ -3,29 +3,48 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import requests
|
import requests
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
|
|
||||||
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
|
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
|
||||||
|
|
||||||
def retrieve_config():
|
def retrieve_config():
|
||||||
my_config = "oops"
|
my_json_config = {"verdict":"oops"}
|
||||||
resp = None
|
|
||||||
my_ip_ = str(subprocess.check_output("echo $MY_IP", shell=True)) #subprocess returning format: b'X.X.X.X\n'
|
my_ip_ = str(subprocess.check_output("echo $MY_IP", shell=True)) #subprocess returning format: b'X.X.X.X\n'
|
||||||
my_ip = my_ip_.replace("b'",'').replace("'",'').replace("\\n",'')
|
my_ip = my_ip_.replace("b'",'').replace("'",'').replace("\\n",'')
|
||||||
print("MY_IP : %s"%(my_ip))
|
print("MY_IP : %s"%(my_ip))
|
||||||
while resp is None:
|
while my_json_config["verdict"] != "yes":
|
||||||
try:
|
try:
|
||||||
resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
|
resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
|
||||||
except:
|
except:
|
||||||
print("Unable to join the bootstrap server")
|
print("Unable to join the bootstrap server")
|
||||||
try:
|
try:
|
||||||
my_config = resp.text
|
my_json_config = resp.json()
|
||||||
except:
|
except:
|
||||||
print("Unable to extract configs from bootstrap server's answer")
|
print("Unable to extract configs from bootstrap server's answer")
|
||||||
print("request url : %s"%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
|
print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
|
||||||
print("received configs : %s"%(my_config))
|
print("received configs : %s"%(my_config))
|
||||||
if my_config != "oops":
|
if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
|
||||||
|
my_config = config_json_to_string(my_json_config)
|
||||||
subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
|
subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
|
||||||
|
else:
|
||||||
|
my_json_config = {"verdict":"oops"}
|
||||||
|
|
||||||
|
def config_json_to_string(json_config):
|
||||||
|
config = ""
|
||||||
|
if "local_ip" in json_config:
|
||||||
|
config += "--local_ip "+json_config["local_ip"]
|
||||||
|
if "local_port" in json_config:
|
||||||
|
config += "--local_port "+json_config["local_port"]
|
||||||
|
if "local_name" in json_config:
|
||||||
|
config += "--local_name "+json_config["local_name"]
|
||||||
|
if "remote_ip" in json_config:
|
||||||
|
config += "--remote_ip "+json_config["remote_ip"]
|
||||||
|
if "remote_port" in json_config:
|
||||||
|
config += "--remote_port "+json_config["remote_port"]
|
||||||
|
if "remote_name" in json_config:
|
||||||
|
config += "--remote_name "+json_config["remote_name"]
|
||||||
|
if "send_period" in json_config:
|
||||||
|
config += "--send_period "+json_config["send_period"]
|
||||||
|
return config
|
||||||
|
|
||||||
retrieve_config()
|
retrieve_config()
|
||||||
|
|
Loading…
Reference in a new issue