mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +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
|
|
@ -4,11 +4,12 @@ from django.db import transaction
|
|||
from django.db.models import CharField, IntegerField, Model
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from libvirt import virConnect
|
||||
from libvirt import libvirtError, virConnect
|
||||
|
||||
from computes.validators import validate_hostname, validate_login, validate_migration_address
|
||||
from vrtManager.connection import connection_manager
|
||||
from vrtManager.hostdetails import wvmHostDetails
|
||||
from vrtManager.storage import wvmStorages
|
||||
|
||||
|
||||
class Compute(Model):
|
||||
|
|
@ -87,6 +88,20 @@ class Compute(Model):
|
|||
def ram_usage(self):
|
||||
return self.proxy.get_memory_usage()["percent"]
|
||||
|
||||
@cached_property
|
||||
def capacity(self):
|
||||
"""What the host has given its VMs (wvmHostDetails.get_capacity) and
|
||||
its active storage pools, or None when it cannot be read."""
|
||||
if self.status is not True:
|
||||
return None
|
||||
try:
|
||||
given = self.proxy.get_capacity()
|
||||
storages = wvmStorages(self.hostname, self.login, self.password, self.type)
|
||||
given["pools"] = [pool for pool in storages.get_storages_info() if pool["status"]]
|
||||
except libvirtError:
|
||||
return None
|
||||
return given
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue