Use vmmFSDetails in details dialog to allow editing filesystem devices

This commit is contained in:
Cédric Bosdonnat 2014-01-21 10:05:31 +01:00 committed by Cole Robinson
parent 40422e13f2
commit d2f625cb22
5 changed files with 86 additions and 233 deletions

View File

@ -6048,223 +6048,13 @@
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment45">
<object class="GtkAlignment" id="fs-alignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">3</property>
<property name="left_padding">12</property>
<child>
<object class="GtkTable" id="table12">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkLabel" id="fs-mode-title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Mode:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label64">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Driver:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-wrpolicy-title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Write Policy:</property>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label65">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Source:</property>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label66">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Target:</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="GtkLabel" id="fs-readonly-title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Readonly Filesystem:</property>
</object>
<packing>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-mode">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">label</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-driver">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">label</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-wrpolicy">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">label</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-source">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">label</property>
<property name="ellipsize">end</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-target">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">label</property>
<property name="ellipsize">end</property>
</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="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-readonly">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label">label</property>
<property name="ellipsize">end</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label67">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Type:</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="fs-type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
<placeholder/>
</child>
</object>
</child>

View File

@ -56,6 +56,7 @@
<object class="GtkComboBox" id="fs-mode-combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_fs_mode_combo_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@ -129,6 +130,7 @@
<object class="GtkComboBox" id="fs-wrpolicy-combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_fs_wrpolicy_combo_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@ -162,6 +164,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<signal name="changed" handler="on_fs_target_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
@ -179,6 +182,7 @@
<property name="use_underline">True</property>
<property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_fs_readonly_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
@ -197,6 +201,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<signal name="changed" handler="on_fs_source_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
@ -366,6 +371,7 @@
<property name="xalign">1</property>
<property name="adjustment">adjustment6</property>
<property name="climb_rate">1</property>
<signal name="changed" handler="on_fs_ram_source_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@ -417,6 +423,7 @@
<object class="GtkComboBox" id="fs-format-combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_fs_format_combo_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>

View File

@ -36,6 +36,7 @@ from virtManager.addhardware import vmmAddHardware
from virtManager.choosecd import vmmChooseCD
from virtManager.snapshots import vmmSnapshotPage
from virtManager.graphwidgets import Sparkline
from virtManager.fsdetails import vmmFSDetails
from virtinst import VirtualRNGDevice
import virtinst
@ -96,7 +97,9 @@ EDIT_WATCHDOG_ACTION,
EDIT_CONTROLLER_MODEL,
EDIT_TPM_TYPE,
) = range(1, 42)
EDIT_FS,
) = range(1, 43)
# Columns in hw list model
@ -551,6 +554,13 @@ class vmmDetails(vmmGObjectUI):
self.vm.connect("config-changed", self.refresh_vm_state)
self.vm.connect("resources-sampled", self.refresh_resources)
self.fsDetails = vmmFSDetails(self.vm)
self.fsDetails.set_initial_state()
fsAlignment = self.widget("fs-alignment")
fsAlignment.add(self.fsDetails.topwin)
self.fsDetails.connect("changed", lambda *x: self.enable_apply(x,
EDIT_FS))
self.populate_hw_list()
self.repopulate_boot_list()
@ -582,6 +592,8 @@ class vmmDetails(vmmGObjectUI):
self.conn = None
self.addhwmenu = None
self.fsDetails.cleanup()
def show(self):
logging.debug("Showing VM details: %s", self.vm)
vis = self.is_visible()
@ -589,6 +601,8 @@ class vmmDetails(vmmGObjectUI):
if vis:
return
self.fsDetails.topwin.show_all()
self.emit("details-opened")
self.refresh_vm_state()
@ -1917,6 +1931,8 @@ class vmmDetails(vmmGObjectUI):
ret = self.config_smartcard_apply(key)
elif pagetype is HW_LIST_TYPE_CONTROLLER:
ret = self.config_controller_apply(key)
elif pagetype is HW_LIST_TYPE_FILESYSTEM:
ret = self.config_filesystem_apply(key)
else:
ret = False
except Exception, e:
@ -2346,6 +2362,18 @@ class vmmDetails(vmmGObjectUI):
return self._change_config_helper(df, da, hf, ha)
# Filesystem options
def config_filesystem_apply(self, dev_id_info):
df, da, add_define, hf, ha, add_hotplug = self.make_apply_data()
ignore = add_hotplug
if self.edited(EDIT_FS):
self.fsDetails.validate_page_filesystem()
add_define(self.vm.define_filesystem, dev_id_info,
self.fsDetails.get_dev())
return self._change_config_helper(df, da, hf, ha)
# Device removal
def remove_device(self, dev_type, dev_id_info):
logging.debug("Removing device: %s %s", dev_type, dev_id_info)
@ -3324,26 +3352,8 @@ class vmmDetails(vmmGObjectUI):
if not dev:
return
self.widget("fs-type").set_text(dev.type)
# mode can be irrelevant depending on the fs driver type
# selected.
if dev.mode:
self.show_pair("fs-mode", True)
self.widget("fs-mode").set_text(dev.mode)
else:
self.show_pair("fs-mode", False)
self.widget("fs-driver").set_text(dev.driver or _("Default"))
self.widget("fs-wrpolicy").set_text(dev.wrpolicy or _("Default"))
self.widget("fs-source").set_text(dev.source or _("RAM"))
self.widget("fs-target").set_text(dev.target)
if dev.readonly:
self.widget("fs-readonly").set_text("Yes")
else:
self.widget("fs-readonly").set_text("No")
self.fsDetails.set_dev(dev)
self.fsDetails.update_fs_rows()
def refresh_boot_page(self):
# Refresh autostart

View File

@ -845,6 +845,19 @@ class vmmDomain(vmmLibvirtObject):
return self._redefine_device(change, devobj)
def define_filesystem(self, devobj, newdev):
def change(editdev):
editdev.type = newdev.type
editdev.mode = newdev.mode
editdev.wrpolicy = newdev.wrpolicy
editdev.driver = newdev.driver
editdev.format = newdev.format
editdev.readonly = newdev.readonly
editdev.units = newdev.units
editdev.source = newdev.source
editdev.target = newdev.target
return self._redefine_device(change, devobj)
####################

View File

@ -21,6 +21,7 @@
# pylint: disable=E0611
from gi.repository import Gtk
from gi.repository import GObject
# pylint: enable=E0611
from virtinst import VirtualFilesystem
@ -30,6 +31,10 @@ from virtManager.storagebrowse import vmmStorageBrowser
class vmmFSDetails(vmmGObjectUI):
__gsignals__ = {
"changed": (GObject.SignalFlags.RUN_FIRST, None, [])
}
def __init__(self, vm):
vmmGObjectUI.__init__(self, "fsdetails.ui", "vmm-fs-details")
@ -45,6 +50,13 @@ class vmmFSDetails(vmmGObjectUI):
"on_fs_driver_combo_changed": self.change_field,
"on_fs_source_browse_clicked": self.browse_fs_source,
"on_fs_ram_units_combo_changed": self.change_ram_units,
"on_fs_mode_combo_changed": self.notify_change,
"on_fs_wrpolicy_combo_changed": self.notify_change,
"on_fs_readonly_toggled": self.notify_change,
"on_fs_format_combo_changed": self.notify_change,
"on_fs_source_changed": self.notify_change,
"on_fs_ram_source_changed": self.notify_change,
"on_fs_target_changed": self.notify_change,
})
def _cleanup(self):
@ -192,6 +204,23 @@ class vmmFSDetails(vmmGObjectUI):
return combo.get_model()[combo.get_active()][1]
# Setters
def set_dev(self, dev):
self._dev = dev
self.set_config_value("fs-type", dev.type or "default")
self.set_config_value("fs-mode", dev.mode or "default")
self.set_config_value("fs-driver", dev.driver or "default")
self.set_config_value("fs-wrpolicy", dev.wrpolicy or "default")
self.set_config_value("fs-format", dev.format or "default")
if dev.type != VirtualFilesystem.TYPE_RAM:
self.widget("fs-source").set_text(dev.source)
else:
self.set_config_ram_usage(dev.source, dev.units)
self.widget("fs-target").set_text(dev.target or "")
self.widget("fs-readonly").set_active(dev.readonly)
self.show_pair_combo("fs-type", self.conn.is_openvz() or self.conn.is_lxc())
def set_config_ram_usage(self, usage, units):
value = int(usage)
@ -222,6 +251,9 @@ class vmmFSDetails(vmmGObjectUI):
label.set_text(value)
# listeners
def notify_change(self, ignore):
self.emit("changed")
def browse_fs_source(self, ignore1):
self._browse_file(self.widget("fs-source"), isdir=True)
@ -270,6 +302,7 @@ class vmmFSDetails(vmmGObjectUI):
def change_field(self, src):
self.update_fs_rows()
self.notify_change(src)
def change_ram_units(self, ignore):
units = self.get_config_fs_units()