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:
Cole Robinson 2019-07-02 19:44:10 -04:00
parent 67bb8fabdb
commit f21d7e4c27
2 changed files with 27 additions and 30 deletions

View File

@ -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:

View File

@ -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"