mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 08:44:52 +02:00
Return disk usage for partition that contains the default project directory. Fixes #1947
This commit is contained in:
parent
041d2bd2d6
commit
a55c9a5c6a
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user