diff options
author | Cole Robinson <crobinso@redhat.com> | 2013-12-04 18:57:43 -0500 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2013-12-04 19:01:52 -0500 |
commit | c351c8963ac002c4f92f3e8685dcdc9620bba2ef (patch) | |
tree | aa5949ed05389b82f6a185d745a585164374179e | |
parent | 10d5eb837578a4f6e4a41ea1a7f4a99c64d49428 (diff) | |
download | virt-manager-c351c8963ac002c4f92f3e8685dcdc9620bba2ef.tar.gz |
storage: Merge duplicate vol list populating
-rw-r--r-- | virtManager/host.py | 73 | ||||
-rw-r--r-- | virtManager/storagebrowse.py | 46 |
2 files changed, 49 insertions, 70 deletions
diff --git a/virtManager/host.py b/virtManager/host.py index cf815afa..b873e639 100644 --- a/virtManager/host.py +++ b/virtManager/host.py @@ -766,7 +766,7 @@ class vmmHost(vmmGObjectUI): vol.delete() def idlecb(): self.refresh_current_pool() - self.populate_storage_volumes() + self.repopulate_storage_volumes() self.idle_add(idlecb) logging.debug("Deleting volume '%s'", vol.get_name()) @@ -912,7 +912,7 @@ class vmmHost(vmmGObjectUI): self.widget("pool-autostart").set_active(auto) self.widget("vol-list").set_sensitive(active) - self.populate_storage_volumes() + self.repopulate_storage_volumes() self.widget("pool-delete").set_sensitive(not active) self.widget("pool-stop").set_sensitive(active) @@ -987,37 +987,10 @@ class vmmHost(vmmGObjectUI): pool_list = self.widget("pool-list") populate_storage_pools(pool_list, self.conn, self.current_pool()) - def populate_storage_volumes(self): + def repopulate_storage_volumes(self): + list_widget = self.widget("vol-list") pool = self.current_pool() - model = self.widget("vol-list").get_model() - model.clear() - vols = pool.get_volumes() - for key in vols.keys(): - vol = vols[key] - - try: - path = vol.get_target_path() - name = vol.get_name() - cap = vol.get_pretty_capacity() - fmt = vol.get_format() or "" - except: - logging.debug("Error getting volume info for '%s', " - "hiding it", key, exc_info=True) - continue - - namestr = None - try: - if path: - names = VirtualDisk.path_in_use_by(self.conn.get_backend(), - path) - namestr = ", ".join(names) - if not namestr: - namestr = None - except: - logging.exception("Failed to determine if storage volume in " - "use.") - - model.append([key, name, cap, fmt, namestr]) + populate_storage_volumes(list_widget, pool, None) ############################# @@ -1333,6 +1306,42 @@ def populate_storage_pools(pool_list, conn, curpool): curpool and curpool.get_uuid() or None) +def populate_storage_volumes(list_widget, pool, sensitive_cb): + vols = pool and pool.get_volumes() or {} + model = list_widget.get_model() + model.clear() + + for key in vols.keys(): + vol = vols[key] + + try: + path = vol.get_target_path() + name = vol.get_name() + cap = vol.get_pretty_capacity() + fmt = vol.get_format() or "" + except: + logging.debug("Error getting volume info for '%s', " + "hiding it", key, exc_info=True) + continue + + namestr = None + try: + if path: + names = VirtualDisk.path_in_use_by(vol.conn.get_backend(), + path) + namestr = ", ".join(names) + if not namestr: + namestr = None + except: + logging.exception("Failed to determine if storage volume in " + "use.") + + row = [key, name, cap, fmt, namestr] + if sensitive_cb: + row.append(sensitive_cb(fmt)) + model.append(row) + + def get_pool_size_percent(conn, uuid): pool = conn.get_pool(uuid) cap = pool.get_capacity() diff --git a/virtManager/storagebrowse.py b/virtManager/storagebrowse.py index 75859d94..b4f93c18 100644 --- a/virtManager/storagebrowse.py +++ b/virtManager/storagebrowse.py @@ -25,8 +25,6 @@ from gi.repository import GObject from gi.repository import Gtk # pylint: enable=E0611 -from virtinst import VirtualDisk - from virtManager import host from virtManager.createvol import vmmCreateVolume from virtManager.baseclass import vmmGObjectUI @@ -327,47 +325,19 @@ class vmmStorageBrowser(vmmGObjectUI): # Do stuff! def populate_storage_volumes(self): - model = self.widget("vol-list").get_model() - model.clear() - dironly = self.browse_reason == self.config.CONFIG_DIR_FS - + list_widget = self.widget("vol-list") pool = self.current_pool() - if not pool: - return - vols = pool.get_volumes() - for key in vols.keys(): - vol = vols[key] - sensitive = True - try: - path = vol.get_target_path() - fmt = vol.get_format() or "" - except Exception: - logging.exception("Failed to determine volume parameters, " - "skipping volume %s", key) - continue - - namestr = None - - try: - if path: - names = VirtualDisk.path_in_use_by(self.conn.get_backend(), - path) - namestr = ", ".join(names) - if not namestr: - namestr = None - except: - logging.exception("Failed to determine if storage volume in " - "use.") - - if dironly and fmt != 'dir': - sensitive = False + def sensitive_cb(fmt): + if ((self.browse_reason == self.config.CONFIG_DIR_FS) + and fmt != 'dir'): + return False elif not self.rhel6_defaults: if fmt == "vmdk": - sensitive = False + return False + return True - model.append([key, vol.get_name(), vol.get_pretty_capacity(), - fmt, namestr, sensitive]) + host.populate_storage_volumes(list_widget, pool, sensitive_cb) def show_err(self, info, details=None): self.err.show_err(info, |