[virt-tools-list] [PATCH] virt-install: Add --memballoon support
Eiichi Tsukata
devel at etsukata.com
Sun Apr 8 10:42:39 UTC 2012
Currently, virt-install automatically creates memballoon device.
This patch adds the option to disable memballoon device.
Disable memballoon device:
--memballoon none
Enable memballoon device with model virtio:
--memballoon virtio
Signed-off-by: Eiichi Tsukata <devel at etsukata.com>
---
AUTHORS | 1 +
man/en/virt-install.pod.in | 17 ++++++++
tests/clitest.py | 6 +++
tests/xmlconfig-xml/boot-many-devices.xml | 1 +
tests/xmlconfig.py | 7 +++
virt-install | 1 +
virtinst/Guest.py | 3 +-
virtinst/VirtualDevice.py | 4 +-
virtinst/VirtualMemballoon.py | 58 +++++++++++++++++++++++++++++
virtinst/__init__.py | 3 +-
virtinst/cli.py | 34 +++++++++++++++++
11 files changed, 132 insertions(+), 3 deletions(-)
create mode 100644 virtinst/VirtualMemballoon.py
diff --git a/AUTHORS b/AUTHORS
index 5f9fed2..341b10f 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -60,6 +60,7 @@ Patches also received from
Li Zhang <zhlcindy-at-linux-dot-vnet-dot-ibm-dot-com>
Deepak C Shetty <deepakcs-at-linux-dot-vnet-dot-ibm-dot-com>
Wanlong Gao <gaowanlong-at-cn-dot-fujitsu-dot-com>
+ Eiichi Tsukata <devel-at-etsukata-dot-com>
...send patches and get your name here...
diff --git a/man/en/virt-install.pod.in b/man/en/virt-install.pod.in
index ee991ab..460d95e 100644
--- a/man/en/virt-install.pod.in
+++ b/man/en/virt-install.pod.in
@@ -1142,6 +1142,23 @@ Add a USB device redirected via a dedicated Spice channel.
=back
+=item --memballoon MODEL
+
+Attach a virtual memory balloon device to the guest. If the memballoon device
+needs to be explicitly disabled, MODEL='none' is used.
+
+MODEL is the type of memballoon device provided. The value can be 'virtio',
+'xen' or 'none'.
+Some examples:
+
+Use the recommended settings:
+
+--memballoon virtio
+
+Do not use memballoon device:
+
+--memballoon none
+
=head2 Miscellaneous Options
=over 2
diff --git a/tests/clitest.py b/tests/clitest.py
index abeabbe..c320453 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -567,6 +567,10 @@ args_dict = {
"--hvm --pxe --filesystem template_name,/,type=template",
# no networks
"--hvm --nodisks --nonetworks --cdrom %(EXISTIMG1)s",
+ # --memballoon use virtio
+ "--hvm --nodisks --pxe --memballoon virtio",
+ # --memballoon disabled
+ "--hvm --nodisks --pxe --memballoon none",
],
"invalid": [
@@ -586,6 +590,8 @@ args_dict = {
"--paravirt --import --disk path=virt-install --print-step 2",
# 2 stage install with --print-xml
"--hvm --nodisks --pxe --print-xml",
+ # Busted --memballoon
+ "--hvm --nodisks --pxe --memballoon foobar",
],
"compare": [
diff --git a/tests/xmlconfig-xml/boot-many-devices.xml b/tests/xmlconfig-xml/boot-many-devices.xml
index 043e291..9a6f91d 100644
--- a/tests/xmlconfig-xml/boot-many-devices.xml
+++ b/tests/xmlconfig-xml/boot-many-devices.xml
@@ -93,6 +93,7 @@
</source>
</hostdev>
<watchdog model='ib700' action='none'/>
+ <memballoon model='virtio'/>
</devices>
<seclabel type='static' model='selinux'>
<label>foolabel</label>
diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py
index 1dd447d..c95d4e7 100644
--- a/tests/xmlconfig.py
+++ b/tests/xmlconfig.py
@@ -31,6 +31,7 @@ from virtinst import VirtualVideoDevice
from virtinst import VirtualController
from virtinst import VirtualWatchdog
from virtinst import VirtualInputDevice
+from virtinst import VirtualMemballoon
import utils
_testconn = utils.open_testdriver()
@@ -772,11 +773,17 @@ class TestXMLConfig(unittest.TestCase):
g.add_device(vdev3)
g.add_device(vdev4)
+ # Watchdog Devices
wdev2 = VirtualWatchdog(g.conn)
wdev2.model = "ib700"
wdev2.action = "none"
g.add_device(wdev2)
+ # Memballoon Devices
+ mdev1 = VirtualMemballoon(g.conn)
+ mdev1.model = "virtio"
+ g.add_device(mdev1)
+
# Check keymap autoconfig
gdev1 = virtinst.VirtualGraphics(conn=g.conn, type="vnc")
self.assertTrue(gdev1.keymap != None)
diff --git a/virt-install b/virt-install
index 1540dac..2e1770e 100755
--- a/virt-install
+++ b/virt-install
@@ -492,6 +492,7 @@ def build_guest_instance(conn, options):
# Non-default devices
cli.get_controller(guest, options.controller)
cli.get_redirdev(guest, options.redirdev)
+ cli.get_memballoon(guest, options.memballoon)
if not options.nonetworks:
get_networks(guest, options)
get_graphics(guest, options)
diff --git a/virtinst/Guest.py b/virtinst/Guest.py
index cd529aa..93e407f 100644
--- a/virtinst/Guest.py
+++ b/virtinst/Guest.py
@@ -782,7 +782,8 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
"controller": virtinst.VirtualController,
"filesystem": virtinst.VirtualFilesystem,
"smartcard" : virtinst.VirtualSmartCardDevice,
- "redirdev" : virtinst.VirtualRedirDevice,
+ "redirdev" : virtinst.VirtualRedirDevice,
+ "memballoon": virtinst.VirtualMemballoon,
}
# Hand off all child element parsing to relevant classes
diff --git a/virtinst/VirtualDevice.py b/virtinst/VirtualDevice.py
index 95b43fb..ce987fe 100644
--- a/virtinst/VirtualDevice.py
+++ b/virtinst/VirtualDevice.py
@@ -44,6 +44,7 @@ class VirtualDevice(XMLBuilderDomain):
VIRTUAL_DEV_FILESYSTEM = "filesystem"
VIRTUAL_DEV_SMARTCARD = "smartcard"
VIRTUAL_DEV_REDIRDEV = "redirdev"
+ VIRTUAL_DEV_MEMBALLOON = "memballoon"
# Ordering in this list is important: it will be the order the
# Guest class outputs XML. So changing this may upset the test suite
@@ -62,7 +63,8 @@ class VirtualDevice(XMLBuilderDomain):
VIRTUAL_DEV_HOSTDEV,
VIRTUAL_DEV_WATCHDOG,
VIRTUAL_DEV_SMARTCARD,
- VIRTUAL_DEV_REDIRDEV]
+ VIRTUAL_DEV_REDIRDEV,
+ VIRTUAL_DEV_MEMBALLOON]
# General device type (disk, interface, etc.)
_virtual_device_type = None
diff --git a/virtinst/VirtualMemballoon.py b/virtinst/VirtualMemballoon.py
new file mode 100644
index 0000000..7bb09aa
--- /dev/null
+++ b/virtinst/VirtualMemballoon.py
@@ -0,0 +1,58 @@
+#
+# Copyright 2012
+# Eiichi Tsukata <devel at etsukata.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.
+
+import VirtualDevice
+from virtinst import _gettext as _
+from XMLBuilderDomain import _xml_property
+
+class VirtualMemballoon(VirtualDevice.VirtualDevice):
+
+ _virtual_device_type = VirtualDevice.VirtualDevice.VIRTUAL_DEV_MEMBALLOON
+
+ MODEL_DEFAULT = "virtio"
+ MODELS = [ "xen", "none", MODEL_DEFAULT ]
+
+ def __init__(self, model=MODEL_DEFAULT,
+ conn=None, parsexml=None, parsexmlnode=None, caps=None):
+ VirtualDevice.VirtualDevice.__init__(self, conn, parsexml,
+ parsexmlnode, caps)
+
+ self._model = None
+
+ if self._is_parse():
+ return
+
+ self.model = model
+
+ def get_model(self):
+ return self._model
+ def set_model(self, new_model):
+ if type(new_model) != str:
+ raise ValueError(_("'model' must be a string, "
+ " was '%s'." % type(new_model)))
+ if not self.MODELS.count(new_model):
+ raise ValueError(_("Unsupported memballoon model '%s'" % new_model))
+ self._model = new_model
+ model = _xml_property(get_model, set_model,
+ xpath="./@model")
+
+ def _get_xml_config(self):
+ xml = " <memballoon model='%s'" % self.model
+ xml += "/>"
+ return xml
diff --git a/virtinst/__init__.py b/virtinst/__init__.py
index efa4d0d..a392b9a 100644
--- a/virtinst/__init__.py
+++ b/virtinst/__init__.py
@@ -51,6 +51,7 @@ from VirtualWatchdog import VirtualWatchdog
from VirtualFilesystem import VirtualFilesystem
from VirtualSmartCardDevice import VirtualSmartCardDevice
from VirtualRedirDevice import VirtualRedirDevice
+from VirtualMemballoon import VirtualMemballoon
from FullVirtGuest import FullVirtGuest
from ParaVirtGuest import ParaVirtGuest
from DistroInstaller import DistroInstaller
@@ -82,4 +83,4 @@ __all__ = ["Guest", "XenGuest", "VirtualNetworkInterface",
"VirtualHostDevicePCI", "VirtualCharDevice", "VirtualInputDevice",
"VirtualController", "VirtualWatchdog",
"VirtualFilesystem", "VirtualSmartCardDevice",
- "VirtualHostDeviceUSBRedir"]
+ "VirtualHostDeviceUSBRedir", "VirtualMemballoon"]
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 9063df6..d846209 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1018,6 +1018,16 @@ def get_redirdev(guest, sc_opts):
if dev:
guest.add_device(dev)
+def get_memballoon(guest, sc_opts):
+ for sc in listify(sc_opts):
+ try:
+ dev = parse_memballoon(guest, sc)
+ except Exception, e:
+ fail(_("Error in memballoon device parameters: %s") % str(e))
+
+ if dev:
+ guest.add_device(dev)
+
#############################
# Common CLI option/group #
#############################
@@ -1113,6 +1123,9 @@ def add_device_options(devg):
devg.add_option("", "--redirdev", dest="redirdev", action="append",
help=_("Configure a guest redirection device. Ex:\n"
"--redirdev usb,type=tcp,server=192.168.1.1:4000"))
+ devg.add_option("", "--memballoon", dest="memballoon", action="append",
+ help=_("Configure a guest memballoon device. Ex:\n"
+ "--memballoon medel=virtio"))
def add_gfx_option(devg):
devg.add_option("", "--graphics", dest="graphics", action="append",
@@ -1831,6 +1844,27 @@ def parse_watchdog(guest, optstring, dev=None):
return dev
+########################
+# --memballoon parsing #
+########################
+
+def parse_memballoon(guest, optstring, dev=None):
+ if optstring is None:
+ return None
+
+ # Peel the mode off the front
+ opts = parse_optstr(optstring, remove_first="model")
+ model = get_opt_param(opts, "model")
+
+ if not dev:
+ dev = virtinst.VirtualMemballoon(model=model,
+ conn=guest.conn)
+
+ if opts:
+ raise ValueError(_("Unknown options %s") % opts.keys())
+
+ return dev
+
######################################################
# --serial, --parallel, --channel, --console parsing #
--
1.7.7.6
More information about the virt-tools-list
mailing list