Skip to content

Commit

Permalink
Add low disk space warning when creating a new project.
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Nov 14, 2017
1 parent 135c529 commit 9afe756
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gns3server/compute/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import aiohttp
import psutil
import platform
from .project import Project
from uuid import UUID

import logging
log = logging.getLogger(__name__)


class ProjectManager:

Expand Down Expand Up @@ -70,6 +75,26 @@ def get_project(self, project_id):
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
return self._projects[project_id]

def _check_available_disk_space(self, project):
"""
Sends a warning notification if disk space is getting low.
:param project: project instance
"""

try:
used_disk_space = psutil.disk_usage(project.path).percent
except FileNotFoundError:
log.warning('Could not find "{}" when checking for used disk space'.format(project.path))
return
# send a warning if used disk space is >= 90%
if used_disk_space >= 90:
message = 'Only {}% or less of disk space detected in "{}" on "{}"'.format(used_disk_space,
project.path,
platform.node())
log.warning(message)
project.emit("log.warning", {"message": message})

def create_project(self, name=None, project_id=None, path=None):
"""
Create a project and keep a references to it in project manager.
Expand All @@ -80,6 +105,7 @@ def create_project(self, name=None, project_id=None, path=None):
if project_id is not None and project_id in self._projects:
return self._projects[project_id]
project = Project(name=name, project_id=project_id, path=path)
self._check_available_disk_space(project)
self._projects[project.id] = project
return project

Expand Down

0 comments on commit 9afe756

Please sign in to comment.