[virt-tools-list] [PATCH 4/5] virt-manager: Add checkbox controlling disk 'removable' flag
Fred A. Kemp
anonym at riseup.net
Fri Oct 4 01:39:01 UTC 2013
From: "Fred A. Kemp" <anonym at riseup.net>
---
ui/details.ui | 36 +++++++++++++++++++++++++++++++++++-
virtManager/details.py | 20 +++++++++++++++++++-
virtManager/domain.py | 4 ++++
3 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/ui/details.ui b/ui/details.ui
index e2e4efc..f111683 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -3575,7 +3575,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">3</property>
- <property name="n_rows">5</property>
+ <property name="n_rows">6</property>
<property name="n_columns">2</property>
<property name="column_spacing">8</property>
<property name="row_spacing">4</property>
@@ -3612,6 +3612,22 @@
</packing>
</child>
<child>
+ <object class="GtkLabel" id="disk-removable-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Removab_le:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">disk-removable</property>
+ </object>
+ <packing>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkCheckButton" id="disk-readonly">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -3648,6 +3664,24 @@
</packing>
</child>
<child>
+ <object class="GtkCheckButton" id="disk-removable">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0.5</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_disk_removable_changed" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
diff --git a/virtManager/details.py b/virtManager/details.py
index 63107f2..8ed4514 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -66,6 +66,7 @@ EDIT_INIT,
EDIT_DISK_RO,
EDIT_DISK_SHARE,
+EDIT_DISK_REMOVABLE,
EDIT_DISK_CACHE,
EDIT_DISK_IO,
EDIT_DISK_BUS,
@@ -94,7 +95,7 @@ EDIT_WATCHDOG_ACTION,
EDIT_CONTROLLER_MODEL,
EDIT_TPM_TYPE,
-) = range(1, 41)
+) = range(1, 42)
# Columns in hw list model
@@ -475,6 +476,7 @@ class vmmDetails(vmmGObjectUI):
"on_disk_readonly_changed": lambda *x: self.enable_apply(x, EDIT_DISK_RO),
"on_disk_shareable_changed": lambda *x: self.enable_apply(x, EDIT_DISK_SHARE),
+ "on_disk_removable_changed": lambda *x: self.enable_apply(x, EDIT_DISK_REMOVABLE),
"on_disk_cache_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_CACHE),
"on_disk_io_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_IO),
"on_disk_bus_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_BUS),
@@ -2157,6 +2159,12 @@ class vmmDetails(vmmGObjectUI):
add_define(self.vm.define_disk_shareable,
dev_id_info, do_shareable)
+ if self.edited(EDIT_DISK_REMOVABLE):
+ do_removable = self.widget("disk-removable").get_active()
+ if not do_removable:
+ do_removable = None
+ add_define(self.vm.define_disk_removable, dev_id_info, do_removable)
+
if self.edited(EDIT_DISK_CACHE):
cache = self.get_combo_entry("disk-cache")
add_define(self.vm.define_disk_cache, dev_id_info, cache)
@@ -2766,6 +2774,7 @@ class vmmDetails(vmmGObjectUI):
ro = disk.read_only
share = disk.shareable
bus = disk.bus
+ removable = disk.removable
addr = disk.address.type
idx = disk.disk_bus_index
cache = disk.driver_cache
@@ -2797,6 +2806,12 @@ class vmmDetails(vmmGObjectUI):
is_cdrom = (devtype == virtinst.VirtualDisk.DEVICE_CDROM)
is_floppy = (devtype == virtinst.VirtualDisk.DEVICE_FLOPPY)
+ is_usb = (bus == "usb")
+
+ can_set_removable = (is_usb and (self.conn.is_qemu() or
+ self.conn.is_test_conn()))
+ if removable is None:
+ removable = False
if addr == "spapr-vio":
bus = "spapr-vscsi"
@@ -2809,6 +2824,9 @@ class vmmDetails(vmmGObjectUI):
self.widget("disk-readonly").set_active(ro)
self.widget("disk-readonly").set_sensitive(not is_cdrom)
self.widget("disk-shareable").set_active(share)
+ self.widget("disk-removable").set_active(removable)
+ uihelpers.set_table_row_visible(self.widget("disk-removable"),
+ can_set_removable)
self.widget("disk-size").set_text(size)
self.set_combo_entry("disk-cache", cache)
self.set_combo_entry("disk-io", io)
diff --git a/virtManager/domain.py b/virtManager/domain.py
index ae2efdd..9b07e67 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -646,6 +646,10 @@ class vmmDomain(vmmLibvirtObject):
def change(editdev):
editdev.shareable = do_shareable
return self._redefine_device(change, devobj)
+ def define_disk_removable(self, devobj, do_removable):
+ def change(editdev):
+ editdev.removable = do_removable
+ return self._redefine_device(change, devobj)
def define_disk_cache(self, devobj, new_cache):
def change(editdev):
editdev.driver_cache = new_cache or None
--
1.7.10.4
More information about the virt-tools-list
mailing list