From 0e5a13ecade1734d1b85c928fe2de623f6741a83 Mon Sep 17 00:00:00 2001 From: chabisik Date: Fri, 1 Jan 2021 21:46:40 +0100 Subject: [PATCH] mise a jour --- .../bootserver/bootstrap_client.py | 16 +++--- .../bootserver/bootstrap_server.py | 19 ++++--- .../device/bootstrap_client.py | 16 +++--- .../gateway/bootstrap_client.py | 16 +++--- .../forContainerNet/goteway/Dockerfile | 29 ----------- .../goteway/bootstrap_client.py | 50 ------------------- 6 files changed, 35 insertions(+), 111 deletions(-) delete mode 100644 Dockerfiles/forContainerNet/goteway/Dockerfile delete mode 100755 Dockerfiles/forContainerNet/goteway/bootstrap_client.py diff --git a/Dockerfiles/forContainerNet/bootserver/bootstrap_client.py b/Dockerfiles/forContainerNet/bootserver/bootstrap_client.py index 25637b8..d2f06a7 100755 --- a/Dockerfiles/forContainerNet/bootserver/bootstrap_client.py +++ b/Dockerfiles/forContainerNet/bootserver/bootstrap_client.py @@ -32,19 +32,19 @@ def retrieve_config(): def config_json_to_string(json_config): config = "" if "local_ip" in json_config: - config += "--local_ip "+json_config["local_ip"] + config += "--local_ip "+json_config["local_ip"]+" " if "local_port" in json_config: - config += "--local_port "+str(json_config["local_port"]) + config += "--local_port "+str(json_config["local_port"])+" " if "local_name" in json_config: - config += "--local_name "+json_config["local_name"] + config += "--local_name "+json_config["local_name"]+" " if "remote_ip" in json_config: - config += "--remote_ip "+json_config["remote_ip"] + config += "--remote_ip "+json_config["remote_ip"]+" " if "remote_port" in json_config: - config += "--remote_port "+str(json_config["remote_port"]) + config += "--remote_port "+str(json_config["remote_port"])+" " if "remote_name" in json_config: - config += "--remote_name "+json_config["remote_name"] + config += "--remote_name "+json_config["remote_name"]+" " if "send_period" in json_config: - config += "--send_period "+str(json_config["send_period"]) - return config + config += "--send_period "+str(json_config["send_period"])+" " + return config.strip() retrieve_config() diff --git a/Dockerfiles/forContainerNet/bootserver/bootstrap_server.py b/Dockerfiles/forContainerNet/bootserver/bootstrap_server.py index 6aaefd1..afb0a6c 100755 --- a/Dockerfiles/forContainerNet/bootserver/bootstrap_server.py +++ b/Dockerfiles/forContainerNet/bootserver/bootstrap_server.py @@ -10,7 +10,7 @@ app = Flask(__name__) SVR_IP = '10.0.0.1' #name = srv GWI1_IP = '10.2.2.1' #name = gwi1 -GWI2_IP = '10.2.2.2' #name = gwi2 +GWI2_IP = '10.2.2.2' #name = gwi2 (dc) GWF1_IP = '10.0.1.100' #name = gwf1 DEV1_GWF1_IP = '10.0.1.1' #name = dev1gwf1 @@ -49,13 +49,6 @@ def configurations_giver(my_ip): configs["remote_port"] = 8080 configs["remote_name"] = "srv" configs["verdict"] = "yes" - elif my_ip==GWI2_IP: - configs["local_port"] = 8181 - configs["local_name"] = "gwi2" - configs["remote_ip"] = SVR_IP - configs["remote_port"] = 8080 - configs["remote_name"] = "srv" - configs["verdict"] = "yes" elif my_ip==GWF1_IP: configs["local_port"] = 8282 configs["local_name"] = "gwf1" @@ -151,6 +144,16 @@ def configurations_giver(my_ip): configs["verdict"] = "yes" return jsonify(configs) +@app.route("/getmyconfig/") +def configurations_giver_to_dc(my_ip): + configs = {"local_ip":"127.0.0.1", "verdict":"yes"} + configs["local_port"] = 8181 + configs["local_name"] = "gwi2" + configs["remote_ip"] = SVR_IP + configs["remote_port"] = 8080 + configs["remote_name"] = "srv" + return jsonify(configs) + if __name__=='__main__': app.run(debug=False, host='0.0.0.0', port=5555) diff --git a/Dockerfiles/forContainerNet/device/bootstrap_client.py b/Dockerfiles/forContainerNet/device/bootstrap_client.py index 25637b8..d2f06a7 100755 --- a/Dockerfiles/forContainerNet/device/bootstrap_client.py +++ b/Dockerfiles/forContainerNet/device/bootstrap_client.py @@ -32,19 +32,19 @@ def retrieve_config(): def config_json_to_string(json_config): config = "" if "local_ip" in json_config: - config += "--local_ip "+json_config["local_ip"] + config += "--local_ip "+json_config["local_ip"]+" " if "local_port" in json_config: - config += "--local_port "+str(json_config["local_port"]) + config += "--local_port "+str(json_config["local_port"])+" " if "local_name" in json_config: - config += "--local_name "+json_config["local_name"] + config += "--local_name "+json_config["local_name"]+" " if "remote_ip" in json_config: - config += "--remote_ip "+json_config["remote_ip"] + config += "--remote_ip "+json_config["remote_ip"]+" " if "remote_port" in json_config: - config += "--remote_port "+str(json_config["remote_port"]) + config += "--remote_port "+str(json_config["remote_port"])+" " if "remote_name" in json_config: - config += "--remote_name "+json_config["remote_name"] + config += "--remote_name "+json_config["remote_name"]+" " if "send_period" in json_config: - config += "--send_period "+str(json_config["send_period"]) - return config + config += "--send_period "+str(json_config["send_period"])+" " + return config.strip() retrieve_config() diff --git a/Dockerfiles/forContainerNet/gateway/bootstrap_client.py b/Dockerfiles/forContainerNet/gateway/bootstrap_client.py index 25637b8..d2f06a7 100755 --- a/Dockerfiles/forContainerNet/gateway/bootstrap_client.py +++ b/Dockerfiles/forContainerNet/gateway/bootstrap_client.py @@ -32,19 +32,19 @@ def retrieve_config(): def config_json_to_string(json_config): config = "" if "local_ip" in json_config: - config += "--local_ip "+json_config["local_ip"] + config += "--local_ip "+json_config["local_ip"]+" " if "local_port" in json_config: - config += "--local_port "+str(json_config["local_port"]) + config += "--local_port "+str(json_config["local_port"])+" " if "local_name" in json_config: - config += "--local_name "+json_config["local_name"] + config += "--local_name "+json_config["local_name"]+" " if "remote_ip" in json_config: - config += "--remote_ip "+json_config["remote_ip"] + config += "--remote_ip "+json_config["remote_ip"]+" " if "remote_port" in json_config: - config += "--remote_port "+str(json_config["remote_port"]) + config += "--remote_port "+str(json_config["remote_port"])+" " if "remote_name" in json_config: - config += "--remote_name "+json_config["remote_name"] + config += "--remote_name "+json_config["remote_name"]+" " if "send_period" in json_config: - config += "--send_period "+str(json_config["send_period"]) - return config + config += "--send_period "+str(json_config["send_period"])+" " + return config.strip() retrieve_config() diff --git a/Dockerfiles/forContainerNet/goteway/Dockerfile b/Dockerfiles/forContainerNet/goteway/Dockerfile deleted file mode 100644 index b4ad0c3..0000000 --- a/Dockerfiles/forContainerNet/goteway/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -# 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 - diff --git a/Dockerfiles/forContainerNet/goteway/bootstrap_client.py b/Dockerfiles/forContainerNet/goteway/bootstrap_client.py deleted file mode 100755 index 25637b8..0000000 --- a/Dockerfiles/forContainerNet/goteway/bootstrap_client.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/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()