1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

feat(instances): the Guest Info tab shows how full the guest's file systems are

A disk filling up inside a guest was seen only from the guest. The Guest Info
tab now lists, from the guest agent, each mounted file system with its type
and used / total size, a bar turning amber from 85 %. File systems the agent
gives no size of (pseudo ones, Windows' System Reserved) are left out; an
agent without the command still shows the rest of the tab.
This commit is contained in:
catborise 2026-11-20 09:13:59 +03:00
parent 981ff7b294
commit 46931bdbdb
10 changed files with 544 additions and 401 deletions

View file

@ -784,8 +784,21 @@ class wvmInstance(wvmConnect):
for command in ("guest-get-timezone", "guest-get-host-name"):
with contextlib.suppress(libvirtError):
info.update(agent_command(self.instance, command))
with contextlib.suppress(libvirtError):
info["filesystems"] = self.guest_filesystems()
return info
def guest_filesystems(self):
"""The guest's mounted file systems the agent gives both sizes of (not
pseudo ones), by mount point: [{"mountpoint", "type", "used", "total"}], bytes."""
filesystems = []
for fs in agent_command(self.instance, "guest-get-fsinfo") or []:
used, total = (fs or {}).get("used-bytes"), (fs or {}).get("total-bytes")
if isinstance(used, int) and isinstance(total, int) and total > 0:
filesystems.append({"mountpoint": str(fs.get("mountpoint", "")), "type": str(fs.get("type", "")),
"used": used, "total": total})
return sorted(filesystems, key=lambda fs: fs["mountpoint"])
def start(self, flags=0):
self.instance.createWithFlags(flags)

View file

@ -68,13 +68,14 @@ class InterfaceAddressesTestCase(unittest.TestCase):
class OsInfoTestCase(unittest.TestCase):
def test_the_os_details_are_asked_with_a_timeout(self):
answers = {"guest-get-osinfo": {"kernel-release": "6.12"}, "guest-get-timezone": {"zone": "UTC"},
"guest-get-host-name": {"host-name": "web"}}
"guest-get-host-name": {"host-name": "web"}, "guest-get-fsinfo": []}
inst = wvmInstance.__new__(wvmInstance)
inst.instance = MagicMock()
with patch.object(module, "qemuAgentCommand",
side_effect=lambda dom, cmd, timeout, flags: json.dumps(
{"return": answers[json.loads(cmd)["execute"]]})) as agent:
self.assertEqual(inst.osinfo(), {"kernel-release": "6.12", "zone": "UTC", "host-name": "web"})
self.assertEqual(inst.osinfo(), {"kernel-release": "6.12", "zone": "UTC", "host-name": "web",
"filesystems": []})
self.assertEqual({c.args[2] for c in agent.call_args_list}, {10})
def test_a_command_the_agent_lacks_leaves_out_only_its_details(self):
@ -82,14 +83,30 @@ class OsInfoTestCase(unittest.TestCase):
inst.instance = MagicMock()
def agent(dom, cmd, timeout, flags):
if json.loads(cmd)["execute"] == "guest-get-timezone":
raise libvirtError("The command guest-get-timezone has not been found")
if json.loads(cmd)["execute"] in ("guest-get-timezone", "guest-get-fsinfo"):
raise libvirtError("The command has not been found")
return json.dumps({"return": {"guest-get-osinfo": {"id": "alma"}, "guest-get-host-name": {"host-name": "web"}}[
json.loads(cmd)["execute"]]})
with patch.object(module, "qemuAgentCommand", side_effect=agent):
self.assertEqual(inst.osinfo(), {"id": "alma", "host-name": "web"})
def test_the_file_systems_with_a_size_by_mount_point(self):
fsinfo = [
{"name": "vda2", "mountpoint": "/boot", "type": "xfs", "used-bytes": 2**28, "total-bytes": 2**30},
{"name": "vda1", "mountpoint": "/var/lib/containers/overlay", "type": "overlay"}, # no size: left out
{"name": "vdb1", "mountpoint": "/data", "type": "xfs", "total-bytes": 2**30}, # no used size: left out
None,
{"name": "vda1", "mountpoint": "/", "type": "xfs", "used-bytes": 3 * 2**30, "total-bytes": 10 * 2**30},
]
inst = wvmInstance.__new__(wvmInstance)
inst.instance = MagicMock()
with patch.object(module, "qemuAgentCommand", return_value=json.dumps({"return": fsinfo})):
self.assertEqual(inst.guest_filesystems(), [
{"mountpoint": "/", "type": "xfs", "used": 3 * 2**30, "total": 10 * 2**30},
{"mountpoint": "/boot", "type": "xfs", "used": 2**28, "total": 2**30},
])
if __name__ == "__main__":
unittest.main()