mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-24 02:04:13 +03:00
diskbackend: Simplify pool source lookup
Have it share logic with a similar routine
This commit is contained in:
parent
3753fcbaa3
commit
3064f4058d
@ -28,30 +28,6 @@ from virtinst import StoragePool, StorageVolume
|
||||
from virtinst import util
|
||||
|
||||
|
||||
def _check_if_pool_source(conn, path):
|
||||
"""
|
||||
If passed path is a host disk device like /dev/sda, want to let the user
|
||||
use it
|
||||
"""
|
||||
if not conn.check_support(conn.SUPPORT_CONN_STORAGE):
|
||||
return None
|
||||
|
||||
def check_pool(poolname, path):
|
||||
pool = conn.storagePoolLookupByName(poolname)
|
||||
xmlobj = StoragePool(conn, parsexml=pool.XMLDesc(0))
|
||||
if xmlobj.source_path == path:
|
||||
return pool
|
||||
|
||||
running_list = conn.listStoragePools()
|
||||
inactive_list = conn.listDefinedStoragePools()
|
||||
for plist in [running_list, inactive_list]:
|
||||
for name in plist:
|
||||
p = check_pool(name, path)
|
||||
if p:
|
||||
return p
|
||||
return None
|
||||
|
||||
|
||||
def check_if_path_managed(conn, path):
|
||||
"""
|
||||
Determine if we can use libvirt storage APIs to create or lookup
|
||||
@ -110,7 +86,8 @@ def check_if_path_managed(conn, path):
|
||||
|
||||
if not vol:
|
||||
# See if path is a pool source, and allow it through
|
||||
trypool = _check_if_pool_source(conn, path)
|
||||
trypool = StoragePool.lookup_pool_by_path(
|
||||
conn, path, use_source=True)
|
||||
if trypool:
|
||||
path_is_pool = True
|
||||
pool = trypool
|
||||
|
@ -236,18 +236,24 @@ class StoragePool(_StorageObject):
|
||||
|
||||
|
||||
@staticmethod
|
||||
def lookup_pool_by_path(conn, path):
|
||||
def lookup_pool_by_path(conn, path, use_source=False):
|
||||
"""
|
||||
Return the first pool with matching matching target path.
|
||||
return the first we find, active or inactive. This iterates over
|
||||
all pools and dumps their xml, so it is NOT quick.
|
||||
Favor running pools over inactive pools.
|
||||
|
||||
@use_source: If true, compare against pool source path, not
|
||||
target path.
|
||||
|
||||
@returns: virStoragePool object if found, None otherwise
|
||||
"""
|
||||
if not conn.check_support(conn.SUPPORT_CONN_STORAGE):
|
||||
return None
|
||||
|
||||
def check_pool(pool, path):
|
||||
if use_source:
|
||||
xml_path = pool.source_path
|
||||
else:
|
||||
xml_path = pool.target_path
|
||||
if xml_path is not None and os.path.abspath(xml_path) == path:
|
||||
return True
|
||||
|
Loading…
x
Reference in New Issue
Block a user