virtinst: Add vsock device type

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@vmware.com>
This commit is contained in:
Slavomir Kaslev 2018-12-14 16:34:17 +02:00 committed by Cole Robinson
parent e103c5fa81
commit be1b5e6ebb
6 changed files with 59 additions and 1 deletions

View File

@ -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"/>

View File

@ -545,6 +545,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" \

View File

@ -717,6 +717,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):
@ -2640,6 +2644,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 #
######################################################

View File

@ -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

30
virtinst/devices/vsock.py Normal file
View File

@ -0,0 +1,30 @@
# Copyright (C) 2018 VMware, Inc.
#
# Copyright 2018
# Slavomir Kaslev <kaslevs@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)
##################
# 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

View File

@ -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 = []