mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
refactor(computes): the Computes page reads capacity through vrtManager
The capacity read lived in its own module with raw libvirt calls and a thread pool with a deadline, beside helpers that already read the same things. It now uses them: - wvmHostDetails.get_capacity() sums the vCPUs and memory of all and of the running VMs from get_host_instances(), against the host's info. - get_storages_info() also gives each pool's free space. - Compute.capacity joins the two, like cpu_count and ram_size, and is None when the host is down or the read fails. The page reads the hosts one after another, as it already connected to each of them; a host that cannot be reached is given up after the connect timeout. computes/capacity.py and its thread handling are gone. The page looks and sorts as before.
This commit is contained in:
parent
1436ed13af
commit
d9f9ebab58
8 changed files with 114 additions and 185 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import time
|
||||
|
||||
from libvirt import VIR_NODE_CPU_STATS_ALL_CPUS
|
||||
from libvirt import VIR_DOMAIN_SHUTOFF, VIR_NODE_CPU_STATS_ALL_CPUS
|
||||
|
||||
from vrtManager.connection import wvmConnect
|
||||
from vrtManager.util import get_xml_path
|
||||
|
|
@ -83,3 +83,18 @@ class wvmHostDetails(wvmConnect):
|
|||
) # cpu version
|
||||
info.append(self.wvm.getURI()) # uri
|
||||
return info
|
||||
|
||||
def get_capacity(self):
|
||||
"""
|
||||
What the host has given its VMs: vCPUs and memory (bytes) of all VMs
|
||||
and of the running ones, against its CPUs and memory. A shut-off VM
|
||||
takes its share again when it starts.
|
||||
"""
|
||||
vcpus = {"all": 0, "running": 0}
|
||||
assigned = {"all": 0, "running": 0}
|
||||
for vm in self.get_host_instances(raw_mem_size=True).values():
|
||||
for share in ("all",) if vm["status"] == VIR_DOMAIN_SHUTOFF else ("all", "running"):
|
||||
vcpus[share] += int(vm["vcpu"])
|
||||
assigned[share] += vm["memory"]
|
||||
return {"cpus": self.host_info[2], "memory": self.host_info[1] * 1048576,
|
||||
"vcpus": vcpus, "assigned": assigned}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue