a8a3752
# HG changeset patch
a8a3752
# User Cole Robinson <crobinso@redhat.com>
a8a3752
# Date 1253563791 14400
a8a3752
# Node ID f75237b0a84e73552a55ef0121215633c4530879
a8a3752
# Parent  d3b377306a994f66cd1c03f3bcbef17c4b060720
a8a3752
Use timer to refresh available disk space in 'New VM' wizard (bz 502777)
a8a3752
a8a3752
diff -r d3b377306a99 -r f75237b0a84e src/virtManager/create.py
a8a3752
--- a/src/virtManager/create.py	Thu Sep 17 13:45:53 2009 -0400
a8a3752
+++ b/src/virtManager/create.py	Mon Sep 21 16:09:51 2009 -0400
a8a3752
@@ -93,6 +93,10 @@
a8a3752
         # 'Guest' class from the previous failed install
a8a3752
         self.failed_guest = None
a8a3752
 
a8a3752
+        # Host space polling
a8a3752
+        self.host_storage_timer = None
a8a3752
+        self.host_storage = None
a8a3752
+
a8a3752
         self.window.signal_autoconnect({
a8a3752
             "on_vmm_newcreate_delete_event" : self.close,
a8a3752
 
a8a3752
@@ -136,8 +140,18 @@
a8a3752
 
a8a3752
     def close(self, ignore1=None, ignore2=None):
a8a3752
         self.topwin.hide()
a8a3752
+        self.remove_timers()
a8a3752
+
a8a3752
         return 1
a8a3752
 
a8a3752
+    def remove_timers(self):
a8a3752
+        try:
a8a3752
+            if self.host_storage_timer:
a8a3752
+                gobject.source_remote(self.host_storage_timer)
a8a3752
+                self.host_storage_timer = None
a8a3752
+        except:
a8a3752
+            pass
a8a3752
+
a8a3752
     def set_conn(self, newconn):
a8a3752
         if self.conn == newconn:
a8a3752
             return
a8a3752
@@ -303,9 +317,11 @@
a8a3752
         self.window.get_widget("config-cpus").set_value(1)
a8a3752
 
a8a3752
         # Storage
a8a3752
+        if not self.host_storage_timer:
a8a3752
+            self.host_storage_timer = gobject.timeout_add(3 * 1000,
a8a3752
+                                                          self.host_space_tick)
a8a3752
         self.window.get_widget("enable-storage").set_active(True)
a8a3752
         self.window.get_widget("config-storage-create").set_active(True)
a8a3752
-        # FIXME: Make sure this doesn't exceed host?
a8a3752
         self.window.get_widget("config-storage-size").set_value(8)
a8a3752
         self.window.get_widget("config-storage-entry").set_text("")
a8a3752
         self.window.get_widget("config-storage-nosparse").set_active(True)
a8a3752
@@ -437,11 +453,6 @@
a8a3752
         # Storage
a8a3752
         have_storage = (is_local or is_storage_capable)
a8a3752
         storage_tooltip = None
a8a3752
-        max_storage = self.host_disk_space()
a8a3752
-        hd_label = "%s available on the host" % self.pretty_storage(max_storage)
a8a3752
-        hd_label = ("%s" % hd_label)
a8a3752
-        self.window.get_widget("phys-hd-label").set_markup(hd_label)
a8a3752
-        self.window.get_widget("config-storage-size").set_range(1, max_storage)
a8a3752
 
a8a3752
         use_storage = self.window.get_widget("config-storage-select")
a8a3752
         storage_area = self.window.get_widget("config-storage-area")
a8a3752
@@ -863,6 +874,7 @@
a8a3752
             # FIXME: use a conn specific function after we send pool-added
a8a3752
             pool = virtinst.util.lookup_pool_by_path(self.conn.vmm, path)
a8a3752
             if pool:
a8a3752
+                pool.refresh(0)
a8a3752
                 avail = int(virtinst.util.get_xml_path(pool.XMLDesc(0),
a8a3752
                                                        "/pool/available"))
a8a3752
 
a8a3752
@@ -870,7 +882,21 @@
a8a3752
             vfs = os.statvfs(os.path.dirname(path))
a8a3752
             avail = vfs[statvfs.F_FRSIZE] * vfs[statvfs.F_BAVAIL]
a8a3752
 
a8a3752
-        return int(avail / 1024.0 / 1024.0 / 1024.0)
a8a3752
+        return float(avail / 1024.0 / 1024.0 / 1024.0)
a8a3752
+
a8a3752
+    def host_space_tick(self):
a8a3752
+        max_storage = self.host_disk_space()
a8a3752
+        if self.host_storage == max_storage:
a8a3752
+            return 1
a8a3752
+        self.host_storage = max_storage
a8a3752
+
a8a3752
+        hd_label = ("%s available in the default location" %
a8a3752
+                    self.pretty_storage(max_storage))
a8a3752
+        hd_label = ("%s" % hd_label)
a8a3752
+        self.window.get_widget("phys-hd-label").set_markup(hd_label)
a8a3752
+        self.window.get_widget("config-storage-size").set_range(1, self.host_storage)
a8a3752
+
a8a3752
+        return 1
a8a3752
 
a8a3752
     def get_config_network_info(self):
a8a3752
         netidx = self.window.get_widget("config-netdev").get_active()