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

Lubomir Rintel lkundrak at v3.sk
Fri Jun 15 09:29:35 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 5692b3733..a2630316d 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1226,6 +1226,10 @@ PCI device (via lspci).
 
 Network device (in LXC container).
 
+=item B<--hostdev /dev/net/tun,type=misc>
+
+Character 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 c5ec1b596..c93253b42 100644
--- a/tests/xmlparse-xml/change-hostdevs-in.xml
+++ b/tests/xmlparse-xml/change-hostdevs-in.xml
@@ -48,5 +48,10 @@
         <interface>wlan0</interface>
       </source>
     </hostdev>
+    <hostdev mode="capabilities" type="misc" managed="yes">
+      <source>
+        <char>/dev/net/tun</char>
+      </source>
+    </hostdev>
   </devices>
 </domain>
diff --git a/tests/xmlparse-xml/change-hostdevs-out.xml b/tests/xmlparse-xml/change-hostdevs-out.xml
index 427e8d329..12733851b 100644
--- a/tests/xmlparse-xml/change-hostdevs-out.xml
+++ b/tests/xmlparse-xml/change-hostdevs-out.xml
@@ -51,5 +51,10 @@
         <interface>eth0</interface>
       </source>
     </hostdev>
+    <hostdev mode="capabilities" type="misc" managed="yes">
+      <source>
+        <char>/dev/null</char>
+      </source>
+    </hostdev>
   </devices>
 </domain>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 331277602..d99d86ec6 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -696,6 +696,7 @@ class XMLParseTest(unittest.TestCase):
         dev3 = guest.devices.hostdev[2]
         dev4 = guest.devices.hostdev[3]
         dev5 = guest.devices.hostdev[4]
+        dev6 = guest.devices.hostdev[5]
 
         check = self._make_checker(dev1)
         check("type", "usb", "foo", "usb")
@@ -734,6 +735,10 @@ class XMLParseTest(unittest.TestCase):
         check = self._make_checker(dev5)
         check("type", "net")
         check("net_interface", "wlan0", "eth0")
+
+        check = self._make_checker(dev6)
+        check("type", "misc")
+        check("misc_char", "/dev/net/tun", "/dev/null")
         self._alter_compare(guest.get_xml_config(), outfile)
 
     def testAlterWatchdogs(self):
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 4c419a0ea..655a11501 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -2782,6 +2782,9 @@ class ParserHostdev(VirtCLIParser):
         if inst.type == "net":
             inst.mode = "capabilities"
             inst.net_interface = val
+        elif inst.type == "misc":
+            inst.mode = "capabilities"
+            inst.misc_char = 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 dce86d542..5d0364cb4 100644
--- a/virtinst/devices/hostdev.py
+++ b/virtinst/devices/hostdev.py
@@ -135,3 +135,6 @@ class DeviceHostdev(Device):
 
     # type=net handling
     net_interface = XMLProperty("./source/interface")
+
+    # type=misc handling
+    misc_char = XMLProperty("./source/char")
-- 
2.17.1




More information about the virt-tools-list mailing list