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:
Cole Robinson 2018-09-01 21:58:46 -04:00
parent ef83565e48
commit 6215f790f5
2 changed files with 30 additions and 44 deletions

View File

@ -71,17 +71,20 @@ class vmmFSDetails(vmmGObjectUI):
def set_initial_state(self): def set_initial_state(self):
def simple_store_set(comboname, values, sort=True, capitalize=True): def simple_store_set(comboname, values, sort=True, capitalize=True):
combo = self.widget(comboname) combo = self.widget(comboname)
# [XML value, label]
model = Gtk.ListStore(str, str) model = Gtk.ListStore(str, str)
combo.set_model(model) combo.set_model(model)
uiutil.init_combo_text_column(combo, 1) uiutil.init_combo_text_column(combo, 1)
if sort: if sort:
model.set_sort_column_id(0, Gtk.SortType.ASCENDING) model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
if capitalize:
for val in values: for xmlval in values:
model.append([val, val.capitalize()]) label = xmlval
else: if xmlval is None:
for val in values: label = "Default"
model.append([val.lower(), val]) if capitalize:
label = label.capitalize()
model.append([xmlval, label])
# Filesystem widgets # Filesystem widgets
if self.conn.is_openvz(): if self.conn.is_openvz():
@ -98,23 +101,23 @@ class vmmFSDetails(vmmGObjectUI):
simple_store_set("fs-type-combo", [DeviceFilesystem.TYPE_MOUNT]) simple_store_set("fs-type-combo", [DeviceFilesystem.TYPE_MOUNT])
self.widget("fs-type-label").set_text(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(): if self.conn.is_qemu() or self.conn.is_test():
simple_store_set("fs-driver-combo", simple_store_set("fs-driver-combo",
[DeviceFilesystem.DRIVER_PATH, [DeviceFilesystem.DRIVER_PATH,
DeviceFilesystem.DRIVER_HANDLE, DeviceFilesystem.DRIVER_HANDLE,
DeviceFilesystem.DRIVER_DEFAULT]) None])
elif self.conn.is_lxc(): elif self.conn.is_lxc():
simple_store_set("fs-driver-combo", simple_store_set("fs-driver-combo",
[DeviceFilesystem.DRIVER_LOOP, [DeviceFilesystem.DRIVER_LOOP,
DeviceFilesystem.DRIVER_NBD, DeviceFilesystem.DRIVER_NBD,
DeviceFilesystem.DRIVER_DEFAULT]) None])
else: else:
simple_store_set("fs-driver-combo", simple_store_set("fs-driver-combo", [None])
[DeviceFilesystem.DRIVER_DEFAULT])
simple_store_set("fs-format-combo", simple_store_set("fs-format-combo",
StorageVolume.ALL_FORMATS, capitalize=False) 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.show_pair_combo("fs-type",
self.conn.is_openvz() or self.conn.is_lxc()) self.conn.is_openvz() or self.conn.is_lxc())
self.show_check_button("fs-readonly", self.show_check_button("fs-readonly",
@ -167,11 +170,11 @@ class vmmFSDetails(vmmGObjectUI):
def set_dev(self, dev): def set_dev(self, dev):
self._dev = dev self._dev = dev
self.set_config_value("fs-type", dev.type or "default") self.set_config_value("fs-type", dev.type)
self.set_config_value("fs-mode", dev.accessmode or "default") self.set_config_value("fs-mode", dev.accessmode)
self.set_config_value("fs-driver", dev.driver or "default") self.set_config_value("fs-driver", dev.driver)
self.set_config_value("fs-wrpolicy", dev.wrpolicy or "default") self.set_config_value("fs-wrpolicy", dev.wrpolicy)
self.set_config_value("fs-format", dev.format or "default") self.set_config_value("fs-format", dev.format)
if dev.type != DeviceFilesystem.TYPE_RAM: if dev.type != DeviceFilesystem.TYPE_RAM:
self.widget("fs-source").set_text(dev.source) self.widget("fs-source").set_text(dev.source)
else: else:
@ -194,7 +197,7 @@ class vmmFSDetails(vmmGObjectUI):
combo.set_active(idx) combo.set_active(idx)
if label: if label:
label.set_text(value) label.set_text(value or "default")
# listeners # listeners
def notify_change(self, ignore): def notify_change(self, ignore):
@ -212,7 +215,7 @@ class vmmFSDetails(vmmGObjectUI):
show_mode = bool(ismount and show_mode = bool(ismount and
(fsdriver == DeviceFilesystem.DRIVER_PATH or (fsdriver == DeviceFilesystem.DRIVER_PATH or
fsdriver == DeviceFilesystem.DRIVER_DEFAULT)) fsdriver is None))
uiutil.set_grid_row_visible(self.widget("fs-mode-box"), show_mode) uiutil.set_grid_row_visible(self.widget("fs-mode-box"), show_mode)
show_wrpol = bool(ismount and show_wrpol = bool(ismount and

View File

@ -19,41 +19,25 @@ class DeviceFilesystem(Device):
TYPE_FILE = "file" TYPE_FILE = "file"
TYPE_BLOCK = "block" TYPE_BLOCK = "block"
TYPE_RAM = "ram" TYPE_RAM = "ram"
TYPE_DEFAULT = "default"
TYPES = [TYPE_MOUNT, TYPE_TEMPLATE, TYPE_FILE, TYPE_BLOCK, TYPE_RAM,
TYPE_DEFAULT]
MODE_PASSTHROUGH = "passthrough" MODE_PASSTHROUGH = "passthrough"
MODE_MAPPED = "mapped" MODE_MAPPED = "mapped"
MODE_SQUASH = "squash" MODE_SQUASH = "squash"
MODE_DEFAULT = "default" MODES = [MODE_PASSTHROUGH, MODE_MAPPED, MODE_SQUASH]
MODES = [MODE_PASSTHROUGH, MODE_MAPPED, MODE_SQUASH, MODE_DEFAULT]
WRPOLICY_IMM = "immediate" WRPOLICY_IMM = "immediate"
WRPOLICY_DEFAULT = "default" WRPOLICIES = [WRPOLICY_IMM]
WRPOLICIES = [WRPOLICY_IMM, WRPOLICY_DEFAULT]
DRIVER_PATH = "path" DRIVER_PATH = "path"
DRIVER_HANDLE = "handle" DRIVER_HANDLE = "handle"
DRIVER_LOOP = "loop" DRIVER_LOOP = "loop"
DRIVER_NBD = "nbd" DRIVER_NBD = "nbd"
DRIVER_DEFAULT = "default"
DRIVERS = [DRIVER_PATH, DRIVER_HANDLE, DRIVER_LOOP, DRIVER_NBD,
DRIVER_DEFAULT]
_type_prop = XMLProperty("./@type", _type_prop = XMLProperty("./@type")
default_cb=lambda s: None, accessmode = XMLProperty("./@accessmode")
default_name=TYPE_DEFAULT) wrpolicy = XMLProperty("./driver/@wrpolicy")
accessmode = XMLProperty("./@accessmode", driver = XMLProperty("./driver/@type")
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)
format = XMLProperty("./driver/@format") format = XMLProperty("./driver/@format")
readonly = XMLProperty("./readonly", is_bool=True) 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 # that is exported to the guest as a hint for where to mount
if ((self.conn.is_qemu() or self.conn.is_test()) and if ((self.conn.is_qemu() or self.conn.is_test()) and
(self.type is None or (self.type is None or
self.type == self.TYPE_DEFAULT or
self.type == self.TYPE_MOUNT)): self.type == self.TYPE_MOUNT)):
pass pass
elif not os.path.isabs(val): 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(): if self.conn.is_qemu() or self.conn.is_lxc() or self.conn.is_test():
# type=mount is the libvirt default. But hardcode it # type=mount is the libvirt default. But hardcode it
# here since we need it for the accessmode check # 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 self.type = self.TYPE_MOUNT
# libvirt qemu defaults to accessmode=passthrough, but that # libvirt qemu defaults to accessmode=passthrough, but that
# really only works well for qemu running as root, which is # really only works well for qemu running as root, which is
# not the common case. so use mode=mapped # 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 self.accessmode = self.MODE_MAPPED