[virt-tools-list] [PATCH 3/3] virtinst: allow adding host block devices to LXC containers

Lubomir Rintel lkundrak at v3.sk
Fri Jun 15 09:29:36 UTC 2018


Signed-off-by: Lubomir Rintel <lkundrak at v3.sk>
---
 man/virt-install.pod                       | 4 ++++
 tests/xmlparse-xml/change-hostdevs-in.xml  | 5 +++++
 tests/xmlparse-xml/change-hostdevs-out.xml | 5 +++++
 tests/xmlparse.py                          | 5 +++++
 virtinst/cli.py                            | 3 +++
 virtinst/devices/hostdev.py                | 3 +++
 6 files changed, 25 insertions(+)

diff --git a/man/virt-install.pod b/man/virt-install.pod
index a2630316d..657ef8cbf 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1230,6 +1230,10 @@ Network device (in LXC container).
 
 Character device (in LXC container).
 
+=item B<--hostdev /dev/sdf,type=storage>
+
+Block device (in LXC container).
+
 =back
 
 Use --hostdev=? to see a list of all available sub options. Complete details at L<https://libvirt.org/formatdomain.html#elementsHostDev>
diff --git a/tests/xmlparse-xml/change-hostdevs-in.xml b/tests/xmlparse-xml/change-hostdevs-in.xml
index c93253b42..ed173a6ad 100644
--- a/tests/xmlparse-xml/change-hostdevs-in.xml
+++ b/tests/xmlparse-xml/change-hostdevs-in.xml
@@ -53,5 +53,10 @@
         <char>/dev/net/tun</char>
       </source>
     </hostdev>
+    <hostdev mode="capabilities" type="storage" managed="yes">
+      <source>
+        <block>/dev/sdf</block>
+      </source>
+    </hostdev>
   </devices>
 </domain>
diff --git a/tests/xmlparse-xml/change-hostdevs-out.xml b/tests/xmlparse-xml/change-hostdevs-out.xml
index 12733851b..7c1fe64a4 100644
--- a/tests/xmlparse-xml/change-hostdevs-out.xml
+++ b/tests/xmlparse-xml/change-hostdevs-out.xml
@@ -56,5 +56,10 @@
         <char>/dev/null</char>
       </source>
     </hostdev>
+    <hostdev mode="capabilities" type="storage" managed="yes">
+      <source>
+        <block>/dev/fd0</block>
+      </source>
+    </hostdev>
   </devices>
 </domain>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index d99d86ec6..6bed133dc 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -697,6 +697,7 @@ class XMLParseTest(unittest.TestCase):
         dev4 = guest.devices.hostdev[3]
         dev5 = guest.devices.hostdev[4]
         dev6 = guest.devices.hostdev[5]
+        dev7 = guest.devices.hostdev[6]
 
         check = self._make_checker(dev1)
         check("type", "usb", "foo", "usb")
@@ -739,6 +740,10 @@ class XMLParseTest(unittest.TestCase):
         check = self._make_checker(dev6)
         check("type", "misc")
         check("misc_char", "/dev/net/tun", "/dev/null")
+
+        check = self._make_checker(dev7)
+        check("type", "storage")
+        check("storage_block", "/dev/sdf", "/dev/fd0")
         self._alter_compare(guest.get_xml_config(), outfile)
 
     def testAlterWatchdogs(self):
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 655a11501..c3464d60f 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -2785,6 +2785,9 @@ class ParserHostdev(VirtCLIParser):
         elif inst.type == "misc":
             inst.mode = "capabilities"
             inst.misc_char = val
+        elif inst.type == "storage":
+            inst.mode = "capabilities"
+            inst.storage_block = val
         else:
             val = NodeDevice.lookupNodedevFromString(inst.conn, val)
             inst.set_from_nodedev(val)
diff --git a/virtinst/devices/hostdev.py b/virtinst/devices/hostdev.py
index 5d0364cb4..4769b0a20 100644
--- a/virtinst/devices/hostdev.py
+++ b/virtinst/devices/hostdev.py
@@ -138,3 +138,6 @@ class DeviceHostdev(Device):
 
     # type=misc handling
     misc_char = XMLProperty("./source/char")
+
+    # type=misc handling
+    storage_block = XMLProperty("./source/block")
-- 
2.17.1




More information about the virt-tools-list mailing list