mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
The Stats tab stacked one large card per chart, so a VM with a few devices made a long page, and its "Real Time" and "Logs" sub-tabs were shown to every user although only a superuser may read the logs. The owner chose the layout from rendered options: a state line, CPU and memory side by side, one chart per NIC and disk below, each with its latest reading next to its title, and a small Graphs/Logs switch for superusers. Codex reviewed the tab; this is fixed: - Memory is shown in MiB (it was labelled MB), and its axis grows to the RSS when the RSS passes the balloon size instead of clipping it. - The CPU reading says it is of the host's CPUs. - A NIC is titled by its MAC, not an invented "eth0", and its readings are matched to its chart by the MAC: they were matched by position, so removing a NIC while the page was open moved the next one's readings into its chart. - A VM that is not running says nothing is measured. - The logs load whenever the Logs view is shown, by keyboard too; an empty answer says "None" and a failed one says so, instead of an empty table. The tab shows the latest 50 rows, with a link to all of the VM's rows on the Logs page. - The VM's header shows memory in MiB; it said MB.
28 lines
1,005 B
Python
28 lines
1,005 B
Python
from django.http import JsonResponse
|
|
from django.shortcuts import get_object_or_404
|
|
from django.utils.translation import gettext as _
|
|
|
|
from admin.decorators import superuser_only
|
|
from instances.models import Instance
|
|
from logs.models import Logs
|
|
|
|
# the rows of a VM on its Stats tab; the Logs page has them all
|
|
VM_LOG_ROWS = 50
|
|
|
|
|
|
@superuser_only
|
|
def vm_logs(request, pk):
|
|
"""The rows of a VM, found by its UUID: a rename keeps them, and a VM on two computes is one VM."""
|
|
vm = get_object_or_404(Instance, pk=pk)
|
|
results = {None: _("Unknown"), True: _("Done"), False: _("Failed")}
|
|
logs = []
|
|
for log in Logs.objects.filter(instance_uuid=vm.uuid).order_by("-date", "-id")[:VM_LOG_ROWS]:
|
|
logs.append({
|
|
"user": log.user,
|
|
"host": log.host,
|
|
"instance": log.instance,
|
|
"message": log.message,
|
|
"result": results[log.success],
|
|
"date": log.date.strftime("%x %X"),
|
|
})
|
|
return JsonResponse(logs, safe=False)
|