icds/Dockerfiles/forContainerNet/server/bootstrap_client.py
2021-01-01 13:26:19 +01:00

31 lines
1 KiB
Python
Executable file

#!/usr/bin/python3
#coding: utf-8
import os
import subprocess
import requests
from time import sleep
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
def retrieve_config():
my_config = "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 = my_ip_.replace("b'",'').replace("'",'').replace("\\n",'')
print("MY_IP : %s"%(my_ip))
while resp is None:
try:
resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
except:
print("Unable to join the bootstrap server")
try:
my_config = resp.text
except:
print("Unable to extract configs from bootstrap server's answer")
print("request url : %s"%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
print("received configs : %s"%(my_config))
if my_config != "oops":
subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
retrieve_config()