[virt-tools-list] [virt-manager PATCH] virt-install: add --resource support

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Fri May 30 06:01:22 UTC 2014


This patch will enable setting
resource partition configuration.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 man/virt-install.pod                    |  6 ++++++
 tests/clitest.py                        |  1 +
 tests/xmlparse-xml/change-guest-out.xml |  3 +++
 tests/xmlparse.py                       |  3 +++
 virtinst/__init__.py                    |  1 +
 virtinst/cli.py                         | 15 +++++++++++++++
 virtinst/domainresource.py              | 31 +++++++++++++++++++++++++++++++
 virtinst/guest.py                       |  8 +++++---
 8 files changed, 65 insertions(+), 3 deletions(-)
 create mode 100644 virtinst/domainresource.py

diff --git a/man/virt-install.pod b/man/virt-install.pod
index 8aa7ead..7268a64 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -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,
diff --git a/tests/clitest.py b/tests/clitest.py
index 95c7667..3872305 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -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
diff --git a/tests/xmlparse-xml/change-guest-out.xml b/tests/xmlparse-xml/change-guest-out.xml
index 5b1a12b..ab043d6 100644
--- a/tests/xmlparse-xml/change-guest-out.xml
+++ b/tests/xmlparse-xml/change-guest-out.xml
@@ -83,6 +83,9 @@
     <nosharepages/>
     <locked/>
   </memoryBacking>
+  <resource>
+    <partition>/virtualmachines/production</partition>
+  </resource>
   <memtune>
     <hard_limit>2048</hard_limit>
     <soft_limit>200</soft_limit>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 980df27..6ffe186 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -209,6 +209,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")
 
diff --git a/virtinst/__init__.py b/virtinst/__init__.py
index 31beae4..8c4cc14 100644
--- a/virtinst/__init__.py
+++ b/virtinst/__init__.py
@@ -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
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 836f0a5..61d24f8 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -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):
@@ -1240,6 +1242,18 @@ class ParserEvents(VirtCLIParser):
 
 
 ######################
+# --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 #
 ######################
 
@@ -2227,6 +2241,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)
diff --git a/virtinst/domainresource.py b/virtinst/domainresource.py
new file mode 100644
index 0000000..102409a
--- /dev/null
+++ b/virtinst/domainresource.py
@@ -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")
diff --git a/virtinst/guest.py b/virtinst/guest.py
index df43a5e..a59f59e 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -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)
 
 
     ###############################
-- 
1.9.0




More information about the virt-tools-list mailing list