mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-10 01:18:03 +03:00
devices: filesystem: Add set_defaults
Requires a bit of rework in virt-manager handling, which had lots of explicit "default" handling
This commit is contained in:
parent
ef83565e48
commit
6215f790f5
@ -71,17 +71,20 @@ class vmmFSDetails(vmmGObjectUI):
|
||||
def set_initial_state(self):
|
||||
def simple_store_set(comboname, values, sort=True, capitalize=True):
|
||||
combo = self.widget(comboname)
|
||||
# [XML value, label]
|
||||
model = Gtk.ListStore(str, str)
|
||||
combo.set_model(model)
|
||||
uiutil.init_combo_text_column(combo, 1)
|
||||
if sort:
|
||||
model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
|
||||
if capitalize:
|
||||
for val in values:
|
||||
model.append([val, val.capitalize()])
|
||||
else:
|
||||
for val in values:
|
||||
model.append([val.lower(), val])
|
||||
|
||||
for xmlval in values:
|
||||
label = xmlval
|
||||
if xmlval is None:
|
||||
label = "Default"
|
||||
if capitalize:
|
||||
label = label.capitalize()
|
||||
model.append([xmlval, label])
|
||||
|
||||
# Filesystem widgets
|
||||
if self.conn.is_openvz():
|
||||
@ -98,23 +101,23 @@ class vmmFSDetails(vmmGObjectUI):
|
||||
simple_store_set("fs-type-combo", [DeviceFilesystem.TYPE_MOUNT])
|
||||
self.widget("fs-type-label").set_text(DeviceFilesystem.TYPE_MOUNT)
|
||||
|
||||
simple_store_set("fs-mode-combo", DeviceFilesystem.MODES)
|
||||
simple_store_set("fs-mode-combo", DeviceFilesystem.MODES + [None])
|
||||
if self.conn.is_qemu() or self.conn.is_test():
|
||||
simple_store_set("fs-driver-combo",
|
||||
[DeviceFilesystem.DRIVER_PATH,
|
||||
DeviceFilesystem.DRIVER_HANDLE,
|
||||
DeviceFilesystem.DRIVER_DEFAULT])
|
||||
None])
|
||||
elif self.conn.is_lxc():
|
||||
simple_store_set("fs-driver-combo",
|
||||
[DeviceFilesystem.DRIVER_LOOP,
|
||||
DeviceFilesystem.DRIVER_NBD,
|
||||
DeviceFilesystem.DRIVER_DEFAULT])
|
||||
None])
|
||||
else:
|
||||
simple_store_set("fs-driver-combo",
|
||||
[DeviceFilesystem.DRIVER_DEFAULT])
|
||||
simple_store_set("fs-driver-combo", [None])
|
||||
simple_store_set("fs-format-combo",
|
||||
StorageVolume.ALL_FORMATS, capitalize=False)
|
||||
simple_store_set("fs-wrpolicy-combo", DeviceFilesystem.WRPOLICIES)
|
||||
simple_store_set("fs-wrpolicy-combo",
|
||||
DeviceFilesystem.WRPOLICIES + [None])
|
||||
self.show_pair_combo("fs-type",
|
||||
self.conn.is_openvz() or self.conn.is_lxc())
|
||||
self.show_check_button("fs-readonly",
|
||||
@ -167,11 +170,11 @@ class vmmFSDetails(vmmGObjectUI):
|
||||
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.accessmode 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")
|
||||
self.set_config_value("fs-type", dev.type)
|
||||
self.set_config_value("fs-mode", dev.accessmode)
|
||||
self.set_config_value("fs-driver", dev.driver)
|
||||
self.set_config_value("fs-wrpolicy", dev.wrpolicy)
|
||||
self.set_config_value("fs-format", dev.format)
|
||||
if dev.type != DeviceFilesystem.TYPE_RAM:
|
||||
self.widget("fs-source").set_text(dev.source)
|
||||
else:
|
||||
@ -194,7 +197,7 @@ class vmmFSDetails(vmmGObjectUI):
|
||||
|
||||
combo.set_active(idx)
|
||||
if label:
|
||||
label.set_text(value)
|
||||
label.set_text(value or "default")
|
||||
|
||||
# listeners
|
||||
def notify_change(self, ignore):
|
||||
@ -212,7 +215,7 @@ class vmmFSDetails(vmmGObjectUI):
|
||||
|
||||
show_mode = bool(ismount and
|
||||
(fsdriver == DeviceFilesystem.DRIVER_PATH or
|
||||
fsdriver == DeviceFilesystem.DRIVER_DEFAULT))
|
||||
fsdriver is None))
|
||||
uiutil.set_grid_row_visible(self.widget("fs-mode-box"), show_mode)
|
||||
|
||||
show_wrpol = bool(ismount and
|
||||
|
@ -19,41 +19,25 @@ class DeviceFilesystem(Device):
|
||||
TYPE_FILE = "file"
|
||||
TYPE_BLOCK = "block"
|
||||
TYPE_RAM = "ram"
|
||||
TYPE_DEFAULT = "default"
|
||||
TYPES = [TYPE_MOUNT, TYPE_TEMPLATE, TYPE_FILE, TYPE_BLOCK, TYPE_RAM,
|
||||
TYPE_DEFAULT]
|
||||
|
||||
MODE_PASSTHROUGH = "passthrough"
|
||||
MODE_MAPPED = "mapped"
|
||||
MODE_SQUASH = "squash"
|
||||
MODE_DEFAULT = "default"
|
||||
MODES = [MODE_PASSTHROUGH, MODE_MAPPED, MODE_SQUASH, MODE_DEFAULT]
|
||||
MODES = [MODE_PASSTHROUGH, MODE_MAPPED, MODE_SQUASH]
|
||||
|
||||
WRPOLICY_IMM = "immediate"
|
||||
WRPOLICY_DEFAULT = "default"
|
||||
WRPOLICIES = [WRPOLICY_IMM, WRPOLICY_DEFAULT]
|
||||
WRPOLICIES = [WRPOLICY_IMM]
|
||||
|
||||
DRIVER_PATH = "path"
|
||||
DRIVER_HANDLE = "handle"
|
||||
DRIVER_LOOP = "loop"
|
||||
DRIVER_NBD = "nbd"
|
||||
DRIVER_DEFAULT = "default"
|
||||
DRIVERS = [DRIVER_PATH, DRIVER_HANDLE, DRIVER_LOOP, DRIVER_NBD,
|
||||
DRIVER_DEFAULT]
|
||||
|
||||
|
||||
_type_prop = XMLProperty("./@type",
|
||||
default_cb=lambda s: None,
|
||||
default_name=TYPE_DEFAULT)
|
||||
accessmode = XMLProperty("./@accessmode",
|
||||
default_cb=lambda s: None,
|
||||
default_name=MODE_DEFAULT)
|
||||
wrpolicy = XMLProperty("./driver/@wrpolicy",
|
||||
default_cb=lambda s: None,
|
||||
default_name=WRPOLICY_DEFAULT)
|
||||
driver = XMLProperty("./driver/@type",
|
||||
default_cb=lambda s: None,
|
||||
default_name=DRIVER_DEFAULT)
|
||||
_type_prop = XMLProperty("./@type")
|
||||
accessmode = XMLProperty("./@accessmode")
|
||||
wrpolicy = XMLProperty("./driver/@wrpolicy")
|
||||
driver = XMLProperty("./driver/@type")
|
||||
format = XMLProperty("./driver/@format")
|
||||
|
||||
readonly = XMLProperty("./readonly", is_bool=True)
|
||||
@ -66,7 +50,6 @@ class DeviceFilesystem(Device):
|
||||
# that is exported to the guest as a hint for where to mount
|
||||
if ((self.conn.is_qemu() or self.conn.is_test()) and
|
||||
(self.type is None or
|
||||
self.type == self.TYPE_DEFAULT or
|
||||
self.type == self.TYPE_MOUNT)):
|
||||
pass
|
||||
elif not os.path.isabs(val):
|
||||
@ -124,11 +107,11 @@ class DeviceFilesystem(Device):
|
||||
if self.conn.is_qemu() or self.conn.is_lxc() or self.conn.is_test():
|
||||
# type=mount is the libvirt default. But hardcode it
|
||||
# here since we need it for the accessmode check
|
||||
if self.type is None or self.type == self.TYPE_DEFAULT:
|
||||
if self.type is None:
|
||||
self.type = self.TYPE_MOUNT
|
||||
|
||||
# libvirt qemu defaults to accessmode=passthrough, but that
|
||||
# really only works well for qemu running as root, which is
|
||||
# not the common case. so use mode=mapped
|
||||
if self.accessmode is None or self.accessmode == self.MODE_DEFAULT:
|
||||
if self.accessmode is None:
|
||||
self.accessmode = self.MODE_MAPPED
|
||||
|
Loading…
Reference in New Issue
Block a user