storage: Merge duplicate vol list populating

This commit is contained in:
Cole Robinson 2013-12-04 18:57:43 -05:00
parent 10d5eb8375
commit c351c8963a
2 changed files with 49 additions and 70 deletions

View File

@ -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()

View File

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