[virt-tools-list] [PATCH 1/3] virtinst: allow adding host network devices to LXC containers
Lubomir Rintel
lkundrak at v3.sk
Fri Jun 15 09:29:34 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 | 9 +++++++--
virtinst/devices/hostdev.py | 3 +++
6 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/man/virt-install.pod b/man/virt-install.pod
index c7b3bcf9b..5692b3733 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1222,6 +1222,10 @@ USB by vendor, product (via lsusb).
PCI device (via lspci).
+=item B<--hostdev wlan0,type=net>
+
+Network 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 76b8a3a6a..c5ec1b596 100644
--- a/tests/xmlparse-xml/change-hostdevs-in.xml
+++ b/tests/xmlparse-xml/change-hostdevs-in.xml
@@ -43,5 +43,10 @@
<address bus="0" target="0" unit="0"/>
</source>
</hostdev>
+ <hostdev mode="capabilities" type="net" managed="yes">
+ <source>
+ <interface>wlan0</interface>
+ </source>
+ </hostdev>
</devices>
</domain>
diff --git a/tests/xmlparse-xml/change-hostdevs-out.xml b/tests/xmlparse-xml/change-hostdevs-out.xml
index 660d0fc81..427e8d329 100644
--- a/tests/xmlparse-xml/change-hostdevs-out.xml
+++ b/tests/xmlparse-xml/change-hostdevs-out.xml
@@ -46,5 +46,10 @@
<address bus="1" target="2" unit="3"/>
</source>
</hostdev>
+ <hostdev mode="capabilities" type="net" managed="yes">
+ <source>
+ <interface>eth0</interface>
+ </source>
+ </hostdev>
</devices>
</domain>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 906577f88..331277602 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -695,6 +695,7 @@ class XMLParseTest(unittest.TestCase):
dev2 = guest.devices.hostdev[1]
dev3 = guest.devices.hostdev[2]
dev4 = guest.devices.hostdev[3]
+ dev5 = guest.devices.hostdev[4]
check = self._make_checker(dev1)
check("type", "usb", "foo", "usb")
@@ -729,6 +730,10 @@ class XMLParseTest(unittest.TestCase):
check("scsi_bus", 0, 1)
check("scsi_target", 0, 2)
check("scsi_unit", 0, 3)
+
+ check = self._make_checker(dev5)
+ check("type", "net")
+ check("net_interface", "wlan0", "eth0")
self._alter_compare(guest.get_xml_config(), outfile)
def testAlterWatchdogs(self):
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 200f88107..4c419a0ea 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -2779,8 +2779,12 @@ class ParserHostdev(VirtCLIParser):
remove_first = "name"
def set_name_cb(self, inst, val, virtarg):
- val = NodeDevice.lookupNodedevFromString(inst.conn, val)
- inst.set_from_nodedev(val)
+ if inst.type == "net":
+ inst.mode = "capabilities"
+ inst.net_interface = val
+ else:
+ val = NodeDevice.lookupNodedevFromString(inst.conn, val)
+ inst.set_from_nodedev(val)
def name_lookup_cb(self, inst, val, virtarg):
nodedev = NodeDevice.lookupNodedevFromString(inst.conn, val)
@@ -2788,6 +2792,7 @@ class ParserHostdev(VirtCLIParser):
_register_virt_parser(ParserHostdev)
_add_device_address_args(ParserHostdev)
+ParserHostdev.add_arg("type", "type")
ParserHostdev.add_arg(None, "name",
cb=ParserHostdev.set_name_cb,
lookup_cb=ParserHostdev.name_lookup_cb)
diff --git a/virtinst/devices/hostdev.py b/virtinst/devices/hostdev.py
index 9dee3111f..dce86d542 100644
--- a/virtinst/devices/hostdev.py
+++ b/virtinst/devices/hostdev.py
@@ -132,3 +132,6 @@ class DeviceHostdev(Device):
scsi_bus = XMLProperty("./source/address/@bus", is_int=True)
scsi_target = XMLProperty("./source/address/@target", is_int=True)
scsi_unit = XMLProperty("./source/address/@unit", is_int=True)
+
+ # type=net handling
+ net_interface = XMLProperty("./source/interface")
--
2.17.1
More information about the virt-tools-list
mailing list