mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
storage: Add explicit StoragePool.lookup_default_pool
Rather than adding an option to build_default_pool which is only used in one location
This commit is contained in:
parent
67bb8fabdb
commit
f21d7e4c27
@ -502,8 +502,7 @@ class vmmConnection(vmmGObject):
|
||||
return self._get_flags_helper(vm, key, check_func)
|
||||
|
||||
def get_default_pool(self):
|
||||
poolxml = virtinst.StoragePool.build_default_pool(
|
||||
self.get_backend(), build=False)
|
||||
poolxml = virtinst.StoragePool.lookup_default_pool(self.get_backend())
|
||||
if poolxml:
|
||||
for p in self.list_pools():
|
||||
if p.get_name() == poolxml.name:
|
||||
|
@ -63,30 +63,6 @@ def _lookup_poolxml_by_path(conn, path):
|
||||
return None
|
||||
|
||||
|
||||
def _lookup_default_pool(conn):
|
||||
"""
|
||||
Helper to lookup the default pool. It will return one of
|
||||
* The pool named 'default'
|
||||
* If that doesn't exist, the pool pointing to the default path
|
||||
* Otherwise None
|
||||
"""
|
||||
name = "default"
|
||||
path = _preferred_default_pool_path(conn)
|
||||
|
||||
poolxml = None
|
||||
for trypool in conn.fetch_all_pools():
|
||||
if trypool.name == name:
|
||||
poolxml = trypool
|
||||
break
|
||||
else:
|
||||
poolxml = _lookup_poolxml_by_path(conn, path)
|
||||
|
||||
if poolxml:
|
||||
log.debug("Found default pool name=%s target=%s",
|
||||
poolxml.name, poolxml.target_path)
|
||||
return poolxml
|
||||
|
||||
|
||||
class _EnumerateSource(XMLBuilder):
|
||||
XML_NAME = "source"
|
||||
|
||||
@ -166,16 +142,38 @@ class StoragePool(_StorageObject):
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def build_default_pool(conn, build=True):
|
||||
def lookup_default_pool(conn):
|
||||
"""
|
||||
Helper to lookup the default pool. It will return one of
|
||||
* The pool named 'default'
|
||||
* If that doesn't exist, the pool pointing to the default path
|
||||
* Otherwise None
|
||||
"""
|
||||
name = "default"
|
||||
path = _preferred_default_pool_path(conn)
|
||||
|
||||
poolxml = None
|
||||
for trypool in conn.fetch_all_pools():
|
||||
if trypool.name == name:
|
||||
poolxml = trypool
|
||||
break
|
||||
else:
|
||||
poolxml = _lookup_poolxml_by_path(conn, path)
|
||||
|
||||
if poolxml:
|
||||
log.debug("Found default pool name=%s target=%s",
|
||||
poolxml.name, poolxml.target_path)
|
||||
return poolxml
|
||||
|
||||
@staticmethod
|
||||
def build_default_pool(conn):
|
||||
"""
|
||||
Attempt to lookup the 'default' pool, but if it doesn't exist,
|
||||
create it
|
||||
"""
|
||||
poolxml = _lookup_default_pool(conn)
|
||||
poolxml = StoragePool.lookup_default_pool(conn)
|
||||
if poolxml:
|
||||
return poolxml
|
||||
if not build:
|
||||
return None
|
||||
|
||||
try:
|
||||
name = "default"
|
||||
|
Loading…
Reference in New Issue
Block a user