[virt-tools-list] [PATCH v3 1/4] virtinst: Add vsock device type

Slavomir Kaslev kaslevs at vmware.com
Fri Dec 14 14:34:17 UTC 2018


VSOCK sockets allow communication between virtual machines and the host they are
running on.

This patch adds vsock device support along with clitest for the new properties.

Signed-off-by: Slavomir Kaslev <kaslevs at vmware.com>
---
 .../compare/virt-install-many-devices.xml     |  3 ++
 tests/clitest.py                              |  2 +
 virtinst/cli.py                               | 21 ++++++++++
 virtinst/devices/__init__.py                  |  1 +
 virtinst/devices/vsock.py                     | 42 +++++++++++++++++++
 virtinst/guest.py                             |  3 +-
 6 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 virtinst/devices/vsock.py

diff --git a/tests/cli-test-xml/compare/virt-install-many-devices.xml b/tests/cli-test-xml/compare/virt-install-many-devices.xml
index ebc347e8..b7386003 100644
--- a/tests/cli-test-xml/compare/virt-install-many-devices.xml
+++ b/tests/cli-test-xml/compare/virt-install-many-devices.xml
@@ -413,6 +413,9 @@
     <panic model="isa">
       <address iobase="507" type="isa"/>
     </panic>
+    <vsock model="virtio">
+      <cid address="17"/>
+    </vsock>
   </devices>
   <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
     <qemu:arg value="-display"/>
diff --git a/tests/clitest.py b/tests/clitest.py
index 824293e4..c2735c1f 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -527,6 +527,8 @@ c.add_compare(""" \
 \
 --panic iobase=507 \
 \
+--vsock cid=17 \
+\
 --qemu-commandline env=DISPLAY=:0.1 \
 --qemu-commandline="-display gtk,gl=on" \
 --qemu-commandline="-device vfio-pci,addr=05.0,sysfsdev=/sys/class/mdev_bus/0000:00:02.0/f321853c-c584-4a6b-b99a-3eee22a3919c" \
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 21467a4d..c4774c65 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -654,6 +654,10 @@ def add_device_options(devg, sound_back_compat=False):
     devg.add_argument("--memdev", action="append",
                     help=_("Configure a guest memory device. Ex:\n"
                            "--memdev dimm,target_size=1024"))
+    devg.add_argument("--vsock", action="append",
+                    help=_("Configure guest vsock sockets. Ex:\n"
+                           "--vsock auto_cid=yes\n"
+                           "--vsock cid=7"))
 
 
 def add_guest_xml_options(geng):
@@ -2577,6 +2581,23 @@ ParserPanic.add_arg(None, "model", cb=ParserPanic.set_model_cb,
 ParserPanic.add_arg("iobase", "iobase")
 
 
+###################
+# --vsock parsing #
+###################
+
+class ParserVsock(VirtCLIParser):
+    cli_arg_name = "vsock"
+    propname = "devices.vsock"
+    remove_first = "model"
+    stub_none = False
+
+_register_virt_parser(ParserVsock)
+_add_device_address_args(ParserVsock)
+ParserVsock.add_arg("model", "model")
+ParserVsock.add_arg("auto_cid", "auto_cid")
+ParserVsock.add_arg("cid", "cid")
+
+
 ######################################################
 # --serial, --parallel, --channel, --console parsing #
 ######################################################
diff --git a/virtinst/devices/__init__.py b/virtinst/devices/__init__.py
index 6da0766d..6120f5d0 100644
--- a/virtinst/devices/__init__.py
+++ b/virtinst/devices/__init__.py
@@ -22,6 +22,7 @@ from .redirdev import DeviceRedirdev
 from .rng import DeviceRng
 from .tpm import DeviceTpm
 from .video import DeviceVideo
+from .vsock import DeviceVsock
 from .watchdog import DeviceWatchdog
 
 
diff --git a/virtinst/devices/vsock.py b/virtinst/devices/vsock.py
new file mode 100644
index 00000000..27b0cc3d
--- /dev/null
+++ b/virtinst/devices/vsock.py
@@ -0,0 +1,42 @@
+# Copyright (C) 2018 VMware, Inc.
+#
+# Copyright 2018
+# Slavomir Kaslev <kaslevs at vmware.com>
+#
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+from .device import Device
+from ..xmlbuilder import XMLProperty
+
+
+class DeviceVsock(Device):
+    XML_NAME = "vsock"
+
+    model = XMLProperty("./@model")
+    auto_cid = XMLProperty("./cid/@auto", is_yesno=True)
+    cid = XMLProperty("./cid/@address", is_int=True)
+
+    MIN_GUEST_CID = 3
+
+
+    ##############
+    # Validation #
+    ##############
+
+    def validate(self):
+        if not self.auto_cid and (self.cid is None or
+                                  self.cid < self.MIN_GUEST_CID):
+            raise ValueError(_("guest CID {0} must be >= 3").format(self.cid))
+
+
+    ##################
+    # Default config #
+    ##################
+
+    def set_defaults(self, guest):
+        if not self.model:
+            self.model = "virtio"
+
+        if self.auto_cid is None and self.cid is None:
+            self.auto_cid = True
diff --git a/virtinst/guest.py b/virtinst/guest.py
index eeb40cb6..9acff3b9 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -29,7 +29,7 @@ class _DomainDevices(XMLBuilder):
             'smartcard', 'serial', 'parallel', 'console', 'channel',
             'input', 'tpm', 'graphics', 'sound', 'video', 'hostdev',
             'redirdev', 'watchdog', 'memballoon', 'rng', 'panic',
-            'memory']
+            'memory', 'vsock']
 
 
     disk = XMLChildProperty(DeviceDisk)
@@ -53,6 +53,7 @@ class _DomainDevices(XMLBuilder):
     rng = XMLChildProperty(DeviceRng)
     panic = XMLChildProperty(DevicePanic)
     memory = XMLChildProperty(DeviceMemory)
+    vsock = XMLChildProperty(DeviceVsock)
 
     def get_all(self):
         retlist = []
-- 
2.19.1




More information about the virt-tools-list mailing list