1
from __future__ import division
5
from twisted.internet.defer import succeed
7
from landscape.lib.disk import get_mount_info, get_filesystem_for_path
10
def format_megabytes(megabytes):
11
if megabytes >= 1024*1024:
12
return "%.2fTB" % (megabytes/(1024*1024))
13
elif megabytes >= 1024:
14
return "%.2fGB" % (megabytes/1024)
16
return "%dMB" % (megabytes)
20
total = info["total-space"]
21
used = total - info["free-space"]
22
return "%0.1f%% of %s" % ((used / total) * 100, format_megabytes(total))
26
def __init__(self, mounts_file="/proc/mounts", statvfs=os.statvfs):
27
self._mounts_file = mounts_file
28
self._statvfs = statvfs
30
def register(self, sysinfo):
31
self._sysinfo = sysinfo
34
main_info = get_filesystem_for_path("/home", self._mounts_file,
36
total = main_info["total-space"]
37
self._sysinfo.add_header("Usage of " + main_info["mount-point"],
42
infos = list(get_mount_info(self._mounts_file, self._statvfs))
43
infos.sort(key=lambda i: len(i["mount-point"]))
45
total = info["total-space"]
47
if info["mount-point"] in seen_mounts:
49
seen_mounts.add(info["mount-point"])
50
if info["device"] in seen_devices:
52
seen_devices.add(info["device"])
53
if info["filesystem"] in ("udf", "iso9660"):
56
# Some "virtual" filesystems have 0 total space. ignore them.
59
used = ((total - info["free-space"]) / total) * 100
61
self._sysinfo.add_note("%s is using %s"
62
% (info["mount-point"], usage(info)))