From 45e6cd4cacd5caf3bb256242c416112ee403ed51 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 2 May 2015 19:33:16 -0400 Subject: [PATCH] Remove redundant 'default dir' functions --- virtManager/addstorage.py | 5 +---- virtManager/config.py | 20 ++------------------ virtconv/formats.py | 2 +- virtinst/storage.py | 17 ++++++++++------- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/virtManager/addstorage.py b/virtManager/addstorage.py index c31dc2b8d..21a56fb78 100644 --- a/virtManager/addstorage.py +++ b/virtManager/addstorage.py @@ -56,10 +56,7 @@ class vmmAddStorage(vmmGObjectUI): ########################## def _get_default_dir(self): - pool = self.conn.get_default_pool() - if pool: - return pool.get_target_path() - return self.config.get_default_image_dir(self.conn) + return virtinst.StoragePool.get_default_dir(self.conn.get_backend()) def _get_ideal_path_info(self, name): path = self._get_default_dir() diff --git a/virtManager/config.py b/virtManager/config.py index 999b8364e..e983596bf 100644 --- a/virtManager/config.py +++ b/virtManager/config.py @@ -148,10 +148,6 @@ class vmmConfig(object): CONSOLE_SCALE_FULLSCREEN = 1 CONSOLE_SCALE_ALWAYS = 2 - DEFAULT_XEN_IMAGE_DIR = "/var/lib/xen/images" - - DEFAULT_VIRT_IMAGE_DIR = "/var/lib/libvirt/images" - def __init__(self, appname, CLIConfig, test_first_run=False): self.appname = appname self.appversion = CLIConfig.version @@ -645,6 +641,7 @@ class vmmConfig(object): return None def get_default_directory(self, conn, _type): + ignore = conn key = self._get_default_dir_key(_type) path = None @@ -655,7 +652,7 @@ class vmmConfig(object): if (_type == self.CONFIG_DIR_IMAGE or _type == self.CONFIG_DIR_ISO_MEDIA or _type == self.CONFIG_DIR_FLOPPY_MEDIA): - path = self.get_default_image_dir(conn) + path = os.getcwd() logging.debug("directory for type=%s returning=%s", _type, path) return path @@ -668,19 +665,6 @@ class vmmConfig(object): logging.debug("saving directory for type=%s to %s", key, folder) self.conf.set("/paths/%s-default" % key, folder) - def get_default_image_dir(self, conn): - if conn.is_xen(): - return self.DEFAULT_XEN_IMAGE_DIR - - if (conn.is_qemu_session() or - not os.access(self.DEFAULT_VIRT_IMAGE_DIR, os.W_OK)): - return os.getcwd() - - # Just return the default dir since the intention is that it - # is a managed pool and the user will be able to install to it. - return self.DEFAULT_VIRT_IMAGE_DIR - - # Keyring / VNC password dealings def get_secret_name(self, vm): return "vm-console-" + vm.get_uuid() diff --git a/virtconv/formats.py b/virtconv/formats.py index a14a87a60..9a6d23709 100644 --- a/virtconv/formats.py +++ b/virtconv/formats.py @@ -269,7 +269,7 @@ class VirtConverter(object): disk_format = None if destdir is None: - destdir = StoragePool.get_default_path(self.conn, build=not dry) + destdir = StoragePool.get_default_dir(self.conn, build=not dry) guest = self.get_guest() for disk in guest.get_devices("disk"): diff --git a/virtinst/storage.py b/virtinst/storage.py index 9a188bdae..a610a20a4 100644 --- a/virtinst/storage.py +++ b/virtinst/storage.py @@ -232,20 +232,23 @@ class StoragePool(_StorageObject): @staticmethod - def get_default_path(conn, build=True): + def get_default_dir(conn, build=False): """ - Return the default storage path. If there's a 'default' pool, - report that. If there's no default pool, return the path we would + Return the default storage dir. If there's a 'default' pool, + report that. If there's no default pool, return the dir we would use for the default. """ path = _get_default_pool_path(conn) - if not conn.check_support(conn.SUPPORT_CONN_STORAGE): - os.makedirs(path) + if (not conn.is_remote() and + not conn.check_support(conn.SUPPORT_CONN_STORAGE)): + if build and not os.path.exists(path): + os.makedirs(path) return path try: - poolobj = conn.storagePoolLookupByName("default") - return StoragePool(conn, parsexml=poolobj.XMLDesc(0)).target_path + for pool in conn.fetch_all_pools(): + if pool.name == "default": + return pool.target_path except: pass