mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(computes): Balance proposes migrations that even out the hosts
A Balance button on the Computes page opens computes/balance/: the memory and vCPUs each host gives its running VMs, before and after, and the proposed migrations. The proposal (computes/balance.py) takes, step by step, the one move that most lowers the sum of the squared memory loads, then of the squared vCPU loads, and stops when none does; each VM moves once, and the VMs moved to a host fit in the memory its running and paused VMs leave without counting those moved away, so the moves may run in any order. Only running VMs count and move; one that cannot move (no destination shares its disks) still counts on its host and is listed with the reason. Unticking a VM keeps it where it is and makes the proposal again. Migrate runs the moves shown in one host.balance job. It shares the bulk migration's loop (computes.jobs.Migrations): migrate jobs, the chosen number at once, one bulk job at a time. Its migrations take only a running VM (moveto running_only): one stopped since stays where it is. A job another one started now shows only on its own page: a host's page no longer lists a bulk migration's or a balance's migrations, and the Computes page shows the bulk jobs.
This commit is contained in:
parent
027896c3d4
commit
4941a8a048
19 changed files with 1179 additions and 481 deletions
|
|
@ -149,15 +149,15 @@ class wvmInstances(wvmConnect):
|
|||
return sorted(missing), sorted(unlike)
|
||||
|
||||
def moveto(self, conn, name, live, unsafe, offline, autoconverge=False, compress=False, uri=None,
|
||||
pools=None, on_copy=None):
|
||||
pools=None, on_copy=None, running_only=False):
|
||||
"""Migrates the VM of conn (a wvmInstance on the source) here.
|
||||
|
||||
The mode follows the VM's state, read once: a running VM migrates
|
||||
live or, without live, paused for the transfer (non-live); a paused
|
||||
VM stays paused; a shut-off VM moves offline, also when the request
|
||||
was made while it ran (live). An offline request for a running or
|
||||
paused VM is refused. unsafe, autoconverge (live only) and
|
||||
compress apply to a running VM. uri: the native migration URI
|
||||
paused VM is refused, and with running_only a VM not running.
|
||||
unsafe, autoconverge (live only) and compress apply to a running VM. uri: the native migration URI
|
||||
(tcp://address) on the destination; None lets libvirt use the
|
||||
destination's own hostname. pools: {target: pool here} of the disks
|
||||
libvirt copies into those pools during the migration (disk_copies);
|
||||
|
|
@ -166,6 +166,8 @@ class wvmInstances(wvmConnect):
|
|||
libvirt makes them. Returns the mode and options used, for the log,
|
||||
and each copied disk's path and the path of its copy here."""
|
||||
state = conn.get_status()
|
||||
if running_only and state != 1:
|
||||
raise util.OperationError(gettext_noop("The VM is not running"))
|
||||
if state == 5:
|
||||
mode = ["offline"]
|
||||
elif state in (1, 3):
|
||||
|
|
|
|||
|
|
@ -30,6 +30,17 @@ class MigrationFlagsTestCase(unittest.TestCase):
|
|||
destination().moveto(source, "vm", live=True, unsafe=False, offline=False)
|
||||
self.assertIsNone(source.instance.calls[0][1])
|
||||
|
||||
def test_running_only_refuses_a_vm_not_running(self):
|
||||
for state in (3, 5):
|
||||
with self.subTest(state=state):
|
||||
source = FakeSource(state)
|
||||
with self.assertRaisesRegex(util.OperationError, "not running"):
|
||||
destination().moveto(source, "vm", live=True, unsafe=False, offline=False, running_only=True)
|
||||
self.assertEqual(source.instance.calls, [])
|
||||
source = FakeSource(1)
|
||||
destination().moveto(source, "vm", live=True, unsafe=False, offline=False, running_only=True)
|
||||
self.assertEqual(len(source.instance.calls), 1)
|
||||
|
||||
|
||||
class ShutOffMigrationTestCase(unittest.TestCase):
|
||||
"""libvirt's offline migration fails on some builds (RHEL-156800); a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue