prefs: Add 'Add SPICE USB redirection' option, enable it

For qemu guests that are using spice, add 4 redirdevs so USB redirection
happens for free. This can be disabled in the preferences dialog.
This commit is contained in:
Cole Robinson 2014-02-04 15:12:23 -05:00
parent 2cf1901286
commit 8618a3abd7
6 changed files with 92 additions and 8 deletions

View File

@ -214,6 +214,12 @@
<description>Install selected graphics type for new VM. vnc or spice, system for software configured default</description>
</key>
<key name="add-spice-usbredir" type="s">
<default>'system'</default>
<summary>Add spice usbredir HW for new VMs</summary>
<description>Add spice usbredir HW for new VMs. yes, no, or system for software configured default</description>
</key>
<key name="storage-format" type="s">
<default>'default'</default>
<summary>Use selected format for new VM storage</summary>

View File

@ -336,7 +336,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -363,7 +363,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -415,7 +415,7 @@ identical CPUs in order to migrate the VM.</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -428,7 +428,36 @@ identical CPUs in order to migrate the VM.</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label27">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Add Spice USB
Redirection:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="prefs-add-spice-usbredir">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<signal name="changed" handler="on_prefs_add_spice_usbredir_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>

View File

@ -167,6 +167,7 @@ class vmmConfig(object):
self.default_storage_format_from_config = "qcow2"
self.cpu_default_from_config = "host-cpu-model"
self.default_console_resizeguest = 0
self.default_add_spice_usbredir = "yes"
self._objects = []
@ -432,6 +433,18 @@ class vmmConfig(object):
def set_graphics_type(self, gtype):
self.conf.set("/new-vm/graphics-type", gtype.lower())
def get_add_spice_usbredir(self, raw=False):
ret = self.conf.get("/new-vm/add-spice-usbredir")
if ret not in ["system", "yes", "no"]:
ret = "system"
if not raw and not self.get_graphics_type() == "spice":
return "no"
if ret == "system" and not raw:
return self.default_add_spice_usbredir
return ret
def set_add_spice_usbredir(self, val):
self.conf.set("/new-vm/add-spice-usbredir", val)
def get_default_storage_format(self, raw=False):
ret = self.conf.get("/new-vm/storage-format")
if ret not in ["default", "raw", "qcow2"]:

View File

@ -1393,6 +1393,15 @@ class vmmCreate(vmmGObjectUI):
if self.config.get_new_vm_sound():
guest.add_default_sound_device()
if (gdev and
self.config.get_add_spice_usbredir() == "yes" and
self.conn.check_support(self.conn.SUPPORT_CONN_USBREDIR)):
for ignore in range(4):
dev = virtinst.VirtualRedirDevice(guest.conn)
dev.bus = "usb"
dev.type = "spicevmc"
guest.add_device(dev)
if (((guest.conn.is_qemu() and guest.type == "kvm") or
guest.conn.is_test()) and
guest.os.is_x86() and

View File

@ -42,6 +42,7 @@ class vmmPreferences(vmmGObjectUI):
self.refresh_console_resizeguest()
self.refresh_new_vm_sound()
self.refresh_graphics_type()
self.refresh_add_spice_usbredir()
self.refresh_storage_format()
self.refresh_cpu_default()
self.refresh_disk_poll()
@ -57,15 +58,17 @@ class vmmPreferences(vmmGObjectUI):
self.refresh_confirm_delstorage()
self.builder.connect_signals({
"on_vmm_preferences_delete_event": self.close,
"on_prefs_close_clicked": self.close,
"on_prefs_system_tray_toggled" : self.change_view_system_tray,
"on_prefs_stats_update_interval_changed": self.change_update_interval,
"on_prefs_console_accels_toggled": self.change_console_accels,
"on_prefs_console_scaling_changed": self.change_console_scaling,
"on_prefs_console_resizeguest_changed": self.change_console_resizeguest,
"on_prefs_close_clicked": self.close,
"on_vmm_preferences_delete_event": self.close,
"on_prefs_new_vm_sound_toggled": self.change_new_vm_sound,
"on_prefs_graphics_type_changed": self.change_graphics_type,
"on_prefs_add_spice_usbredir_changed": self.change_add_spice_usbredir,
"on_prefs_storage_format_changed": self.change_storage_format,
"on_prefs_cpu_default_changed": self.change_cpu_default,
"on_prefs_stats_enable_disk_toggled": self.change_disk_poll,
@ -80,6 +83,9 @@ class vmmPreferences(vmmGObjectUI):
"on_prefs_confirm_delstorage_toggled": self.change_confirm_delstorage,
"on_prefs_btn_keys_define_clicked": self.change_grab_keys,
})
self.widget("prefs-graphics-type").emit("changed")
self.bind_escape_key_close()
def close(self, ignore1=None, ignore2=None):
@ -130,6 +136,16 @@ class vmmPreferences(vmmGObjectUI):
combo.set_model(model)
uiutil.set_combo_text_column(combo, 1)
combo = self.widget("prefs-add-spice-usbredir")
# [gsettings value, string]
model = Gtk.ListStore(str, str)
for row in [["system", _("System default (%s)") %
self.config.default_add_spice_usbredir],
["yes", "Yes"], ["Yes", "no"]]:
model.append(row)
combo.set_model(model)
uiutil.set_combo_text_column(combo, 1)
combo = self.widget("prefs-storage-format")
# [gsettings value, string]
model = Gtk.ListStore(str, str)
@ -185,6 +201,10 @@ class vmmPreferences(vmmGObjectUI):
combo = self.widget("prefs-graphics-type")
gtype = self.config.get_graphics_type(raw=True)
uiutil.set_row_selection(combo, gtype)
def refresh_add_spice_usbredir(self):
combo = self.widget("prefs-add-spice-usbredir")
val = self.config.get_add_spice_usbredir(raw=True)
uiutil.set_row_selection(combo, val)
def refresh_storage_format(self):
combo = self.widget("prefs-storage-format")
val = self.config.get_default_storage_format(raw=True)
@ -321,8 +341,13 @@ class vmmPreferences(vmmGObjectUI):
def change_new_vm_sound(self, src):
self.config.set_new_vm_sound(src.get_active())
def change_graphics_type(self, src):
typ = uiutil.get_list_selection(src, 0) or "vnc"
self.config.set_graphics_type(typ.lower())
val = uiutil.get_list_selection(src, 0)
self.config.set_graphics_type(val)
uiutil.set_grid_row_visible(
self.widget("prefs-add-spice-usbredir"),
self.config.get_graphics_type() == "spice")
def change_add_spice_usbredir(self, src):
self.config.set_add_spice_usbredir(uiutil.get_list_selection(src, 0))
def change_storage_format(self, src):
typ = uiutil.get_list_selection(src, 0) or "default"
self.config.set_storage_format(typ.lower())

View File

@ -296,6 +296,8 @@ SUPPORT_CONN_PM_DISABLE = _make(version="10002",
drv_version=[("qemu", 1002000), ("test", 0)])
SUPPORT_CONN_QCOW2_LAZY_REFCOUNTS = _make(version="1001000",
drv_version=[("qemu", 1002000), ("test", 0)])
SUPPORT_CONN_USBREDIR = _make(version="9005",
drv_version=[("qemu", 1003000), ("test", 0)])
# Domain checks