diff --git a/CHANGELOG b/CHANGELOG index 37b335f..a73453d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +30-08-2022 (AKo): V0.5.3 + - Pyros container has fix hostname (hostname of local machine) + - Adding switch of database if we're not in docker and not on the computer that host the database + - Add fix IP adress for db_pyros and pyros container, updating database.env files to connect to db_pyros + 29-08-2022 (AKo): v0.5.2.1 - Adding colors for recieved and sended commands of an agent. - Renabling print when pulling git repo of guitastro diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f44ea54..38dc21b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -16,7 +16,9 @@ services: - db:/var/lib/mysql/ # create network to allow images to communicate with other images within the same network networks: - - pyros-network + pyros-network: + ipv4_address: 172.19.0.2 + healthcheck: test: ["CMD", 'mysqladmin', 'ping', '-h', 'db', '-u', 'root', '-p$$MYSQL_ROOT_PASSWORD' ] timeout: 10s @@ -61,7 +63,8 @@ services: - db # create network to allow images to communicate with other images within the same network networks: - - pyros-network + pyros-network: + ipv4_address: 172.19.0.3 #ipv4_address: "${IP_PYROS_USER}" restart: always phpmyadmin: @@ -75,7 +78,8 @@ services: PMA_ARBITRARY: 1 restart: always networks: - - pyros-network + pyros-network: + ipv4_address: 172.19.0.4 ports: - 8081:80 @@ -88,3 +92,7 @@ networks: pyros-network: #bridge is the default network driver driver: bridge + ipam: + config: + - subnet: 172.19.0.0/16 + gateway: 172.19.0.1 diff --git a/privatedev/config/default/.database.env b/privatedev/config/default/.database.env index 30c52ae..06f94a2 100644 --- a/privatedev/config/default/.database.env +++ b/privatedev/config/default/.database.env @@ -1 +1,2 @@ -DATABASE_HOST=test \ No newline at end of file +DATABASE_HOST=172.19.0.2 +DATABASE_PORT=3306 \ No newline at end of file diff --git a/privatedev/config/guitalens/.database.env b/privatedev/config/guitalens/.database.env index a8e5116..06f94a2 100644 --- a/privatedev/config/guitalens/.database.env +++ b/privatedev/config/guitalens/.database.env @@ -1 +1,2 @@ -DATABASE_HOST=localhost \ No newline at end of file +DATABASE_HOST=172.19.0.2 +DATABASE_PORT=3306 \ No newline at end of file diff --git a/privatedev/config/tnc/.database.env b/privatedev/config/tnc/.database.env index 4ef3b0c..06f94a2 100644 --- a/privatedev/config/tnc/.database.env +++ b/privatedev/config/tnc/.database.env @@ -1,2 +1,2 @@ -DATABASE_HOST=localhost -DATABASE_PORT=3360 \ No newline at end of file +DATABASE_HOST=172.19.0.2 +DATABASE_PORT=3306 \ No newline at end of file diff --git a/pyros.py b/pyros.py index 73ac05d..2add563 100755 --- a/pyros.py +++ b/pyros.py @@ -810,7 +810,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos # TODO: "python -m pip" au lieu de "pip" pip = "pip" if IS_WINDOWS else "pip3" process = subprocess.Popen( - pip + " install --user --upgrade pykwalify", shell=True) + pip + " install --upgrade pykwalify", shell=True) process.wait() if process.returncode == 0: # self.addExecuted(self.current_command, command) @@ -914,7 +914,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos # Agent "webserver" if agent_name == "webserver": - cmd = "manage.py runserver" + cmd = "manage.py runserver 127.0.0.1:8080" if(WITH_DOCKER): # If we're running pyros within docker, we need to specify a specific adress in order to access the website on our host machine PYROS_WEBSITE_PORT = os.environ.get("PYROS_WEBSITE_PORT") diff --git a/src/core/pyros_django/dashboard/views.py b/src/core/pyros_django/dashboard/views.py index 42cc591..786154a 100644 --- a/src/core/pyros_django/dashboard/views.py +++ b/src/core/pyros_django/dashboard/views.py @@ -218,9 +218,7 @@ def send_agent_cmd(request): reciever = request.POST.get("agent_name") cmd_name = request.POST.get("cmd_name") cmd_args = request.POST.get("cmd_args") - print(request.POST) new_cmd = AgentCmd.send_cmd_from_to("Operator",reciever,cmd_name,cmd_args) - print(new_cmd) if new_cmd != None: messages.add_message(request, messages.INFO, f"Command sended !") else: diff --git a/src/core/pyros_django/pyros/settings.py b/src/core/pyros_django/pyros/settings.py index d79ceb0..ddf8a0c 100644 --- a/src/core/pyros_django/pyros/settings.py +++ b/src/core/pyros_django/pyros/settings.py @@ -110,16 +110,17 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s raise BaseException() os.environ[key] = value except: - with open(env_sample_path, 'r') as env_sample_file: - with open(env_path, "w") as env_file: - for env_sample_line in env_sample_file: - if(env_sample_line.startswith("#") or not env_sample_line.strip()): - continue - key, value = env_sample_line.split("=") - key = key.strip() - value = value.strip() - os.environ[key] = value - env_file.write(env_sample_line) + if env_sample_path != None: + with open(env_sample_path, 'r') as env_sample_file: + with open(env_path, "w") as env_file: + for env_sample_line in env_sample_file: + if(env_sample_line.startswith("#") or not env_sample_line.strip()): + continue + key, value = env_sample_line.split("=") + key = key.strip() + value = value.strip() + os.environ[key] = value + env_file.write(env_sample_line) # BASE_DIR is an absolute path to django folder os.environ["DJANGO_PATH"] = BASE_DIR @@ -150,7 +151,7 @@ if type(WITH_DOCKER) is str and re.match("^y$|^Y$|^yes$|^Yes$",WITH_DOCKER.rstri WITH_DOCKER = True else : WITH_DOCKER = False -HTTP_PORT = "" +HTTP_PORT = "8080" ENV_PATH = os.path.join(BASE_DIR,"../../../docker/variables.env") ENV_SAMPLE_PATH = os.path.join(BASE_DIR,"../../../docker/.env-sample") # default value of mysql port @@ -158,15 +159,8 @@ MYSQL_PORT = "3306" SQL_USER = "" SQL_PWD = "" #PATH_TO_OBSCONF_FILE = os.path.join(BASE_DIR,"../../privatedev/config/default/observatory_default.yml") -HOST = os.environ["HOST_NAME"] -ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'pyros.irap.omp.eu', 'astroguita.hd.free.fr', '0.0.0.0'] -# defining variables when using Docker -if WITH_DOCKER: - ALLOWED_HOSTS.append('0.0.0.0') - HTTP_PORT = ":8000" -if HOST: - ALLOWED_HOSTS.append(HOST) try: + HOST = os.environ["HOST_NAME"] MYSQL_PORT = os.environ['MYSQL_TCP_PORT'].strip() SQL_USER = os.environ["MYSQL_PYROS_LOGIN"].strip() SQL_PWD = os.environ["MYSQL_PYROS_PWD"].strip() @@ -174,6 +168,14 @@ try: except: set_environment_variables_if_not_configured(ENV_PATH,ENV_SAMPLE_PATH) +ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'pyros.irap.omp.eu', 'astroguita.hd.free.fr', '0.0.0.0'] +# defining variables when using Docker +if WITH_DOCKER: + ALLOWED_HOSTS.append('0.0.0.0') + HTTP_PORT = ":8000" +HOST = os.environ["HOST_NAME"] +if HOST: + ALLOWED_HOSTS.append(HOST) # TODO : Change ALLOWED_HOSTS depending if you are using docker with windows (the domain is "localhost") or docker with another OS (the domain is "0.0.0.0"). If you are running PyROS without Docker, the domain is "localhost". DEFAULT_DOMAIN = f'{ALLOWED_HOSTS[0]}{HTTP_PORT}' @@ -288,6 +290,13 @@ so Django highly recommends activating a strict mode for MySQL to prevent data l (either STRICT_TRANS_TABLES or STRICT_ALL_TABLES) ''' mysql_options = { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" } +from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig +import socket +obsconfig = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"]) +database_computer = obsconfig.get_database_for_unit(obsconfig.unit_name)["computer"] +database_file = obsconfig.get_database_environment(obsconfig.unit_name) +current_computer = socket.gethostname() +set_environment_variables_if_not_configured(database_file, None) # DEFAULT (NORMAL) RUN MODE, use pyros (normal) database if MYSQL: @@ -317,6 +326,9 @@ if MYSQL: DATABASES['default']['PORT'] = '3306' else: DATABASES['default']['HOST'] = "localhost" + if current_computer != database_computer: + DATABASES['default']['HOST'] = os.environ["DATABASE_HOST"] + DATABASES['default']['PORT'] = os.environ["DATABASE_PORT"] else: DATABASES = { 'default': { -- libgit2 0.21.2