mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(computes): the Computes page tells what a host lacks for another host's VMs
A VM migrated to a host without its network, network filter or secret was refused only when the migration was asked for. The box above the hosts now names, for each pair of hosts it has read, what the VMs of one use (their running definition and the one for the next start) that the other lacks: an active network, a network filter or one of other rules, a secret by UUID or usage; the migration check refuses moving those VMs there. A host in maintenance is no destination. What a host's VMs need is read on its own thread, apart from the pools and snapshots, and used again for 5 minutes, so a host of many VMs is compared too. The rules of two hosts' filters are compared as the migration check does (filter_rules, shared).
This commit is contained in:
parent
b36f674542
commit
640511cfd4
11 changed files with 542 additions and 321 deletions
|
|
@ -6,6 +6,7 @@ from libvirt import (
|
|||
libvirtError,
|
||||
VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT,
|
||||
VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT,
|
||||
VIR_CONNECT_LIST_NETWORKS_ACTIVE,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE,
|
||||
VIR_ERR_NO_DOMAIN,
|
||||
VIR_DOMAIN_BLOCKED,
|
||||
|
|
@ -20,6 +21,8 @@ from libvirt import (
|
|||
from lxml import etree
|
||||
|
||||
from vrtManager.connection import wvmConnect
|
||||
from vrtManager.nwfilters import filter_rules
|
||||
from vrtManager.virtsecrets import REF_USAGE_TYPES
|
||||
from vrtManager.util import get_xml_path
|
||||
|
||||
|
||||
|
|
@ -80,6 +83,42 @@ class wvmHostDetails(wvmConnect):
|
|||
snapshots.append({"vm": domain.name(), "count": count})
|
||||
return {"pools": pools, "snapshots": snapshots}
|
||||
|
||||
def migration_needs(self):
|
||||
"""What the host's VMs need of a host they migrate to, as the migration check reads
|
||||
it, and what this host has: {"uses": {"networks", "filters", "secrets", "usages"},
|
||||
"has": {"networks" (active), "filters" {name: rules}, "secrets", "usages"}}. A VM's
|
||||
running definition and the one for its next start count; its filters include those
|
||||
these reference here; a secret is named by UUID ("secrets") or by usage type and
|
||||
usage ("usages", [type, usage]). A VM or filter gone meanwhile is passed over."""
|
||||
networks, filters_used, secrets, usages = set(), set(), set(), set()
|
||||
for _name, trees in self.domain_trees():
|
||||
for tree in trees:
|
||||
networks.update(tree.xpath("devices/interface[@type='network']/source/@network"))
|
||||
filters_used.update(tree.xpath("devices/interface/filterref/@filter"))
|
||||
for ref in tree.xpath("devices//secret"):
|
||||
if ref.get("uuid"):
|
||||
secrets.add(ref.get("uuid").lower())
|
||||
elif ref.get("usage"):
|
||||
usages.add((REF_USAGE_TYPES.get(ref.get("type")), ref.get("usage")))
|
||||
secrets.update(uuid.lower() for uuid in tree.xpath("devices/tpm/backend/encryption/@secret"))
|
||||
filters = {}
|
||||
for nwfilter in self.wvm.listAllNWFilters(0):
|
||||
with suppress(libvirtError): # undefined meanwhile
|
||||
filters[nwfilter.name()] = filter_rules(nwfilter)
|
||||
todo = list(filters_used)
|
||||
while todo: # and those they reference
|
||||
for ref in filters.get(todo.pop(), ("", []))[1]:
|
||||
if ref not in filters_used:
|
||||
filters_used.add(ref)
|
||||
todo.append(ref)
|
||||
have = self.get_secrets_info()
|
||||
return {"uses": {"networks": sorted(networks), "filters": sorted(filters_used), "secrets": sorted(secrets),
|
||||
"usages": sorted(usages, key=str)},
|
||||
"has": {"networks": sorted(n.name() for n in self.wvm.listAllNetworks(VIR_CONNECT_LIST_NETWORKS_ACTIVE)),
|
||||
"filters": {name: rules for name, (rules, _refs) in filters.items()},
|
||||
"secrets": sorted(secret["uuid"].lower() for secret in have),
|
||||
"usages": sorted(((secret["usage_type"], secret["usage"]) for secret in have), key=str)}}
|
||||
|
||||
def get_memory_usage(self):
|
||||
"""
|
||||
Function return memory usage on node.
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ from lxml import etree
|
|||
from vrtManager import util
|
||||
from vrtManager.connection import NVRAM_DIR, wvmConnect
|
||||
from vrtManager.nodedevs import check_hostdevs, pci_address, pci_label, usb_selector, usb_selector_label
|
||||
from vrtManager.nwfilters import same_text
|
||||
from vrtManager.nwfilters import filter_rules
|
||||
from vrtManager.storage import wvmStorage, wvmStorages
|
||||
from vrtManager.virtsecrets import REF_USAGE_TYPES
|
||||
|
||||
|
|
@ -138,10 +138,7 @@ class wvmInstances(wvmConnect):
|
|||
source (another connection), each sorted. A VM runs with its host's
|
||||
filters of those names, whatever their rules."""
|
||||
def rules(wvm, name):
|
||||
tree = etree.fromstring(wvm.nwfilterLookupByName(name).XMLDesc(0))
|
||||
for uuid in tree.findall("uuid"): # each host's own
|
||||
tree.remove(uuid)
|
||||
return same_text(etree.tostring(tree, encoding="unicode")), tree.xpath("filterref/@filter")
|
||||
return filter_rules(wvm.nwfilterLookupByName(name))
|
||||
|
||||
if not names: # the hosts are asked only about what the cards name
|
||||
return [], []
|
||||
|
|
|
|||
|
|
@ -13,6 +13,15 @@ from vrtManager.connection import wvmConnect
|
|||
NAME = re.compile(r"[A-Za-z0-9._-]+")
|
||||
|
||||
|
||||
def filter_rules(nwfilter):
|
||||
"""A network filter's rules as text, to compare two hosts' filters of a name (its
|
||||
UUID, each host's own, left out), and the filters it references."""
|
||||
tree = etree.fromstring(nwfilter.XMLDesc(0))
|
||||
for uuid in tree.findall("uuid"):
|
||||
tree.remove(uuid)
|
||||
return same_text(etree.tostring(tree, encoding="unicode")), tree.xpath("filterref/@filter")
|
||||
|
||||
|
||||
def element_text(element):
|
||||
"""An element as the page shows it and sends it back: a rule or reference
|
||||
is changed only while it still reads the same."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue