mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
Allow changing vcpu count in the persistent config.
Changes similar to what was done with memory: try cpu hotplug, and always follow up with XML definition.
This commit is contained in:
parent
8c9bbe1d66
commit
3936943a63
@ -1603,7 +1603,26 @@ class vmmDetails(gobject.GObject):
|
||||
vcpus = self.window.get_widget("config-vcpus").get_adjustment().value
|
||||
logging.info("Setting vcpus for %s to %s" % (self.vm.get_name(),
|
||||
str(vcpus)))
|
||||
self.vm.set_vcpu_count(vcpus)
|
||||
hotplug_err = False
|
||||
|
||||
try:
|
||||
if self.vm.is_active():
|
||||
self.vm.hotplug_vcpus(vcpus)
|
||||
except Exception, e:
|
||||
logging.debug("VCPU hotplug failed: %s" % str(e))
|
||||
hotplug_err = True
|
||||
|
||||
# Change persistent config
|
||||
try:
|
||||
self.vm.define_vcpus(vcpus)
|
||||
except Exception, e:
|
||||
self.err.show_err(_("Error changing vcpu value: %s" % str(e)),
|
||||
"".join(traceback.format_exc()))
|
||||
return False
|
||||
|
||||
if hotplug_err:
|
||||
self.err.show_info(_("These changes will take effect after the "
|
||||
"next guest reboot. "))
|
||||
|
||||
def config_get_maxmem(self):
|
||||
maxadj = self.window.get_widget("config-maxmem").get_adjustment()
|
||||
@ -1657,7 +1676,7 @@ class vmmDetails(gobject.GObject):
|
||||
logging.debug("Memory hotplug failed: %s" % str(e))
|
||||
hotplug_err = True
|
||||
|
||||
# Change persisten config
|
||||
# Change persistent config
|
||||
try:
|
||||
self.vm.define_both_mem(curmem, maxmem)
|
||||
except Exception, e:
|
||||
|
@ -180,14 +180,15 @@ class vmmDomain(gobject.GObject):
|
||||
if origxml == newxml:
|
||||
logging.debug("Redefinition requested, but new xml was not"
|
||||
" different")
|
||||
return
|
||||
|
||||
diff = "".join(difflib.unified_diff(origxml.splitlines(1),
|
||||
newxml.splitlines(1),
|
||||
fromfile="Original XML",
|
||||
tofile="New XML"))
|
||||
logging.debug("Redefining '%s' with XML diff:\n%s",
|
||||
self.get_name(), diff)
|
||||
else:
|
||||
diff = "".join(difflib.unified_diff(origxml.splitlines(1),
|
||||
newxml.splitlines(1),
|
||||
fromfile="Original XML",
|
||||
tofile="New XML"))
|
||||
logging.debug("Redefining '%s' with XML diff:\n%s",
|
||||
self.get_name(), diff)
|
||||
|
||||
self.get_connection().define_domain(newxml)
|
||||
|
||||
# Invalidate cached XML
|
||||
@ -1295,9 +1296,30 @@ class vmmDomain(gobject.GObject):
|
||||
logging.debug("eject_cdrom produced: %s" % result)
|
||||
self._change_cdrom(result, dev_id_info)
|
||||
|
||||
def set_vcpu_count(self, vcpus):
|
||||
def hotplug_vcpu(self, vcpus):
|
||||
self.vm.setVcpus()
|
||||
|
||||
def hotplug_vcpus(self, vcpus):
|
||||
vcpus = int(vcpus)
|
||||
self.vm.setVcpus(vcpus)
|
||||
if vcpus != self.vcpu_count():
|
||||
self.vm.setVcpus(vcpus)
|
||||
|
||||
def define_vcpus(self, vcpus):
|
||||
vcpus = int(vcpus)
|
||||
|
||||
def set_node(doc, ctx, val, xpath):
|
||||
node = ctx.xpathEval(xpath)
|
||||
node = (node and node[0] or None)
|
||||
|
||||
if node:
|
||||
node.setContent(str(val))
|
||||
return doc.serialize()
|
||||
|
||||
def change_vcpu_xml(xml, vcpus):
|
||||
return util.xml_parse_wrapper(xml, set_node, vcpus,
|
||||
"/domain/vcpu[1]")
|
||||
|
||||
self.redefine(change_vcpu_xml, vcpus)
|
||||
|
||||
def hotplug_memory(self, memory):
|
||||
if memory != self.get_memory():
|
||||
|
Loading…
Reference in New Issue
Block a user