1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 08:26:03 +00:00

fix(instances): memory, boot order and QoS edits check what they change first

Three edits went wrong on input or a state made outside the panel:

- A running VM's memory was set live, then for its next start. When the
  next start had a lower maximum (virsh --config), the live change was
  made and the second one failed. The maximum of the next start is now
  checked first.
- A boot order entry without its device type ("disk") raised an error
  page. It is now refused with a message.
- A QoS form of a NIC whose MAC changed since redefined the VM unchanged
  and said the QoS was set or deleted. It now says the NIC is not in the
  definition.

Turkish and Chinese texts included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-11 12:43:40 +03:00
parent 63fb7defee
commit 015972dc38
8 changed files with 307 additions and 243 deletions

View file

@ -1701,6 +1701,12 @@ class wvmInstance(wvmConnect):
# an active VM (running, paused, ...) changes only its current memory;
# a paused guest's balloon driver applies it once it is resumed
if self.instance.isActive():
# the next start's maximum may differ (set with virsh --config):
# checked before the running VM changes
pending = int(etree.fromstring(self._XMLDesc(PERSISTENT_XML)).findtext("memory"))
if cur_memory > pending:
raise util.OperationError(gettext_noop("The VM's next start has a maximum memory of %(max)s MiB"),
max=pending // 1024)
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_LIVE)
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_CONFIG)
return
@ -3085,6 +3091,13 @@ class wvmInstance(wvmConnect):
def set_memory(self, size, flags=0):
self.instance.setMemoryFlags(size, flags)
@staticmethod
def _persistent_nic(tree, mac):
"""Refuses a MAC no NIC of the persistent definition has: a form
loaded before the NIC changed."""
if not tree.xpath("/domain/devices/interface[mac/@address=$mac]", mac=mac):
raise util.OperationError(gettext_noop("Network interface %(mac)s is not in the definition"), mac=mac)
def set_qos(self, mac, direction, average, peak, burst):
if direction not in ("inbound", "outbound"):
raise ValueError("Direction must be inbound or outbound")
@ -3096,6 +3109,7 @@ class wvmInstance(wvmConnect):
xml = f"<{direction} average='{average}' peak='{peak}' burst='{burst}'/>"
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
self._persistent_nic(tree, mac)
macs = tree.xpath("/domain/devices/interface/mac")
for cur_mac in macs:
@ -3118,6 +3132,7 @@ class wvmInstance(wvmConnect):
def unset_qos(self, mac, direction):
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
self._persistent_nic(tree, mac)
for direct in tree.xpath(
"/domain/devices/interface/bandwidth/{}".format(direction)
):