[virt-tools-list] [PATCH v2] virt install: Add support for filesystem <driver> sub-element
Deepak C Shetty
deepakcs at linux.vnet.ibm.com
Mon Dec 26 04:47:50 UTC 2011
This patch adds support for the <driver...> sub-element
of <filesystem> node. driver is an optional sub-element
and has path and handle as the supported values as of
now. For more details refer to libvirt filesystem
doc page at ...
http://libvirt.org/formatdomain.html#elementsFilesystems
Signed-off-by: Deepak C Shetty <deepakcs at linux.vnet.ibm.com>
---
v2:
- added test cases
tests/xmlparse-xml/change-filesystems-in.xml | 2 ++
tests/xmlparse-xml/change-filesystems-out.xml | 1 +
tests/xmlparse.py | 2 ++
virtinst/VirtualFilesystem.py | 21 +++++++++++++++++++++
4 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/tests/xmlparse-xml/change-filesystems-in.xml b/tests/xmlparse-xml/change-filesystems-in.xml
index c1f1054..2f95068 100644
--- a/tests/xmlparse-xml/change-filesystems-in.xml
+++ b/tests/xmlparse-xml/change-filesystems-in.xml
@@ -24,6 +24,7 @@
<target dev="fda" bus="fdc"/>
</disk>
<filesystem>
+ <driver type='handle'/>
<source dir='/foo/bar'/>
<target dir='/bar/baz'/>
</filesystem>
@@ -32,6 +33,7 @@
<target dir='/bar/baz'/>
</filesystem>
<filesystem type='mount' accessmode='squash'>
+ <driver type='path'/>
<source dir='/foo/bar'/>
<target dir='/bar/baz'/>
</filesystem>
diff --git a/tests/xmlparse-xml/change-filesystems-out.xml b/tests/xmlparse-xml/change-filesystems-out.xml
index c29f064..75dde4c 100644
--- a/tests/xmlparse-xml/change-filesystems-out.xml
+++ b/tests/xmlparse-xml/change-filesystems-out.xml
@@ -32,6 +32,7 @@
<target dir="/bar/baz"/>
</filesystem>
<filesystem>
+ <driver type="handle"/>
<source dir="/foo/bar"/>
<target dir="/bar/baz"/>
</filesystem>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index a781f2c..3fc1839 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -580,6 +580,7 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(dev1)
check("type", None, "mount")
check("mode", None, "passthrough")
+ check("driver", "handle", None)
check("source", "/foo/bar", "/new/path")
check("target", "/bar/baz", "/new/target")
@@ -592,6 +593,7 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(dev3)
check("type", "mount", None)
check("mode", "squash", None)
+ check("driver", "path", "handle")
self._alter_compare(guest.get_config_xml(), outfile)
diff --git a/virtinst/VirtualFilesystem.py b/virtinst/VirtualFilesystem.py
index 0b8a876..56f2c1f 100644
--- a/virtinst/VirtualFilesystem.py
+++ b/virtinst/VirtualFilesystem.py
@@ -42,6 +42,11 @@ class VirtualFilesystem(VirtualDevice.VirtualDevice):
MODE_DEFAULT = "default"
MOUNT_MODES = [MODE_PASSTHROUGH, MODE_MAPPED, MODE_SQUASH, MODE_DEFAULT]
+ DRIVER_PATH = "path"
+ DRIVER_HANDLE = "handle"
+ DRIVER_DEFAULT = "default"
+ DRIVER_TYPES = [DRIVER_PATH, DRIVER_HANDLE, DRIVER_DEFAULT]
+
@staticmethod
def type_to_source_prop(fs_type):
"""
@@ -66,6 +71,7 @@ class VirtualFilesystem(VirtualDevice.VirtualDevice):
self._type = None
self._mode = None
+ self._driver = None
self._target = None
self._source = None
@@ -74,6 +80,7 @@ class VirtualFilesystem(VirtualDevice.VirtualDevice):
self.mode = self.MODE_DEFAULT
self.type = self.TYPE_DEFAULT
+ self.driver = self.DRIVER_DEFAULT
def _get_type(self):
return self._type
@@ -91,6 +98,14 @@ class VirtualFilesystem(VirtualDevice.VirtualDevice):
self._mode = val
mode = _xml_property(_get_mode, _set_mode, xpath="./@accessmode")
+ def _get_driver(self):
+ return self._driver
+ def _set_driver(self, val):
+ if val is not None and not self.DRIVER_TYPES.count(val):
+ raise ValueError(_("Unsupported filesystem driver '%s'" % val))
+ self._driver = val
+ driver = _xml_property(_get_driver, _set_driver, xpath="./driver/@type")
+
def _get_source(self):
return self._source
def _set_source(self, val):
@@ -135,6 +150,7 @@ class VirtualFilesystem(VirtualDevice.VirtualDevice):
def _get_xml_config(self):
mode = self.mode
ftype = self.type
+ driver = self.driver
source = self.source
target = self.target
@@ -142,6 +158,8 @@ class VirtualFilesystem(VirtualDevice.VirtualDevice):
mode = None
if ftype == self.TYPE_DEFAULT:
ftype = None
+ if driver == self.DRIVER_DEFAULT:
+ driver = None
if not source or not target:
raise ValueError(
@@ -154,6 +172,9 @@ class VirtualFilesystem(VirtualDevice.VirtualDevice):
fsxml += " accessmode='%s'" % mode
fsxml += ">\n"
+ if driver:
+ fsxml += " <driver type='%s'/>\n" % driver
+
fsxml += " <source %s='%s'/>\n" % (
self.type_to_source_prop(ftype),
source)
More information about the virt-tools-list
mailing list