Guest: Make API users opt in for default console/input devices
We don't need to maintain API back compat anymore
This commit is contained in:
parent
77c044932c
commit
524d1047b1
|
@ -188,6 +188,9 @@ def get_basic_paravirt_guest(installer=None):
|
||||||
instboot.initrd = "/boot/initrd"
|
instboot.initrd = "/boot/initrd"
|
||||||
|
|
||||||
g.installer._scratchdir = scratch
|
g.installer._scratchdir = scratch
|
||||||
|
g.add_default_input_device()
|
||||||
|
g.add_default_console_device()
|
||||||
|
|
||||||
return g
|
return g
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,6 +213,9 @@ def get_basic_fullyvirt_guest(typ="xen", installer=None):
|
||||||
g.installer.os_type = "hvm"
|
g.installer.os_type = "hvm"
|
||||||
|
|
||||||
g.installer._scratchdir = scratch
|
g.installer._scratchdir = scratch
|
||||||
|
g.add_default_input_device()
|
||||||
|
g.add_default_console_device()
|
||||||
|
|
||||||
return g
|
return g
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
<domain type="xen">
|
|
||||||
<name>TestGuest</name>
|
|
||||||
<uuid>12345678-1234-1234-1234-123456789012</uuid>
|
|
||||||
<memory>409600</memory>
|
|
||||||
<currentMemory>204800</currentMemory>
|
|
||||||
<vcpu>5</vcpu>
|
|
||||||
<os>
|
|
||||||
<type arch="i686">hvm</type>
|
|
||||||
<loader>/usr/lib/xen/boot/hvmloader</loader>
|
|
||||||
<boot dev="hd"/>
|
|
||||||
</os>
|
|
||||||
<features>
|
|
||||||
<acpi/><apic/>
|
|
||||||
</features>
|
|
||||||
<clock offset="utc"/>
|
|
||||||
<on_poweroff>destroy</on_poweroff>
|
|
||||||
<on_reboot>restart</on_reboot>
|
|
||||||
<on_crash>restart</on_crash>
|
|
||||||
<devices>
|
|
||||||
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
|
|
||||||
<disk type="file" device="disk">
|
|
||||||
<source file="/tmp/test.img"/>
|
|
||||||
<target dev="hda" bus="ide"/>
|
|
||||||
</disk>
|
|
||||||
<disk type="block" device="cdrom">
|
|
||||||
<target dev="hdc" bus="ide"/>
|
|
||||||
<readonly/>
|
|
||||||
</disk>
|
|
||||||
<graphics type="sdl" display=":3.4" xauth="/tmp/.Xauthority"/>
|
|
||||||
</devices>
|
|
||||||
</domain>
|
|
|
@ -70,6 +70,7 @@
|
||||||
<parallel type="unix">
|
<parallel type="unix">
|
||||||
<source mode="bind" path="/tmp/foobar"/>
|
<source mode="bind" path="/tmp/foobar"/>
|
||||||
</parallel>
|
</parallel>
|
||||||
|
<console type="pty"/>
|
||||||
<channel type="spicevmc">
|
<channel type="spicevmc">
|
||||||
<target type="virtio" name="com.redhat.spice.0"/>
|
<target type="virtio" name="com.redhat.spice.0"/>
|
||||||
</channel>
|
</channel>
|
||||||
|
|
|
@ -30,7 +30,6 @@ from virtinst import (VirtualChannelDevice, VirtualConsoleDevice,
|
||||||
from virtinst import VirtualVideoDevice
|
from virtinst import VirtualVideoDevice
|
||||||
from virtinst import VirtualController
|
from virtinst import VirtualController
|
||||||
from virtinst import VirtualWatchdog
|
from virtinst import VirtualWatchdog
|
||||||
from virtinst import VirtualInputDevice
|
|
||||||
from virtinst import VirtualMemballoon
|
from virtinst import VirtualMemballoon
|
||||||
|
|
||||||
from tests import utils
|
from tests import utils
|
||||||
|
@ -309,21 +308,6 @@ class TestXMLConfig(unittest.TestCase):
|
||||||
self._compare(g, "install-fullyvirt-livecd", False)
|
self._compare(g, "install-fullyvirt-livecd", False)
|
||||||
self._compare(g, "install-fullyvirt-livecd", False)
|
self._compare(g, "install-fullyvirt-livecd", False)
|
||||||
|
|
||||||
def testDefaultDeviceRemoval(self):
|
|
||||||
g = utils.get_basic_fullyvirt_guest()
|
|
||||||
g.add_device(utils.get_filedisk())
|
|
||||||
|
|
||||||
inp = VirtualInputDevice(g.conn)
|
|
||||||
cons = VirtualConsoleDevice(g.conn)
|
|
||||||
cons.type = "pty"
|
|
||||||
g.add_device(inp)
|
|
||||||
g.add_device(cons)
|
|
||||||
|
|
||||||
g.remove_device(inp)
|
|
||||||
g.remove_device(cons)
|
|
||||||
|
|
||||||
self._compare(g, "boot-default-device-removal", False)
|
|
||||||
|
|
||||||
def testOSDeviceDefaultChange(self):
|
def testOSDeviceDefaultChange(self):
|
||||||
"""
|
"""
|
||||||
Make sure device defaults are properly changed if we change OS
|
Make sure device defaults are properly changed if we change OS
|
||||||
|
@ -679,49 +663,48 @@ class TestXMLConfig(unittest.TestCase):
|
||||||
i = utils.make_pxe_installer()
|
i = utils.make_pxe_installer()
|
||||||
g = utils.get_basic_fullyvirt_guest(installer=i)
|
g = utils.get_basic_fullyvirt_guest(installer=i)
|
||||||
|
|
||||||
dev1 = VirtualSerialDevice(g.conn)
|
dev = VirtualSerialDevice(g.conn)
|
||||||
dev1.type = "null"
|
dev.type = "null"
|
||||||
dev2 = VirtualParallelDevice(g.conn)
|
g.add_device(dev)
|
||||||
dev2.type = "unix"
|
|
||||||
dev2.source_path = "/tmp/foobar"
|
|
||||||
dev3 = VirtualSerialDevice(g.conn)
|
|
||||||
dev3.type = "tcp"
|
|
||||||
dev3.protocol = "telnet"
|
|
||||||
dev3.source_host = "my.source.host"
|
|
||||||
dev3.source_port = "1234"
|
|
||||||
dev4 = VirtualParallelDevice(g.conn)
|
|
||||||
dev4.type = "udp"
|
|
||||||
dev4.bind_host = "my.bind.host"
|
|
||||||
dev4.bind_port = "1111"
|
|
||||||
dev4.source_host = "my.source.host"
|
|
||||||
dev4.source_port = "2222"
|
|
||||||
|
|
||||||
dev5 = VirtualChannelDevice(g.conn)
|
dev = VirtualParallelDevice(g.conn)
|
||||||
dev5.type = "pty"
|
dev.type = "unix"
|
||||||
dev5.target_type = dev5.CHANNEL_TARGET_VIRTIO
|
dev.source_path = "/tmp/foobar"
|
||||||
dev5.target_name = "foo.bar.frob"
|
g.add_device(dev)
|
||||||
|
|
||||||
dev6 = VirtualConsoleDevice(g.conn)
|
dev = VirtualSerialDevice(g.conn)
|
||||||
dev6.type = "pty"
|
dev.type = "tcp"
|
||||||
|
dev.protocol = "telnet"
|
||||||
|
dev.source_host = "my.source.host"
|
||||||
|
dev.source_port = "1234"
|
||||||
|
g.add_device(dev)
|
||||||
|
|
||||||
dev7 = VirtualConsoleDevice(g.conn)
|
dev = VirtualParallelDevice(g.conn)
|
||||||
dev7.type = "pty"
|
dev.type = "udp"
|
||||||
dev7.target_type = dev7.CONSOLE_TARGET_VIRTIO
|
dev.bind_host = "my.bind.host"
|
||||||
|
dev.bind_port = "1111"
|
||||||
|
dev.source_host = "my.source.host"
|
||||||
|
dev.source_port = "2222"
|
||||||
|
g.add_device(dev)
|
||||||
|
|
||||||
dev8 = VirtualChannelDevice(g.conn)
|
dev = VirtualChannelDevice(g.conn)
|
||||||
dev8.type = "pty"
|
dev.type = "pty"
|
||||||
dev8.target_type = dev8.CHANNEL_TARGET_GUESTFWD
|
dev.target_type = dev.CHANNEL_TARGET_VIRTIO
|
||||||
dev8.target_address = "1.2.3.4"
|
dev.target_name = "foo.bar.frob"
|
||||||
dev8.target_port = "4567"
|
g.add_device(dev)
|
||||||
|
|
||||||
|
dev = VirtualConsoleDevice(g.conn)
|
||||||
|
dev.type = "pty"
|
||||||
|
dev.target_type = dev.CONSOLE_TARGET_VIRTIO
|
||||||
|
g.add_device(dev)
|
||||||
|
|
||||||
|
dev = VirtualChannelDevice(g.conn)
|
||||||
|
dev.type = "pty"
|
||||||
|
dev.target_type = dev.CHANNEL_TARGET_GUESTFWD
|
||||||
|
dev.target_address = "1.2.3.4"
|
||||||
|
dev.target_port = "4567"
|
||||||
|
g.add_device(dev)
|
||||||
|
|
||||||
g.add_device(dev1)
|
|
||||||
g.add_device(dev2)
|
|
||||||
g.add_device(dev3)
|
|
||||||
g.add_device(dev4)
|
|
||||||
g.add_device(dev5)
|
|
||||||
g.add_device(dev6)
|
|
||||||
g.add_device(dev7)
|
|
||||||
g.add_device(dev8)
|
|
||||||
self._compare(g, "boot-many-chars", False)
|
self._compare(g, "boot-many-chars", False)
|
||||||
|
|
||||||
def testManyDevices(self):
|
def testManyDevices(self):
|
||||||
|
|
|
@ -178,6 +178,10 @@ def main(conn=None):
|
||||||
if options.noapic:
|
if options.noapic:
|
||||||
guest.features["apic"] = False
|
guest.features["apic"] = False
|
||||||
|
|
||||||
|
if not guest.get_devices("input"):
|
||||||
|
guest.add_default_input_device()
|
||||||
|
if not guest.get_devices("console") and not guest.get_devices("serial"):
|
||||||
|
guest.add_default_console_device()
|
||||||
|
|
||||||
# we've got everything -- try to start the install
|
# we've got everything -- try to start the install
|
||||||
if options.print_only:
|
if options.print_only:
|
||||||
|
|
|
@ -535,6 +535,10 @@ def build_guest_instance(conn, options):
|
||||||
cli.get_smartcard(guest, options.smartcard)
|
cli.get_smartcard(guest, options.smartcard)
|
||||||
cli.get_tpm(guest, options.tpm)
|
cli.get_tpm(guest, options.tpm)
|
||||||
|
|
||||||
|
if not guest.get_devices("input"):
|
||||||
|
guest.add_default_input_device()
|
||||||
|
if not guest.get_devices("console") and not guest.get_devices("serial"):
|
||||||
|
guest.add_default_console_device()
|
||||||
|
|
||||||
# Install options
|
# Install options
|
||||||
cli.set_os_variant(guest, options.distro_type, options.distro_variant)
|
cli.set_os_variant(guest, options.distro_type, options.distro_variant)
|
||||||
|
|
|
@ -1437,6 +1437,8 @@ class vmmCreate(vmmGObjectUI):
|
||||||
if dev:
|
if dev:
|
||||||
guest.add_device(dev)
|
guest.add_device(dev)
|
||||||
|
|
||||||
|
guest.add_default_input_device()
|
||||||
|
guest.add_default_console_device()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.err.show_err(_("Error setting up default devices:") + str(e))
|
self.err.show_err(_("Error setting up default devices:") + str(e))
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -51,8 +51,6 @@ class Guest(XMLBuilder):
|
||||||
_DEFAULTS = osdict.DEFAULTS
|
_DEFAULTS = osdict.DEFAULTS
|
||||||
_OS_TYPES = osdict.OS_TYPES
|
_OS_TYPES = osdict.OS_TYPES
|
||||||
|
|
||||||
_default_os_type = None
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pretty_os_list():
|
def pretty_os_list():
|
||||||
"""
|
"""
|
||||||
|
@ -164,8 +162,7 @@ class Guest(XMLBuilder):
|
||||||
|
|
||||||
return cpustr
|
return cpustr
|
||||||
|
|
||||||
def __init__(self, conn, type=None,
|
def __init__(self, conn, type=None, installer=None, parsexml=None):
|
||||||
installer=None, parsexml=None):
|
|
||||||
# pylint: disable=W0622
|
# pylint: disable=W0622
|
||||||
# Redefining built-in 'type', but it matches the XML so keep it
|
# Redefining built-in 'type', but it matches the XML so keep it
|
||||||
|
|
||||||
|
@ -201,29 +198,12 @@ class Guest(XMLBuilder):
|
||||||
self.domain = None
|
self.domain = None
|
||||||
self._consolechild = None
|
self._consolechild = None
|
||||||
|
|
||||||
self._default_input_device = None
|
|
||||||
self._default_console_device = None
|
|
||||||
|
|
||||||
XMLBuilder.__init__(self, conn, parsexml)
|
XMLBuilder.__init__(self, conn, parsexml)
|
||||||
if self._is_parse():
|
if self._is_parse():
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.installer:
|
if not self.installer:
|
||||||
i = virtinst.DistroInstaller(conn,
|
self.installer = virtinst.DistroInstaller(conn, type)
|
||||||
type=type,
|
|
||||||
os_type=self._default_os_type)
|
|
||||||
self.installer = i
|
|
||||||
|
|
||||||
# Add default devices (if applicable)
|
|
||||||
inp = self._get_default_input_device()
|
|
||||||
if inp:
|
|
||||||
self.add_device(inp)
|
|
||||||
self._default_input_device = inp
|
|
||||||
|
|
||||||
con = self._get_default_console_device()
|
|
||||||
con.virtinst_default = True
|
|
||||||
self.add_device(con)
|
|
||||||
self._default_console_device = con
|
|
||||||
|
|
||||||
# Need to do this after all parameter init
|
# Need to do this after all parameter init
|
||||||
self._features = DomainFeatures(self.conn)
|
self._features = DomainFeatures(self.conn)
|
||||||
|
@ -535,34 +515,16 @@ class Guest(XMLBuilder):
|
||||||
dev.set_xml_node(node)
|
dev.set_xml_node(node)
|
||||||
self._add_child_node("./devices", node)
|
self._add_child_node("./devices", node)
|
||||||
|
|
||||||
self._add_device(dev)
|
self._track_device(dev)
|
||||||
if set_defaults:
|
if set_defaults:
|
||||||
def list_one_dev(devtype):
|
def list_one_dev(devtype):
|
||||||
if dev.virtual_device_type == devtype:
|
if dev.virtual_device_type == devtype:
|
||||||
return [dev][:]
|
return [dev][:]
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
self._set_defaults(list_one_dev, None, self.features)
|
self._set_defaults(list_one_dev, self.features)
|
||||||
|
|
||||||
def _add_device(self, dev):
|
def _track_device(self, dev):
|
||||||
devtype = dev.virtual_device_type
|
|
||||||
|
|
||||||
# If user adds a device conflicting with a default assigned device
|
|
||||||
# remove the default
|
|
||||||
if (devtype == VirtualDevice.VIRTUAL_DEV_INPUT and
|
|
||||||
self._default_input_device):
|
|
||||||
if self._default_input_device in self.get_all_devices():
|
|
||||||
self.remove_device(self._default_input_device)
|
|
||||||
self._default_input_device = None
|
|
||||||
|
|
||||||
if (devtype in [VirtualDevice.VIRTUAL_DEV_CONSOLE,
|
|
||||||
VirtualDevice.VIRTUAL_DEV_SERIAL] and
|
|
||||||
self._default_console_device):
|
|
||||||
if self._default_console_device in self.get_all_devices():
|
|
||||||
self.remove_device(self._default_console_device)
|
|
||||||
self._default_console_device = None
|
|
||||||
|
|
||||||
# Actually add the device
|
|
||||||
self._devices.append(dev)
|
self._devices.append(dev)
|
||||||
|
|
||||||
|
|
||||||
|
@ -653,7 +615,7 @@ class Guest(XMLBuilder):
|
||||||
objclass = device_mappings.get(devnode.name)
|
objclass = device_mappings.get(devnode.name)
|
||||||
|
|
||||||
dev = objclass(self.conn, parsexmlnode=devnode)
|
dev = objclass(self.conn, parsexmlnode=devnode)
|
||||||
self._add_device(dev)
|
self._track_device(dev)
|
||||||
|
|
||||||
self._xml_node.virtinst_root_doc = self._xml_root_doc
|
self._xml_node.virtinst_root_doc = self._xml_root_doc
|
||||||
self._installer = virtinst.Installer.Installer(self.conn,
|
self._installer = virtinst.Installer.Installer(self.conn,
|
||||||
|
@ -666,19 +628,17 @@ class Guest(XMLBuilder):
|
||||||
self._numatune = DomainNumatune(self.conn,
|
self._numatune = DomainNumatune(self.conn,
|
||||||
parsexmlnode=self._xml_node)
|
parsexmlnode=self._xml_node)
|
||||||
|
|
||||||
def _get_default_input_device(self):
|
def add_default_input_device(self):
|
||||||
"""
|
if self.installer.is_container():
|
||||||
Return a VirtualInputDevice.
|
return
|
||||||
"""
|
self.add_device(VirtualInputDevice(self.conn))
|
||||||
if self.installer and self.installer.is_container():
|
|
||||||
return None
|
|
||||||
dev = VirtualInputDevice(self.conn)
|
|
||||||
return dev
|
|
||||||
|
|
||||||
def _get_default_console_device(self):
|
def add_default_console_device(self):
|
||||||
|
if self.installer.is_xenpv():
|
||||||
|
return
|
||||||
dev = virtinst.VirtualConsoleDevice(self.conn)
|
dev = virtinst.VirtualConsoleDevice(self.conn)
|
||||||
dev.type = dev.TYPE_PTY
|
dev.type = dev.TYPE_PTY
|
||||||
return dev
|
self.add_device(dev)
|
||||||
|
|
||||||
def _get_device_xml(self, devs, install=True):
|
def _get_device_xml(self, devs, install=True):
|
||||||
|
|
||||||
|
@ -872,12 +832,9 @@ class Guest(XMLBuilder):
|
||||||
|
|
||||||
def get_transient_devices(devtype):
|
def get_transient_devices(devtype):
|
||||||
return self._dev_build_list(devtype, devs)
|
return self._dev_build_list(devtype, devs)
|
||||||
def remove_transient_device(device):
|
|
||||||
devs.remove(device)
|
|
||||||
|
|
||||||
# Set device defaults so we can validly generate XML
|
# Set device defaults so we can validly generate XML
|
||||||
self._set_defaults(get_transient_devices,
|
self._set_defaults(get_transient_devices,
|
||||||
remove_transient_device,
|
|
||||||
tmpfeat)
|
tmpfeat)
|
||||||
|
|
||||||
if install:
|
if install:
|
||||||
|
@ -1234,8 +1191,7 @@ class Guest(XMLBuilder):
|
||||||
The install process will call a non-persistent version, so calling
|
The install process will call a non-persistent version, so calling
|
||||||
this manually isn't required.
|
this manually isn't required.
|
||||||
"""
|
"""
|
||||||
self._set_defaults(self.get_devices, self.remove_device,
|
self._set_defaults(self.get_devices, self.features)
|
||||||
self.features)
|
|
||||||
|
|
||||||
def _set_hvm_defaults(self, devlist_func, features):
|
def _set_hvm_defaults(self, devlist_func, features):
|
||||||
disktype = VirtualDevice.VIRTUAL_DEV_DISK
|
disktype = VirtualDevice.VIRTUAL_DEV_DISK
|
||||||
|
@ -1267,7 +1223,7 @@ class Guest(XMLBuilder):
|
||||||
self.conn.caps.host.arch == "ppc64"):
|
self.conn.caps.host.arch == "ppc64"):
|
||||||
self.installer.machine = "pseries"
|
self.installer.machine = "pseries"
|
||||||
|
|
||||||
def _set_pv_defaults(self, devlist_func, remove_func):
|
def _set_pv_defaults(self, devlist_func):
|
||||||
# Default file backed PV guests to tap driver
|
# Default file backed PV guests to tap driver
|
||||||
for d in devlist_func(VirtualDevice.VIRTUAL_DEV_DISK):
|
for d in devlist_func(VirtualDevice.VIRTUAL_DEV_DISK):
|
||||||
if (d.type == VirtualDisk.TYPE_FILE
|
if (d.type == VirtualDisk.TYPE_FILE
|
||||||
|
@ -1281,10 +1237,6 @@ class Guest(XMLBuilder):
|
||||||
if d.bus == d.BUS_DEFAULT:
|
if d.bus == d.BUS_DEFAULT:
|
||||||
d.bus = d.BUS_XEN
|
d.bus = d.BUS_XEN
|
||||||
|
|
||||||
for d in devlist_func(VirtualDevice.VIRTUAL_DEV_CONSOLE):
|
|
||||||
if hasattr(d, "virtinst_default"):
|
|
||||||
remove_func(d)
|
|
||||||
|
|
||||||
def add_usb_ich9_controllers(self):
|
def add_usb_ich9_controllers(self):
|
||||||
ctrl = VirtualController(self.conn)
|
ctrl = VirtualController(self.conn)
|
||||||
ctrl.type = "usb"
|
ctrl.type = "usb"
|
||||||
|
@ -1309,14 +1261,14 @@ class Guest(XMLBuilder):
|
||||||
ctrl.master_startport = 4
|
ctrl.master_startport = 4
|
||||||
self.add_device(ctrl)
|
self.add_device(ctrl)
|
||||||
|
|
||||||
def _set_defaults(self, devlist_func, remove_func, features):
|
def _set_defaults(self, devlist_func, features):
|
||||||
for dev in devlist_func("all"):
|
for dev in devlist_func("all"):
|
||||||
dev.set_defaults()
|
dev.set_defaults()
|
||||||
|
|
||||||
if self.installer.is_hvm():
|
if self.installer.is_hvm():
|
||||||
self._set_hvm_defaults(devlist_func, features)
|
self._set_hvm_defaults(devlist_func, features)
|
||||||
if self.installer.is_xenpv():
|
if self.installer.is_xenpv():
|
||||||
self._set_pv_defaults(devlist_func, remove_func)
|
self._set_pv_defaults(devlist_func)
|
||||||
|
|
||||||
soundtype = VirtualDevice.VIRTUAL_DEV_AUDIO
|
soundtype = VirtualDevice.VIRTUAL_DEV_AUDIO
|
||||||
videotype = VirtualDevice.VIRTUAL_DEV_VIDEO
|
videotype = VirtualDevice.VIRTUAL_DEV_VIDEO
|
||||||
|
|
Loading…
Reference in New Issue