details: Revive maxmem and memory hotplug

This was removed in 7547905d79 but I've changed my mind about
dropping it

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-09-13 17:59:51 -04:00
parent 428948a690
commit 6657e23a7a
4 changed files with 144 additions and 14 deletions

View File

@ -176,14 +176,27 @@ class Details(lib.testcase.UITestCase):
appl.click()
lib.utils.check(lambda: not appl.sensitive)
# There's no hotplug operations after this point
self._stop_vm(win)
# Memory
tab = self._select_hw(win, "Memory", "memory-tab")
tab.find("Memory allocation:", "spin button").set_text("300")
curmem = tab.find("Current allocation:", "spin button")
maxmem = tab.find("Maximum allocation:", "spin button")
maxmemtext = maxmem.text
curmem.set_text("2000")
appl.click()
lib.utils.check(lambda: not appl.sensitive)
curmem.set_text("50000")
lib.utils.check(lambda: maxmem.text == "50000")
curmem.set_text("5000")
lib.utils.check(lambda: maxmem.text == "50000")
maxmem.set_text("1500")
appl.click()
self.app.click_alert_button("changes will take effect", "OK")
lib.utils.check(lambda: not appl.sensitive)
# There's no hotplug operations after this point
self._stop_vm(win)
lib.utils.check(lambda: curmem.text == "1500")
lib.utils.check(lambda: maxmem.text == "1500")
# Static CPU config
# more cpu config: host-passthrough, copy, clear CPU, manual

View File

@ -2,6 +2,13 @@
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="lower">1</property>
<property name="upper">10240000</property>
<property name="value">50</property>
<property name="step_increment">1</property>
<property name="page_increment">25</property>
</object>
<object class="GtkAdjustment" id="adjustment16">
<property name="upper">10000000</property>
<property name="value">1000</property>
@ -1659,7 +1666,7 @@
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="label" translatable="yes">Memory a_llocation:</property>
<property name="label" translatable="yes">Current a_llocation:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">mem-memory</property>
</object>
@ -1668,6 +1675,21 @@
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label307">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="label" translatable="yes">Ma_ximum allocation:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">mem-maxmem</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label61">
<property name="visible">True</property>
@ -1745,6 +1767,55 @@
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox47">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="spacing">3</property>
<child>
<object class="GtkSpinButton" id="mem-maxmem">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="text" translatable="yes">50</property>
<property name="adjustment">adjustment1</property>
<property name="climb_rate">2</property>
<property name="numeric">True</property>
<property name="update_policy">if-valid</property>
<property name="value">50</property>
<signal name="changed" handler="on_mem_maxmem_changed" swapped="no"/>
<child internal-child="accessible">
<object class="AtkObject" id="mem-maxmem-atkobject">
<property name="AtkObject::accessible-name">Max Memory Select</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label346">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">MiB</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
</child>
</object>

View File

@ -447,7 +447,8 @@ class vmmDetails(vmmGObjectUI):
"on_cpu_sockets_changed": self._cpu_topology_changed_cb,
"on_cpu_threads_changed": self._cpu_topology_changed_cb,
"on_cpu_topology_enable_toggled": self._cpu_topology_enable_cb,
"on_mem_memory_changed": _e(EDIT_MEM),
"on_mem_maxmem_changed": _e(EDIT_MEM),
"on_mem_memory_changed": self._curmem_changed_cb,
"on_boot_list_changed": self._boot_list_changed_cb,
"on_boot_moveup_clicked": self._boot_moveup_clicked_cb,
@ -1126,6 +1127,17 @@ class vmmDetails(vmmGObjectUI):
def _os_list_name_selected_cb(self, src, osobj):
self._enable_apply(EDIT_OS_NAME)
def _curmem_changed_cb(self, src):
self._enable_apply(EDIT_MEM)
maxadj = self.widget("mem-maxmem")
mem = uiutil.spin_get_helper(self.widget("mem-memory"))
if maxadj.get_value() < mem:
maxadj.set_value(mem)
ignore, upper = maxadj.get_range()
maxadj.set_range(mem, upper)
def _config_vcpus_changed_cb(self, src):
self._enable_apply(EDIT_VCPUS)
@ -1435,13 +1447,22 @@ class vmmDetails(vmmGObjectUI):
def _apply_memory(self):
kwargs = {}
hotplug_args = {}
if self._edited(EDIT_MEM):
memory = uiutil.spin_get_helper(self.widget("mem-memory"))
kwargs["memory"] = int(memory) * 1024
maxmem = uiutil.spin_get_helper(self.widget("mem-maxmem"))
curmem = uiutil.spin_get_helper(self.widget("mem-memory"))
curmem = int(curmem) * 1024
maxmem = int(maxmem) * 1024
return vmmAddHardware.change_config_helper(self.vm.define_memory,
kwargs, self.vm, self.err)
kwargs["memory"] = curmem
kwargs["maxmem"] = maxmem
hotplug_args["memory"] = kwargs["memory"]
hotplug_args["maxmem"] = kwargs["maxmem"]
return vmmAddHardware.change_config_helper(
self.vm.define_memory, kwargs, self.vm, self.err,
hotplug_args=hotplug_args)
def _apply_boot_options(self):
kwargs = {}
@ -1960,12 +1981,15 @@ class vmmDetails(vmmGObjectUI):
def _refresh_config_memory(self):
host_mem_widget = self.widget("state-host-memory")
host_mem = self.vm.conn.host_memory_size() // 1024
vm_cur_mem = self.vm.xmlobj.memory / 1024.0
vm_cur_mem = self.vm.xmlobj.currentMemory / 1024.0
vm_max_mem = self.vm.xmlobj.memory / 1024.0
host_mem_widget.set_text("%d MiB" % (int(round(host_mem))))
curmem = self.widget("mem-memory")
maxmem = self.widget("mem-maxmem")
curmem.set_value(int(round(vm_cur_mem)))
maxmem.set_value(int(round(vm_max_mem)))
def _refresh_disk_page(self, disk):
path = disk.path

View File

@ -648,12 +648,13 @@ class vmmDomain(vmmLibvirtObject):
guest.cpu.set_model(guest, model)
self._redefine_xmlobj(guest)
def define_memory(self, memory=_SENTINEL):
def define_memory(self, memory=_SENTINEL, maxmem=_SENTINEL):
guest = self._make_xmlobj_to_define()
if memory != _SENTINEL:
guest.currentMemory = int(memory)
guest.memory = int(memory)
if maxmem != _SENTINEL:
guest.memory = int(maxmem)
self._redefine_xmlobj(guest)
def define_overview(self, machine=_SENTINEL, description=_SENTINEL,
@ -1014,15 +1015,36 @@ class vmmDomain(vmmLibvirtObject):
log.debug("update_device with xml=\n%s", xml)
self._backend.updateDeviceFlags(xml, flags)
def hotplug(self, description=_SENTINEL, title=_SENTINEL, device=_SENTINEL):
def hotplug(self, memory=_SENTINEL, maxmem=_SENTINEL,
description=_SENTINEL, title=_SENTINEL, device=_SENTINEL):
if not self.is_active():
return
def _hotplug_memory(val):
if val != self.xmlobj.currentMemory:
self._backend.setMemory(val)
def _hotplug_maxmem(val):
if val != self.xmlobj.memory:
self._backend.setMaxMemory(val)
def _hotplug_metadata(val, mtype):
flags = (libvirt.VIR_DOMAIN_AFFECT_LIVE |
libvirt.VIR_DOMAIN_AFFECT_CONFIG)
self._backend.setMetadata(mtype, val, None, None, flags)
if memory != _SENTINEL:
log.debug("Hotplugging curmem=%s maxmem=%s for VM '%s'",
memory, maxmem, self.get_name())
actual_cur = self.xmlobj.currentMemory
if maxmem < actual_cur:
# Set current first to avoid error
_hotplug_memory(memory)
_hotplug_maxmem(maxmem)
else:
_hotplug_maxmem(maxmem)
_hotplug_memory(memory)
if description != _SENTINEL:
_hotplug_metadata(description,
libvirt.VIR_DOMAIN_METADATA_DESCRIPTION)