mise a jour

This commit is contained in:
Abdel Kader Chabi Sika Boni 2021-01-01 19:54:47 +01:00
parent 81cad4643c
commit f3da18acd1
4 changed files with 81 additions and 2 deletions

View file

@ -0,0 +1,29 @@
# Choosing the image to use
FROM node:buster
ENV MY_IP=10.2.2.2
# Installing required libraries
RUN apt-get update && \
apt-get install -y net-tools iputils-ping python-pip && \
pip install flask && \
pip install requests && \
mkdir mydir && \
cd mydir && \
npm install express && \
npm install yargs && \
npm install systeminformation && \
npm install request && \
wget http://homepages.laas.fr/smedjiah/tmp/gateway.js
COPY bootstrap_client.py /mydir
SHELL ["/bin/bash", "-c"]
RUN echo "nohup python /mydir/bootstrap_client.py &" > start.sh && \
echo "/bin/bash" >> start.sh && \
chmod 777 start.sh
# Mandatory entrypoint in containernet
ENTRYPOINT ./start.sh

View file

@ -0,0 +1,50 @@
#!/usr/bin/python
#coding: utf-8
import os
import subprocess
import requests
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
def retrieve_config():
my_json_config = {"verdict":"oops"}
my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
print("MY_IP : %s"%(my_ip))
while my_json_config["verdict"] != "yes":
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_json_config = resp.json()
print("Extracted configs [succ] : %s"%(my_json_config))
except:
print("Unable to extract configs from bootstrap server's answer")
print("Extracted configs [fail] : %s"%(my_json_config))
print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
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)
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 "+str(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 "+str(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 "+str(json_config["send_period"])
return config
retrieve_config()

View file

@ -114,7 +114,7 @@ def create_topology():
btrap = net.addDocker('btrap', ip=BOOTSTRAP_SERVER, dimage="config:topo") btrap = net.addDocker('btrap', ip=BOOTSTRAP_SERVER, dimage="config:topo")
info('*** Adding topology server\n') info('*** Adding topology server\n')
srv = net.addDocker('srv', ip=SVR_IP, dimage="server:topo", environment={'MY_IP':SVR_IP}) srv = net.addDocker('srv', ip=SVR_IP, dimage="server:topo", environment={'MY_IP':SVR_IP})# ports=[8080], publish_all_ports=True,
info('*** Adding topology intermediary gateway\n') info('*** Adding topology intermediary gateway\n')
#gwi1 = net.addDocker('gwi1', ip=GWI1_IP, dimage="gateway:topo", environment={'MY_IP':GWI1_IP}) #gwi1 = net.addDocker('gwi1', ip=GWI1_IP, dimage="gateway:topo", environment={'MY_IP':GWI1_IP})