mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-10-26 17:25:22 +03:00
cli: Add --memory opts to match XML names
Sort out the memory property naming ambiguity on the command line. * memory -> currentMemory * maxmemory -> memory * hotplugmemorymax -> maxMemory * hotplugmemoryslots -> maxMemory.slots To maintain back compat, we need to do some funky handling with memory and maxmemory values. Basically if currentMemory is specfied, we interpret them as new style, otherwise preserve the old behavior.
This commit is contained in:
parent
7f9e21f9b5
commit
2d80a0b4b9
@ -95,10 +95,11 @@ running C<virt-install>.
|
||||
=item B<--memory> OPTIONS
|
||||
|
||||
Memory to allocate for the guest, in MiB. This deprecates the -r/--ram option.
|
||||
Sub options are available, like 'maxmemory', 'hugepages', 'hotplugmemorymax'
|
||||
and 'hotplugmemoryslots'. The memory parameter is mapped to <currentMemory> element,
|
||||
the 'maxmemory' sub-option is mapped to <memory> element and 'hotplugmemorymax'
|
||||
and 'hotplugmemoryslots' are mapped to <maxMemory> element.
|
||||
Sub options are available, like 'memory', 'currentMemory', 'maxMemory'
|
||||
and 'maxMemory.slots', which all map to the identically named XML values.
|
||||
|
||||
Back compat values 'memory' maps to the <currentMemory> element, and maxmemory
|
||||
maps to the <memory> element.
|
||||
|
||||
To configure memory modules which can be hotunplugged see B<--memdev> description.
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
<domain type="test">
|
||||
<name>foobar</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<maxMemory>409600</maxMemory>
|
||||
<memory>307200</memory>
|
||||
<currentMemory>102400</currentMemory>
|
||||
<vcpu>1</vcpu>
|
||||
<os>
|
||||
<type arch="i686">hvm</type>
|
||||
<boot dev="network"/>
|
||||
</os>
|
||||
<features>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset="utc"/>
|
||||
<on_reboot>destroy</on_reboot>
|
||||
<pm>
|
||||
<suspend-to-mem enabled="no"/>
|
||||
<suspend-to-disk enabled="no"/>
|
||||
</pm>
|
||||
<devices>
|
||||
<emulator>/usr/bin/test-hv</emulator>
|
||||
<controller type="usb" index="0" model="ich9-ehci1"/>
|
||||
<controller type="usb" index="0" model="ich9-uhci1">
|
||||
<master startport="0"/>
|
||||
</controller>
|
||||
<controller type="usb" index="0" model="ich9-uhci2">
|
||||
<master startport="2"/>
|
||||
</controller>
|
||||
<controller type="usb" index="0" model="ich9-uhci3">
|
||||
<master startport="4"/>
|
||||
</controller>
|
||||
<interface type="user">
|
||||
<mac address="00:11:22:33:44:55"/>
|
||||
<model type="e1000"/>
|
||||
</interface>
|
||||
<console type="pty"/>
|
||||
</devices>
|
||||
</domain>
|
||||
<domain type="test">
|
||||
<name>foobar</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<maxMemory>409600</maxMemory>
|
||||
<memory>307200</memory>
|
||||
<currentMemory>102400</currentMemory>
|
||||
<vcpu>1</vcpu>
|
||||
<os>
|
||||
<type arch="i686">hvm</type>
|
||||
<boot dev="network"/>
|
||||
</os>
|
||||
<features>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset="utc"/>
|
||||
<pm>
|
||||
<suspend-to-mem enabled="no"/>
|
||||
<suspend-to-disk enabled="no"/>
|
||||
</pm>
|
||||
<devices>
|
||||
<emulator>/usr/bin/test-hv</emulator>
|
||||
<controller type="usb" index="0" model="ich9-ehci1"/>
|
||||
<controller type="usb" index="0" model="ich9-uhci1">
|
||||
<master startport="0"/>
|
||||
</controller>
|
||||
<controller type="usb" index="0" model="ich9-uhci2">
|
||||
<master startport="2"/>
|
||||
</controller>
|
||||
<controller type="usb" index="0" model="ich9-uhci3">
|
||||
<master startport="4"/>
|
||||
</controller>
|
||||
<interface type="user">
|
||||
<mac address="00:11:22:33:44:55"/>
|
||||
<model type="e1000"/>
|
||||
</interface>
|
||||
<console type="pty"/>
|
||||
</devices>
|
||||
</domain>
|
@ -604,6 +604,7 @@ c.add_invalid("--clock foo_tickpolicy=merge") # Unknown timer
|
||||
c.add_invalid("--security foobar") # Busted --security
|
||||
c.add_compare("--cpuset auto --vcpus 2", "cpuset-auto") # --cpuset=auto actually works
|
||||
c.add_compare("--memory 1024,hotplugmemorymax=2048,hotplugmemoryslots=2 --cpu cell0.cpus=0,cell0.memory=1048576 --memdev dimm,access=private,target_size=512,target_node=0,source_pagesize=4,source_nodemask=1-2 --memdev nvdimm,source_path=/path/to/nvdimm,target_size=512,target_node=0,target_label_size=128", "memory-hotplug")
|
||||
c.add_compare("--memory currentMemory=100,memory=200,maxmemory=300,maxMemory=400", "memory-option-backcompat")
|
||||
c.add_compare("--connect " + utils.URIs.kvm_q35 + " --cpu qemu64,secure=off", "cpu-disable-sec") # disable security features that are added by default
|
||||
c.add_compare("--connect " + utils.URIs.kvm_rhel, "cpu-rhel7-default") # default CPU for old QEMU where we cannot use host-model
|
||||
|
||||
|
@ -614,9 +614,7 @@ def add_memory_option(grp, backcompat=False):
|
||||
grp.add_argument("--memory", action="append",
|
||||
help=_("Configure guest memory allocation. Ex:\n"
|
||||
"--memory 1024 (in MiB)\n"
|
||||
"--memory 512,maxmemory=1024\n"
|
||||
"--memory 512,maxmemory=1024,hotplugmemorymax=2048,"
|
||||
"hotplugmemoryslots=2"))
|
||||
"--memory memory=1024,currentMemory=512\n"))
|
||||
if backcompat:
|
||||
grp.add_argument("-r", "--ram", type=int, dest="oldmemory",
|
||||
help=argparse.SUPPRESS)
|
||||
@ -1643,19 +1641,60 @@ class ParserNumatune(VirtCLIParser):
|
||||
class ParserMemory(VirtCLIParser):
|
||||
cli_arg_name = "memory"
|
||||
remove_first = "memory"
|
||||
aliases = {
|
||||
"maxMemory.slots": "hotplugmemoryslots",
|
||||
"maxMemory": "hotplugmemorymax",
|
||||
}
|
||||
|
||||
def _convert_old_memory_options(self):
|
||||
"""
|
||||
Historically the cli had:
|
||||
memory -> ./currentMemory
|
||||
maxmemory -> ./memory
|
||||
Then later libvirt gained ./maxMemory. So things are quite a mess.
|
||||
|
||||
Try to convert the back compat cases. Basically if new style option
|
||||
currentMemory is specified, interpret currentMemory and memory as
|
||||
the XML values. Otherwise treat memory and maxmemory as the old
|
||||
swapped names.
|
||||
"""
|
||||
havecur = "currentMemory" in self.optdict
|
||||
havemax = "maxmemory" in self.optdict
|
||||
havemem = "memory" in self.optdict
|
||||
if havecur:
|
||||
if havemax:
|
||||
self.optdict["memory"] = self.optdict.pop("maxmemory", None)
|
||||
elif havemax:
|
||||
if havemem:
|
||||
self.optdict["currentMemory"] = self.optdict.pop("memory")
|
||||
self.optdict["memory"] = self.optdict.pop("maxmemory")
|
||||
elif havemem:
|
||||
self.optdict["currentMemory"] = self.optdict.pop("memory")
|
||||
|
||||
def _parse(self, inst):
|
||||
self._convert_old_memory_options()
|
||||
return super()._parse(inst)
|
||||
|
||||
|
||||
###################
|
||||
# Option handling #
|
||||
###################
|
||||
|
||||
def set_memory_cb(self, inst, val, virtarg):
|
||||
util.set_prop_path(inst, virtarg.propname, int(val) * 1024)
|
||||
|
||||
@classmethod
|
||||
def _init_class(cls, **kwargs):
|
||||
VirtCLIParser._init_class(**kwargs)
|
||||
cls.add_arg("memory", "currentMemory", cb=cls.set_memory_cb)
|
||||
cls.add_arg("maxmemory", "memory", cb=cls.set_memory_cb)
|
||||
cls.add_arg("memory", "memory", cb=cls.set_memory_cb)
|
||||
cls.add_arg("currentMemory", "currentMemory", cb=cls.set_memory_cb)
|
||||
cls.add_arg("maxMemory", "maxMemory", cb=cls.set_memory_cb)
|
||||
cls.add_arg("maxMemory.slots", "maxMemorySlots")
|
||||
|
||||
# This is converted into either memory or currentMemory
|
||||
cls.add_arg("maxmemory", None, lookup_cb=None, cb=cls.noset_cb)
|
||||
|
||||
# New memoryBacking properties should be added to the --memorybacking
|
||||
cls.add_arg("hugepages", "memoryBacking.hugepages", is_onoff=True)
|
||||
cls.add_arg("hotplugmemorymax", "maxMemory",
|
||||
cb=cls.set_memory_cb)
|
||||
cls.add_arg("hotplugmemoryslots", "maxMemorySlots")
|
||||
|
||||
|
||||
#####################
|
||||
|
Loading…
Reference in New Issue
Block a user