virt-install: add --resource support

This patch will enable setting
resource partition configuration.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This commit is contained in:
Chen Hanxiao 2014-06-04 10:08:05 +08:00
parent 809c5a81e5
commit d1b0fade1d
8 changed files with 65 additions and 3 deletions

View File

@ -129,6 +129,12 @@ Specify events values for the guest. Possible options include on_poweroff, on_re
Use --events=? to see a list of all available sub options. Complete details at L<http://libvirt.org/formatdomain.html#elementsEvents>
=item --resource OPT=VAL,[...]
Specify resource partitioning for the guest.
Use --resource=? to see a list of all available sub options. Complete details at L<http://libvirt.org/formatdomain.html#resPartition>
=item --vcpus=VCPUS[,maxvcpus=MAX][,sockets=#][,cores=#][,threads=#][,cpuset=CPUSET]
Number of virtual cpus to configure for the guest. If 'maxvcpus' is specified,

View File

@ -472,6 +472,7 @@ c.add_valid("--blkiotune weight=100,device_path=/home/test/1.img,device_weight=2
c.add_valid("--memtune hard_limit=10,soft_limit=20,swap_hard_limit=30,min_guarantee=40") # --memtune
c.add_valid("--memorybacking hugepages=yes,nosharepages=yes,locked=yes") # --memorybacking nosharepages,locked
c.add_valid("--idmap uid_start=0,uid_target=1000,uid_count=10,gid_start=0,gid_target=1000,gid_count=10") # --idmap
c.add_valid("--resource partition=/virtualmachines/production") # --resource
c.add_compare("--connect %(DEFAULTURI)s --cpuset auto --vcpus 2", "cpuset-auto") # --cpuset=auto actually works
c.add_invalid("--vcpus 32 --cpuset=969-1000") # Bogus cpuset
c.add_invalid("--vcpus 32 --cpuset=autofoo") # Bogus cpuset

View File

@ -86,6 +86,9 @@
<nosharepages/>
<locked/>
</memoryBacking>
<resource>
<partition>/virtualmachines/production</partition>
</resource>
<memtune>
<hard_limit>2048</hard_limit>
<soft_limit>200</soft_limit>

View File

@ -213,6 +213,9 @@ class XMLParseTest(unittest.TestCase):
check("gid_target", None, 1000)
check("gid_count", None, 10)
check = self._make_checker(guest.resource)
check("partition", None, "/virtualmachines/production")
check = self._make_checker(guest.get_devices("memballoon")[0])
check("model", "virtio", "none")

View File

@ -29,6 +29,7 @@ from virtinst.domainnumatune import DomainNumatune
from virtinst.domainblkiotune import DomainBlkiotune
from virtinst.domainmemorytune import DomainMemorytune
from virtinst.domainmemorybacking import DomainMemorybacking
from virtinst.domainresource import DomainResource
from virtinst.clock import Clock
from virtinst.cpu import CPU, CPUFeature
from virtinst.seclabel import Seclabel

View File

@ -800,6 +800,8 @@ def add_guest_xml_options(geng):
geng.add_argument("--pm", help=_("Config power management features"))
geng.add_argument("--events",
help=_("Config OS lifecycle operation management features"))
geng.add_argument("--resource", action="append",
help=_("Config OS resource management features"))
def add_boot_options(insg):
@ -1239,6 +1241,18 @@ class ParserEvents(VirtCLIParser):
self.set_param("on_crash", "on_crash")
######################
# --resource parsing #
######################
class ParserResource(VirtCLIParser):
def _init_params(self):
self.remove_first = "partition"
self.clear_attr = "resource"
self.set_param("resource.partition", "partition")
######################
# --numatune parsing #
######################
@ -2234,6 +2248,7 @@ def build_parser_map(options, skip=None, only=None):
register_parser("metadata", ParserMetadata)
register_parser("events", ParserEvents)
register_parser("resource", ParserResource)
register_parser("memory", ParserMemory)
register_parser("memtune", ParserMemorytune)
register_parser("vcpus", ParserVCPU)

View File

@ -0,0 +1,31 @@
#
# Copyright 2014 Fujitsu Limited.
# Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
from virtinst.xmlbuilder import XMLBuilder, XMLProperty
class DomainResource(XMLBuilder):
"""
Class for generating <resource> XML
"""
_XML_ROOT_NAME = "resource"
_XML_PROP_ORDER = ["partition"]
partition = XMLProperty("./partition")

View File

@ -39,6 +39,7 @@ from virtinst import DomainMemorytune
from virtinst import DomainMemorybacking
from virtinst import DomainBlkiotune
from virtinst import DomainFeatures
from virtinst import DomainResource
from virtinst import PM
from virtinst import IdMap
from virtinst.xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty
@ -93,9 +94,9 @@ class Guest(XMLBuilder):
_XML_ROOT_NAME = "domain"
_XML_PROP_ORDER = ["type", "name", "uuid", "title", "description",
"maxmemory", "memory", "memoryBacking", "vcpus", "curvcpus", "memtune",
"numatune", "blkiotune", "bootloader", "os", "idmap", "features",
"cpu", "clock", "on_poweroff", "on_reboot", "on_crash", "pm",
"maxmemory", "memory", "memoryBacking", "vcpus", "resource", "curvcpus",
"memtune", "numatune", "blkiotune", "bootloader", "os", "idmap",
"features", "cpu", "clock", "on_poweroff", "on_reboot", "on_crash", "pm",
"emulator", "_devices", "seclabel"]
def __init__(self, *args, **kwargs):
@ -196,6 +197,7 @@ class Guest(XMLBuilder):
memtune = XMLChildProperty(DomainMemorytune, is_single=True)
memoryBacking = XMLChildProperty(DomainMemorybacking, is_single=True)
idmap = XMLChildProperty(IdMap, is_single=True)
resource = XMLChildProperty(DomainResource, is_single=True)
###############################