diff --git a/gns3server/handlers/api/compute/server_handler.py b/gns3server/handlers/api/compute/server_handler.py index 74d64d10..5a30ac8c 100644 --- a/gns3server/handlers/api/compute/server_handler.py +++ b/gns3server/handlers/api/compute/server_handler.py @@ -24,6 +24,7 @@ from gns3server.schemas.version import VERSION_SCHEMA from gns3server.schemas.server_statistics import SERVER_STATISTICS_SCHEMA from gns3server.compute.port_manager import PortManager from gns3server.utils.cpu_percent import CpuPercent +from gns3server.utils.path import get_default_project_directory, get_mountpoint from gns3server.version import __version__ from aiohttp.web import HTTPConflict @@ -61,7 +62,8 @@ class ServerHandler: load_average_percent = [int(x / psutil.cpu_count() * 100) for x in psutil.getloadavg()] memory_percent = int(psutil.virtual_memory().percent) swap_percent = int(psutil.swap_memory().percent) - disk_usage_percent = int(psutil.disk_usage('/').percent) + project_dir_mountpoint = get_mountpoint(get_default_project_directory()) + disk_usage_percent = int(psutil.disk_usage(project_dir_mountpoint).percent) except psutil.Error as e: raise HTTPConflict(text="Psutil error detected: {}".format(e)) response.json({"memory_total": memory_total, diff --git a/gns3server/utils/path.py b/gns3server/utils/path.py index e3360010..f5e9a057 100644 --- a/gns3server/utils/path.py +++ b/gns3server/utils/path.py @@ -48,7 +48,7 @@ def is_safe_path(file_path: str, basedir: str) -> bool: return Path(basedir).resolve() in test_path.resolve().parents -def check_path_allowed(path): +def check_path_allowed(path: str): """ If the server is non local raise an error if the path is outside project directories @@ -64,3 +64,16 @@ def check_path_allowed(path): if "local" in config and config.getboolean("local") is False: raise aiohttp.web.HTTPForbidden(text="The path is not allowed") + + +def get_mountpoint(path: str): + """ + Find the mount point of a path. + """ + + path = os.path.abspath(path) + while path != os.path.sep: + if os.path.ismount(path): + return path + path = os.path.abspath(os.path.join(path, os.pardir)) + return path