diff --git a/CHANGELOG.md b/CHANGELOG.md index 456d8ea..e7cf1b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,21 @@ # Changelog +## [0.10.1] - 2025-08-25 + +### Fixed + +- Import images problems when there is not info.checked file (#2723, #2726) +- Improves logging (#2727) + ## [0.10.0] - 2025-07-07 ### Added - - OgGit functionality (#2371, #2363, #2363, #2317) +- OgGit functionality (#2371, #2363, #2363, #2317) ### Removed - - Removed unused BitTorrent-related packages and logic + +- Removed unused BitTorrent-related packages and logic ## [0.9.0] - 2025-06-25 diff --git a/api/repo_api.py b/api/repo_api.py index 705a2dc..67c44b0 100644 --- a/api/repo_api.py +++ b/api/repo_api.py @@ -34,6 +34,7 @@ from systemd import journal # Imports para Swagger: from flasgger import Swagger import yaml +import time # -------------------------------------------------------------------------------------------- @@ -436,15 +437,40 @@ def check_remote_backup(image_name, remote_ip, remote_user, remote_path, job_id) def check_aux_files(image_file_path, job_id): """ Cada 10 segundos comprueba si se han creado todos los archivos auxiliares de la imagen que recibe como parámetro, en cuyo caso lo comunicará a ogCore, llamando a un endpoint, y dejará de realizar la comprobación. - También obtiene el valor del archivo ".full.sum" (que corresonde al ID), y se lo comunica a ogCore. + También obtiene el valor del archivo ".full.sum" (que corresponde al ID), y se lo comunica a ogCore. """ journal.send("Running function 'check_aux_files'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - # Creamos un bucle infinito: + # Creamos un bucle que espere durante media hora a que se creen los ficheros auxiliares + start_time = time.time() + timeout = 30 * 60 # 30 minutos while True: + elapsed_time = time.time() - start_time + if elapsed_time > timeout: + journal.send("Timeout reached while waiting for auxiliary files", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + journal.send("{'component':'ogRepo', 'severity':'ERROR', 'operation':'Run function check_aux_files', 'desc':'Timeout reached while waiting for auxiliary files'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") + data = { + 'job_id': job_id, + 'success': False, + 'error': 'Timeout reached while waiting for auxiliary files' + } + journal.send(f"Calling function 'recall_ogcore' (JOB_ID: {job_id}, SUCCESS: False)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + recall_ogcore(data) + break # Si faltan archivos auxiliares por crear, imprimimos un mensaje en la API: if not os.path.exists(f"{image_file_path}.size") or not os.path.exists(f"{image_file_path}.sum") or not os.path.exists(f"{image_file_path}.full.sum") or not os.path.exists(f"{image_file_path}.torrent") or not os.path.exists(f"{image_file_path}.info.checked"): - journal.send("Task in process (auxiliar files remaining)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + missing_files = [] + if not os.path.exists(f"{image_file_path}.size"): + missing_files.append(f"{image_file_path}.size") + if not os.path.exists(f"{image_file_path}.sum"): + missing_files.append(f"{image_file_path}.sum") + if not os.path.exists(f"{image_file_path}.full.sum"): + missing_files.append(f"{image_file_path}.full.sum") + if not os.path.exists(f"{image_file_path}.torrent"): + missing_files.append(f"{image_file_path}.torrent") + if not os.path.exists(f"{image_file_path}.info.checked"): + missing_files.append(f"{image_file_path}.info.checked") + journal.send(f"Task in process (auxiliar files remaining): {', '.join(missing_files)}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") # Si ya se han creado todos los archivos auxiliares, imprimimos un mensaje en la API, respondemos a ogCore y salimos del bucle: else: journal.send("Task finalized (all auxilar files created)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") @@ -693,21 +719,21 @@ def get_repo_status(): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script getRepoStatus.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": json.loads(result.stdout) + "details": json.loads(result.stdout) }), 200 else: journal.send(f"Script 'getRepoStatus.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getRepoStatus.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'getRepoStatus.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getRepoStatus.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -733,21 +759,21 @@ def get_repo_info(): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script getRepoInfo.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": json.loads(result.stdout) + "details": json.loads(result.stdout) }), 200 else: journal.send(f"Script 'getRepoInfo.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getRepoInfo.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'getRepoInfo.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getRepoInfo.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -770,10 +796,10 @@ def get_repo_image_info(imageId): cmd = ['python3', f"{script_path}/getRepoInfo.py", f"{param_dict['name']}.{param_dict['extension']}"] else: journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint get_repo_image_info', 'desc': 'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint get_repo_image_info', 'desc': 'Warning: Image not found, id: {imageId} , name: {param_dict['name']}'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": f"Image not found: id: {imageId} , name: {param_dict['name']}" }), 400 try: @@ -787,21 +813,21 @@ def get_repo_image_info(imageId): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script getRepoInfo.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": json.loads(result.stdout) + "details": json.loads(result.stdout) }), 200 else: journal.send(f"Script 'getRepoInfo.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getRepoInfo.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'getRepoInfo.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getRepoInfo.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -827,14 +853,14 @@ def update_repo_info(): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script updateRepoInfo.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Repository info updated successfully" + "details": "Repository info updated successfully" }), 200 else: journal.send(f"Script 'updateRepoInfo.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script updateRepoInfo.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'updateRepoInfo.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") @@ -842,7 +868,7 @@ def update_repo_info(): return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -869,7 +895,7 @@ def check_image(imageId): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint check_image', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found (inexistent or deleted)" + "details": f"Image {param_dict['name']} not found (inexistent or deleted)" }), 400 try: @@ -884,26 +910,26 @@ def check_image(imageId): if "Error" in result.stdout: return jsonify({ "success": True, - "output": "Image file didn't pass the Integrity Check" + "details": f"Image {param_dict['name']} file didn't pass the Integrity Check" }), 200 else: return jsonify({ "success": True, - "output": "Image file passed the Integrity Check correctly" + "details": f"Image {param_dict['name']} file passed the Integrity Check correctly" }), 200 else: journal.send(f"Script 'checkImage.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script checkImage.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'checkImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script checkImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -935,14 +961,14 @@ def delete_image(imageId): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint delete_image', 'desc':'Warning: Incorrect method (must be permanent or trash)'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Incorrect method (must be 'permanent' or 'trash')" + "details": "Incorrect method (must be 'permanent' or 'trash')" }), 400 else: journal.send("Image not found (inexistent or deleted)", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint delete_image', 'desc':'Warning: Image not found (inexistent or deleted)'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found (inexistent or deleted)" + "details": f"Image {param_dict['name']} not found (inexistent or deleted)" }), 400 try: @@ -956,21 +982,21 @@ def delete_image(imageId): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script deleteImage.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Image deleted successfully" + "details": f"Image {param_dict['name']} deleted successfully" }), 200 else: journal.send(f"Script 'deleteImage.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script deleteImage.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'deleteImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script deleteImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1001,7 +1027,7 @@ def recover_image(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint recover_image', 'desc':'Warning: Image not found (inexistent or recovered previously)'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found (inexistent or recovered previously)" + "details": f"Image {param_dict['name']} not found (inexistent or recovered previously)" }), 400 try: @@ -1015,21 +1041,21 @@ def recover_image(): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script recoverImage.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Image recovered successfully" + "details": f"Image {param_dict['name']} recovered successfully" }), 200 else: journal.send(f"Script 'recoverImage.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script recoverImage.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'recoverImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script recoverImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1055,7 +1081,7 @@ def delete_trash_image(imageId): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint delete_trash_image', 'desc':'Warning: Image not found at trash'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found at trash" + "details": f"Image {param_dict['name']} not found at trash" }), 400 try: @@ -1069,21 +1095,21 @@ def delete_trash_image(imageId): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script deleteTrashImage.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Image deleted successfully" + "details": f"Image {param_dict['name']} deleted successfully" }), 200 else: journal.send(f"Script 'deleteTrashImage.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script deleteTrashImage.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'deleteTrashImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script deleteTrashImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1112,7 +1138,7 @@ def import_image(): journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'400', 'operation':'Run endpoint import_image', 'desc':'Unable to connect to remote server'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Can't connect to remote server" + "details": "Can't connect to remote server" }), 400 # Construimos la ruta de la imagen: @@ -1125,14 +1151,14 @@ def import_image(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint import_image', 'desc':'Warning: Remote image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Remote image not found" + "details": f"Remote image {image_name} not found" }), 400 elif check_image == "Remote image is locked": journal.send("Remote image is locked", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint import_image', 'desc':'Warning: Remote image is locked'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Remote image is locked" + "details": f"Remote image {image_name} is locked" }), 400 # Construimos la llamada al script: @@ -1160,7 +1186,7 @@ def import_image(): # Informamos que la imagen se está importando, y salimos del endpoint: return jsonify({ "success": True, - "output": "Importing image...", + "details": f"Importing image {image_name}...", "job_id": job_id }), 200 else: @@ -1168,21 +1194,21 @@ def import_image(): journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script importImage.py', 'desc':'Result KO (Error: Image import failed)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image import failed" + "details": f"Image {image_name} import failed" }), 500 except subprocess.CalledProcessError as error: journal.send(f"Script 'importImage.py' result KO (Process Exception: {str(error)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script importImage.py', 'desc':'Result KO (Process Exception: {str(error)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "process exception": str(error) + "details": str(error) }), 500 except Exception as error_description: journal.send(f"Script 'importImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script importImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1222,17 +1248,17 @@ def backup_image(): # Si la imagen existe pero está bloqueada, devolvemos un error: if image_lock_exists == True: journal.send("Image is locked", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint backup_image', 'desc':'Warning: Image is locked'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint backup_image', 'desc':'Warning: Image {image_name} is locked'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Image is locked" + "details": f"Image {image_name} is locked" }), 400 else: journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint backup_image', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint backup_image', 'desc':'Warning: Image {image_name} not found'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": f"Image {image_name} not found" }), 400 # Comprobamos la conexión con el equipo remoto, y si falla salimos del endpoint, retornando un error: @@ -1240,10 +1266,10 @@ def backup_image(): if connection_OK == False: journal.send("Can't connect to remote server", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'400', 'operation':'Run endpoint backup_image', 'desc':'Unable to connect to remote host'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'400', 'operation':'Run endpoint backup_image', 'desc':'Unable to connect to remote host {remote_ip}'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Can't connect to remote host" + "details": f"Can't connect to remote host {remote_ip}" }), 400 # Construimos la llamada al script: @@ -1270,29 +1296,29 @@ def backup_image(): # Informamos que la imagen se está exportando, y salimos del endpoint: return jsonify({ "success": True, - "output": "Making image backup...", + "details": f"Making image backup {image_name} in repo {remote_ip}...", "job_id": job_id }), 200 else: - journal.send("Script 'backupImage.py' result KO (Backup image failed)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script backupImage.py', 'desc':'Result KO (Backup image failed)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"Script 'backupImage.py' result KO (Backup image failed)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script backupImage.py', 'desc':'Result KO (Backup image {image_name} failed)'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Backup image failed" + "details": f"Backup image {image_name} failed" }), 500 except subprocess.CalledProcessError as error: journal.send(f"Script 'backupImage.py' result KO (Process Exception: {str(error)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script backupImage.py', 'desc':'Result KO (Process Exception: {str(error_)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script backupImage.py', 'desc':'Result KO (Process Exception: {str(error)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "process exception": str(error) + "details": str(error) }), 500 except Exception as error_description: journal.send(f"Script 'backupImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script backupImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1317,10 +1343,19 @@ def create_torrent_sum(): # Si la imagen no existe, retornamos un error y salimos del endpoint: if image_exists == False: journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint create_torrent_sum', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint create_torrent_sum', 'desc':'Warning: Image {image_name} not found'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Image not found" + "details": f"{repo_path}{image_name} Image not found" + }), 400 + + # Chequeamos que el archivo checked.info existe y si no existe devolvemos error y salimos del endpoint: + if not check_file_exists(f"{repo_path}{image_name}.info.checked"): + journal.send("Checked info file not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint create_torrent_sum', 'desc':'Warning: Checked info file for image: {image_name}.info.checked not found'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + return jsonify({ + "success": False, + "details": f"{repo_path}{image_name}.info.checked file not found" }), 400 # Construimos la ruta de la imagen (relativa a "repo_path"): @@ -1341,7 +1376,7 @@ def create_torrent_sum(): # Evaluamos el resultado de la ejecución, y devolvemos una respuesta: if result.returncode is None: journal.send("Script 'createTorrentSum.py' result OK (ReturnCode: None)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script createTorrentSum.py', 'desc':'Result OK (ReturnCode: None)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script createTorrentSum.py --> {cmd}', 'desc':'Result OK (ReturnCode: None)'}}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") # Si el resultado es correcto, llamamos a la función "check_aux_files" en un hilo paralelo # (para que compruebe si se han creado todos los archivos auxiliares exitosamente): journal.send("Calling function 'check_aux_files'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") @@ -1350,7 +1385,7 @@ def create_torrent_sum(): # Informamos que los archivos auxiliares se están creando, y salimos del endpoint: return jsonify({ "success": True, - "output": "Creating auxiliar files...", + "details": f"Creating auxiliar files for {image_name}...", "job_id": job_id }), 200 else: @@ -1358,14 +1393,14 @@ def create_torrent_sum(): journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script createTorrentSum.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'createTorrentSum.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script createTorrentSum.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1393,24 +1428,24 @@ def send_wakeonlan(): # Evaluamos el resultado de la ejecución, y devolvemos una respuesta: if result.returncode == 0: journal.send("Script 'sendWakeOnLan.py' result OK (ReturnCode: 0)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script sendWakeOnLan.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script sendWakeOnLan.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Wake On Lan packet sended successfully" + "details": "Wake On Lan packet sended successfully" }), 200 else: journal.send(f"Script 'sendWakeOnLan.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendWakeOnLan.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'sendWakeOnLan.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendWakeOnLan.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1446,7 +1481,7 @@ def send_udpcast(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint send_udpcast', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": f"Image {param_dict['name']}.{param_dict['extension']} not found" }), 400 try: @@ -1461,31 +1496,31 @@ def send_udpcast(): # Evaluamos el resultado de la ejecución, y devolvemos una respuesta: if result.returncode is None and process_running == True: journal.send("Script 'sendFileMcast.py' result OK (ReturnCode: None), and process running", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script sendFileMcast.py', 'desc':'Result OK (ReturnCode: None), and process running'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script sendFileMcast.py', 'desc':'Result OK (ReturnCode: None), and process running'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Sending image..." + "details": f"Sending image {param_dict['name']}.{param_dict['extension']}..." }), 200 else: journal.send("Script 'sendFileMcast.py' result KO (Image send failed)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendFileMcast.py', 'desc':'Result KO (Image send failed)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image send failed" + "details": f"Image {param_dict['name']}.{param_dict['extension']} send failed" }), 500 except subprocess.CalledProcessError as error: journal.send(f"Script 'sendFileMcast.py' result KO (Process Exception: {str(error)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendFileMcast.py', 'desc':'Result KO (Process Exception: {str(error)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "process exeption": str(error) + "details": str(error) }), 500 except Exception as error_description: journal.send(f"Script 'sendFileMcast.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendFileMcast.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1519,7 +1554,7 @@ def send_uftp(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint send_uftp', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": f"Image {param_dict['name']}.{param_dict['extension']} not found" }), 400 try: @@ -1534,31 +1569,31 @@ def send_uftp(): # Evaluamos el resultado de la ejecución, y devolvemos una respuesta: if result.returncode is None and process_running == True: journal.send("Script 'sendFileUFTP.py' result OK (ReturnCode: None), and process running", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script sendFileUFTP.py', 'desc':'Result OK (ReturnCode: None), and process running'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script sendFileUFTP.py', 'desc':'Result OK (ReturnCode: None), and process running'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Sending image..." + "details": f"Sending image {param_dict['name']}.{param_dict['extension']}..." }), 200 else: journal.send("Script 'sendFileUFTP.py' result KO (Image send failed)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendFileUFTP.py', 'desc':'Result KO (Image send failed)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image send failed" + "details": f"Image {param_dict['name']}.{param_dict['extension']} send failed" }), 500 except subprocess.CalledProcessError as error: journal.send(f"Script 'sendFileUFTP.py' result KO (Process Exception: {str(error)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendFileUFTP.py', 'desc':'Result KO (Process Exception: {str(error)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "process exeption": str(error) + "details": str(error) }), 500 except Exception as error_description: journal.send(f"Script 'sendFileUFTP.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script sendFileUFTP.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1589,7 +1624,7 @@ def send_p2p(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint send_p2p', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": f"Image {param_dict['name']}.{param_dict['extension']} not found" }), 400 # Comprobamos si el tracker esta ejecutandose, si no lo esta devolevemos un error y salimos del endpoint: @@ -1600,7 +1635,7 @@ def send_p2p(): error_message = "Tracker not running. Check if the tracker is installed and configured correctly." return jsonify({ "success": False, - "error": error_message + "details": error_message }), 500 # Ejecutamos los scripts "runTorrentSeeder.py", que no reciben parámetros. @@ -1620,7 +1655,7 @@ def send_p2p(): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script runTorrentSeeder.py', 'desc':'Results OK (ReturnCodes: None), and processes running'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Tracker and Seeder serving image correctly" + "details": "Tracker and Seeder serving image correctly" }), 200 else: journal.send("Script 'runTorrentSeeder.py' results KO (Seeder not runnig)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") @@ -1629,7 +1664,7 @@ def send_p2p(): return jsonify({ "success": False, - "error": error_message + "details": error_message }), 500 @@ -1654,17 +1689,17 @@ def get_udpcast_info(): # Evaluamos el resultado de la ejecución, y devolvemos la respuesta: if result.returncode == 0: journal.send("Script 'getUDPcastInfo.py' result OK (ReturnCode: 0)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script getUDPcastInfo.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script getUDPcastInfo.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": json.loads(result.stdout) + "details": json.loads(result.stdout) }), 200 else: journal.send(f"Script 'getUDPcastInfo.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getUDPcastInfo.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: if "exit status 1" in str(error_description): @@ -1672,14 +1707,14 @@ def get_udpcast_info(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run script getUDPcastInfo.py', 'desc':'Warning: No UDPcast active transmissions'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "No UDPCast active transmissions" + "details": "No UDPCast active transmissions" }), 400 else: journal.send(f"Script 'getUDPcastInfo.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getUDPcastInfo.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1703,17 +1738,17 @@ def get_uftp_info(): # Evaluamos el resultado de la ejecución, y devolvemos la respuesta: if result.returncode == 0: journal.send("Script 'getUFTPInfo.py' result OK (ReturnCode: 0)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script getUFTPInfo.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script getUFTPInfo.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": json.loads(result.stdout) + "details": json.loads(result.stdout) }), 200 else: journal.send(f"Script 'getUFTPInfo.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getUFTPInfo.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: if "exit status 1" in str(error_description): @@ -1721,14 +1756,14 @@ def get_uftp_info(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run script getUFTPInfo.py', 'desc':'Warning: No UFTP active transmissions'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "No UFTP active transmissions" + "details": "No UFTP active transmissions" }), 400 else: journal.send(f"Script 'getUFTPInfo.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script getUFTPInfo.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1754,7 +1789,7 @@ def stop_udpcast(imageId): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint stop_udpcast', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": "Image not found" }), 400 try: @@ -1765,17 +1800,17 @@ def stop_udpcast(imageId): # Evaluamos el resultado de la ejecución, y devolvemos una respuesta: if result.returncode == 0: journal.send("Script 'stopUDPcast.py' result OK (ReturnCode: 0)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script stopUDPcast.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script stopUDPcast.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Image transmission canceled successfully" + "details": "Image transmission canceled successfully" }), 200 else: journal.send(f"Script 'stopUDPcast.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUDPcast.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: if "exit status 3" in str(error_description): @@ -1783,28 +1818,28 @@ def stop_udpcast(imageId): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run script stopUDPcast.py', 'desc':'Warning: No UDPCast active transmissions for specified image'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "No UDPCast active transmissions for specified image" + "details": "No UDPCast active transmissions for specified image" }), 400 elif "exit status 4" in str(error_description): journal.send("Script 'stopUDPcast.py' result KO (Unexpected error checking UDPcast transmissions)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUDPcast.py', 'desc':'Result KO (Unexpected error checking UDPcast transmissions)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Unexpected error checking UDPcast transmissions" + "details": "Unexpected error checking UDPcast transmissions" }), 500 elif "exit status 5" in str(error_description): journal.send("Script 'stopUDPcast.py' result KO (Unexpected error finalizing UDPcast transmission)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUDPcast.py', 'desc':'Result KO (Unexpected error finalizing UDPcast transmission)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Unexpected error finalizing UDPcast transmission" + "details": "Unexpected error finalizing UDPcast transmission" }), 500 else: journal.send(f"Script 'stopUDPcast.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUDPcast.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1830,7 +1865,7 @@ def stop_uftp(imageId): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint stop_uftp', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": "Image not found" }), 400 try: @@ -1841,17 +1876,17 @@ def stop_uftp(imageId): # Evaluamos el resultado de la ejecución, y devolvemos una respuesta: if result.returncode == 0: journal.send("Script 'stopUFTP.py' result OK (ReturnCode: 0)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script stopUFTP.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script stopUFTP.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Image transmission canceled successfully" + "details": "Image transmission canceled successfully" }), 200 else: journal.send(f"Script 'stopUFTP.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUFTP.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: if "exit status 3" in str(error_description): @@ -1859,28 +1894,28 @@ def stop_uftp(imageId): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run script stopUFTP.py', 'desc':'Warning: No UFTP active transmissions for specified image'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "No UFTP active transmissions for specified image" + "details": "No UFTP active transmissions for specified image" }), 400 elif "exit status 4" in str(error_description): journal.send("Script 'stopUFTP.py' result KO (Unexpected error checking UFTP transmissions)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUFTP.py', 'desc':'Result KO (Unexpected error checking UFTP transmissions)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Unexpected error checking UFTP transmissions" + "details": "Unexpected error checking UFTP transmissions" }), 500 elif "exit status 5" in str(error_description): journal.send("Script 'stopUFTP.py' result KO (Unexpected error finalizing UFTP transmission)", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUFTP.py', 'desc':'Result KO (Unexpected error finalizing UFTP transmission)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Unexpected error finalizing UFTP transmission" + "details": "Unexpected error finalizing UFTP transmission" }), 500 else: journal.send(f"Script 'stopUFTP.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopUFTP.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1903,24 +1938,24 @@ def stop_p2p(): # Evaluamos el resultado de la ejecución, y devolvemos la respuesta: if result.returncode == 0: journal.send("Script 'stopP2P.py' result OK (ReturnCode: 0)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script stopP2P.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send("{'component':'ogRepo', 'severity':'INFO', 'operation':'Run script stopP2P.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "P2P transmissions canceled successfully" + "details": "P2P transmissions canceled successfully" }), 200 else: journal.send(f"Script 'stopP2P.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopP2P.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'stopP2P.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script stopP2P.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -1950,10 +1985,10 @@ def convert_virtual_image(): # Si la imagen virtual no existe, devolvemos un error: if vm_image_exists == False: journal.send("Virtual image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_virtual_image', 'desc':'Warning: Virtual image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_virtual_image', 'desc':'Warning: Virtual image {vm_image_name_full} not found'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "Virtual image not found" + "details": f"Virtual image {vm_image_name_full} not found" }), 400 # Comprobamos si ya existe una imagen "img" con el mismo nombre que la imagen virtual, llamando a la función "check_file_exists": @@ -1962,10 +1997,10 @@ def convert_virtual_image(): # Si existe una imagen con el mismo nombre que la imagen virtual (salvo por la extensión), devolvemos un error: if img_image_exists == True: journal.send("There is an image with the same name as the virtual image", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_virtual_image', 'desc':'Warning: There is an image with the same name as the virtual image'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_virtual_image', 'desc':'Warning: There is an image with the same name as the virtual image --> {vm_image_name_full}'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "There is an image with the same name as the virtual image" + "details": f"There is an image with the same name as the virtual image: {vm_image_name_full}" }), 400 # Comprobamos si hay espacio suficiente en disco para convertir la imagen virtual (4 veces su tamaño): @@ -1977,7 +2012,7 @@ def convert_virtual_image(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_virtual_image', 'desc':'Warning: There is not enough free disk space'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "There is not enough free disk space" + "details": "There is not enough free disk space" }), 400 # Construimos la llamada al script: @@ -2005,7 +2040,7 @@ def convert_virtual_image(): # Informamos que la imagen se está convirtiendo, y salimos del endpoint: return jsonify({ "success": True, - "output": "Converting virtual image...", + "details": "Converting virtual image...", "job_id": job_id }), 200 else: @@ -2013,21 +2048,21 @@ def convert_virtual_image(): journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script convertVMtoIMG.py', 'desc':'Result KO (Error: Virtual image conversion failed)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Virtual image conversion failed" + "details": f"Virtual image conversion failed" }), 500 except subprocess.CalledProcessError as error: journal.send(f"Script 'convertVMtoIMG.py' result KO (Process Exception: {str(error)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script convertVMtoIMG.py', 'desc':'Result KO (Process Exception: {str(error)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "process exception": str(error) + "details": str(error) }), 500 except Exception as error_description: journal.send(f"Script 'convertVMtoIMG.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script convertVMtoIMG.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -2058,10 +2093,10 @@ def convert_image_to_virtual(): cmd = ['python3', f"{script_path}/convertIMGtoVM.py", image_name_full, vm_extension] else: journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_image_to_virtual', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_image_to_virtual', 'desc':'Warning: Image {image_name_full} not found'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": f"Image {image_name_full} not found" }), 400 # Comprobamos si ya existe una imagen virtual exportada con el mismo nombre que la imagen "img" y la extensión especificada, llamando a la función "check_file_exists": @@ -2070,10 +2105,10 @@ def convert_image_to_virtual(): # Si existe una imagen con el mismo nombre que la imagen virtual (salvo por la extensión), devolvemos un error: if vm_image_exists == True: journal.send("There is an exported virtual image with the same name as the image", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_image_to_virtual', 'desc':'Warning: There is an exported virtual image with the same name as the image'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") + journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_image_to_virtual', 'desc':'Warning: There is an exported virtual image with the same name as the image: {image_name_full}'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "There is an exported virtual image with the same name as the image" + "details": f"There is an exported virtual image with the same name as the image: {image_name_full}" }), 400 # Comprobamos si hay espacio suficiente en disco para convertir la imagen "img" a virtual (4 veces su tamaño): @@ -2085,7 +2120,7 @@ def convert_image_to_virtual(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_image_to_virtual', 'desc':'Warning: There is not enough free disk space'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "There is not enough free disk space" + "details": "There is not enough free disk space" }), 400 try: @@ -2110,7 +2145,7 @@ def convert_image_to_virtual(): # Informamos que la imagen se está convirtiendo, y salimos del endpoint: return jsonify({ "success": True, - "output": "Converting image to virtual...", + "details": "Converting image to virtual...", "job_id": job_id }), 200 else: @@ -2118,21 +2153,21 @@ def convert_image_to_virtual(): journal.send("{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script convertIMGtoVM.py', 'desc':'Result KO (Error: Image conversion to virtual failed)'}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image conversion to virtual failed" + "details": f"Image conversion to virtual failed" }), 500 except subprocess.CalledProcessError as error: journal.send(f"Script 'convertIMGtoVM.py' result KO (Process Exception: {str(error)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script convertIMGtoVM.py', 'desc':'Result KO (Process Exception: {str(error)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "process exception": str(error) + "details": str(error) }), 500 except Exception as error_description: journal.send(f"Script 'convertIMGtoVM.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script convertIMGtoVM.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -2164,7 +2199,7 @@ def rename_image(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint rename_image', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": "Image not found" + "details": f"Image {image_original_name} not found" }), 400 # Comprobamos si ya existe una imagen con el mismo nombre que se quiere asignar, llamando a la función "check_file_exists": @@ -2176,7 +2211,7 @@ def rename_image(): journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_image_to_virtual', 'desc':'Warning: There is an image with the name to assign'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": "There is an image with the name to assign" + "details": f"There is an image with the name {image_new_name} to assign" }), 400 try: @@ -2190,21 +2225,21 @@ def rename_image(): journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script renameImage.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": True, - "output": "Image renamed successfully" + "details": f"Image {image_original_name} renamed successfully" }), 200 else: journal.send(f"Script 'renameImage.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script renameImage.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "error": result.stderr + "details": result.stderr }), 500 except Exception as error_description: journal.send(f"Script 'renameImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script renameImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api") return jsonify({ "success": False, - "exception": str(error_description) + "details": str(error_description) }), 500 @@ -2522,13 +2557,12 @@ def git_get_branches(repo): """ repo_path = os.path.join(REPOSITORIES_BASE_PATH, OGGIT_USER, repo + ".git") if not os.path.isdir(repo_path): - journal.send(f"Can't list repositories. Repository storage at {REPOSITORIES_BASE_PATH} not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + journal.send(f"Can't create branch. Repository storage at {REPOSITORIES_BASE_PATH} not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") return jsonify({"error": "Repository not found"}), 404 git_repo = git.Repo(repo_path) git_repo.git.config('--global', '--add', 'safe.directory', repo_path) - branches = [] for branch in git_repo.branches: branches = branches + [branch.name] diff --git a/bin/createTorrentSum.py b/bin/createTorrentSum.py index 070d88b..61dec1d 100644 --- a/bin/createTorrentSum.py +++ b/bin/createTorrentSum.py @@ -184,11 +184,16 @@ def main(): # Obtenemos la ruta completa de la imagen: file_path = build_file_path() - # Si no existe el archivo de imagen, imprimimos un mensaje de error y salimos del script: - if not os.path.exists(file_path): - journal.send("createTorrentSum.py: Image not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - print("Image file doesn't exist") + # Si no existe el archivo de imagen o el .info, imprimimos un mensaje de error y salimos del script: + if not os.path.exists(file_path) or not os.path.exists(f"{file_path}.info.checked"): + if not os.path.exists(file_path): + journal.send(f"createTorrentSum.py: Image file '{file_path}' not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + print(f"Image file '{file_path}' doesn't exist") + if not os.path.exists(f"{file_path}.info.checked"): + journal.send(f"createTorrentSum.py: Info file '{file_path}.info.checked' not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + print(f"Info file '{file_path}.info.checked' doesn't exist") sys.exit(2) + # Si la imagen está bloqueada, imprimimos un mensaje de error y salimos del script: if os.path.exists(f"{file_path}.lock"):