mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-08 07:03:02 -06:00
storage: Replace pool supports_property with supports_X
Makes usage more explicit, and easier to track for coverage testing
This commit is contained in:
parent
b8074b4505
commit
f64655a843
@ -27,18 +27,18 @@ def createPool(conn, ptype, poolname=None, fmt=None, target_path=None,
|
||||
pool_inst.name = poolname
|
||||
pool_inst.type = ptype
|
||||
|
||||
if pool_inst.supports_property("hosts"):
|
||||
if pool_inst.supports_hosts():
|
||||
hostobj = pool_inst.hosts.add_new()
|
||||
hostobj.name = "some.random.hostname"
|
||||
if pool_inst.supports_property("source_path"):
|
||||
if pool_inst.supports_source_path():
|
||||
pool_inst.source_path = source_path or "/some/source/path"
|
||||
if pool_inst.supports_property("target_path"):
|
||||
if pool_inst.supports_target_path():
|
||||
pool_inst.target_path = target_path or "/some/target/path"
|
||||
if fmt and pool_inst.supports_property("format"):
|
||||
if fmt and pool_inst.supports_format():
|
||||
pool_inst.format = fmt
|
||||
if source_name and pool_inst.supports_property("source_name"):
|
||||
if source_name and pool_inst.supports_source_name():
|
||||
pool_inst.source_name = source_name
|
||||
if iqn and pool_inst.supports_property("iqn"):
|
||||
if iqn and pool_inst.supports_iqn():
|
||||
pool_inst.iqn = iqn
|
||||
|
||||
return poolCompare(pool_inst)
|
||||
|
@ -224,18 +224,18 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
uiutil.set_grid_row_visible(widget, do_show)
|
||||
|
||||
pool = self._make_stub_pool()
|
||||
src = pool.supports_property("source_path")
|
||||
src = pool.supports_source_path()
|
||||
src_b = src and not self.conn.is_remote()
|
||||
tgt = pool.supports_property("target_path")
|
||||
tgt = pool.supports_target_path()
|
||||
tgt_b = tgt and not self.conn.is_remote()
|
||||
host = pool.supports_property("hosts")
|
||||
fmt = pool.supports_property("format")
|
||||
iqn = pool.supports_property("iqn")
|
||||
host = pool.supports_hosts()
|
||||
fmt = pool.supports_format()
|
||||
iqn = pool.supports_iqn()
|
||||
builddef, buildsens = self._get_build_default(pool.type)
|
||||
|
||||
# We don't show source_name for logical pools, since we use
|
||||
# pool-sources to avoid the need for it
|
||||
src_name = (pool.supports_property("source_name") and
|
||||
src_name = (pool.supports_source_name() and
|
||||
pool.type != pool.TYPE_LOGICAL)
|
||||
|
||||
# Source path browsing is meaningless for net pools
|
||||
@ -371,7 +371,7 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
hostobj.name = host
|
||||
if source:
|
||||
pool.source_path = source
|
||||
if fmt and pool.supports_property("format"):
|
||||
if fmt and pool.supports_format():
|
||||
pool.format = fmt
|
||||
if iqn:
|
||||
pool.iqn = iqn
|
||||
|
@ -252,7 +252,7 @@ class StoragePool(_StorageObject):
|
||||
name))
|
||||
|
||||
def default_target_path(self):
|
||||
if not self.supports_property("target_path"):
|
||||
if not self.supports_target_path():
|
||||
return None
|
||||
if (self.type == self.TYPE_DIR or
|
||||
self.type == self.TYPE_NETFS or
|
||||
@ -290,7 +290,7 @@ class StoragePool(_StorageObject):
|
||||
def default_source_name(self):
|
||||
srcname = None
|
||||
|
||||
if not self.supports_property("source_name"):
|
||||
if not self.supports_source_name():
|
||||
srcname = None
|
||||
elif self.type == StoragePool.TYPE_NETFS:
|
||||
srcname = self.name
|
||||
@ -351,25 +351,33 @@ class StoragePool(_StorageObject):
|
||||
# Public API helpers #
|
||||
######################
|
||||
|
||||
def supports_property(self, propname):
|
||||
users = {
|
||||
"source_path": [self.TYPE_FS, self.TYPE_NETFS, self.TYPE_LOGICAL,
|
||||
self.TYPE_DISK, self.TYPE_ISCSI, self.TYPE_SCSI,
|
||||
self.TYPE_GLUSTER],
|
||||
"source_name": [self.TYPE_LOGICAL, self.TYPE_GLUSTER,
|
||||
self.TYPE_RBD, self.TYPE_SHEEPDOG, self.TYPE_ZFS],
|
||||
"hosts": [self.TYPE_NETFS, self.TYPE_ISCSI, self.TYPE_GLUSTER,
|
||||
self.TYPE_RBD, self.TYPE_SHEEPDOG],
|
||||
"format": [self.TYPE_FS, self.TYPE_NETFS, self.TYPE_DISK],
|
||||
"iqn": [self.TYPE_ISCSI],
|
||||
"target_path": [self.TYPE_DIR, self.TYPE_FS, self.TYPE_NETFS,
|
||||
self.TYPE_LOGICAL, self.TYPE_DISK, self.TYPE_ISCSI,
|
||||
self.TYPE_SCSI, self.TYPE_MPATH]
|
||||
}
|
||||
def supports_target_path(self):
|
||||
return self.type in [
|
||||
self.TYPE_DIR, self.TYPE_FS, self.TYPE_NETFS,
|
||||
self.TYPE_LOGICAL, self.TYPE_DISK, self.TYPE_ISCSI,
|
||||
self.TYPE_SCSI, self.TYPE_MPATH]
|
||||
|
||||
if users.get(propname):
|
||||
return self.type in users[propname]
|
||||
return hasattr(self, propname)
|
||||
def supports_source_name(self):
|
||||
return self.type in [self.TYPE_LOGICAL, self.TYPE_GLUSTER,
|
||||
self.TYPE_RBD, self.TYPE_SHEEPDOG, self.TYPE_ZFS]
|
||||
|
||||
|
||||
def supports_source_path(self):
|
||||
return self.type in [
|
||||
self.TYPE_FS, self.TYPE_NETFS, self.TYPE_LOGICAL,
|
||||
self.TYPE_DISK, self.TYPE_ISCSI, self.TYPE_SCSI,
|
||||
self.TYPE_GLUSTER]
|
||||
|
||||
def supports_hosts(self):
|
||||
return self.type in [
|
||||
self.TYPE_NETFS, self.TYPE_ISCSI, self.TYPE_GLUSTER,
|
||||
self.TYPE_RBD, self.TYPE_SHEEPDOG]
|
||||
|
||||
def supports_format(self):
|
||||
return self.type in [self.TYPE_FS, self.TYPE_NETFS, self.TYPE_DISK]
|
||||
|
||||
def supports_iqn(self):
|
||||
return self.type in [self.TYPE_ISCSI]
|
||||
|
||||
def get_disk_type(self):
|
||||
if (self.type == StoragePool.TYPE_DISK or
|
||||
@ -397,12 +405,12 @@ class StoragePool(_StorageObject):
|
||||
self.target_path = self.default_target_path()
|
||||
if not self.source_name:
|
||||
self.source_name = self.default_source_name()
|
||||
if not self.format and self.supports_property("format"):
|
||||
if not self.format and self.supports_format():
|
||||
self.format = "auto"
|
||||
|
||||
if self.supports_property("hosts") and not self.hosts:
|
||||
if self.supports_hosts() and not self.hosts:
|
||||
raise RuntimeError(_("Hostname is required"))
|
||||
if (self.supports_property("source_path") and
|
||||
if (self.supports_source_path() and
|
||||
self.type != self.TYPE_LOGICAL and
|
||||
not self.source_path):
|
||||
raise RuntimeError(_("Source path is required"))
|
||||
|
Loading…
Reference in New Issue
Block a user