Index: /trunk/Nebulous-Server/Changes
===================================================================
--- /trunk/Nebulous-Server/Changes	(revision 24638)
+++ /trunk/Nebulous-Server/Changes	(revision 24639)
@@ -33,4 +33,6 @@
     - add the ability to delete a storage object when it has instances that are
       offline
+    - change Nebulous::Server->stat_object() to return both the total number of
+      instance and just those that are available
       
 0.16
Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pod
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pod	(revision 24638)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pod	(revision 24639)
@@ -183,4 +183,5 @@
     mtime
     number of instances
+    number of available instances
 
 =item * mounts( $key );
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 24638)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 24639)
@@ -83,18 +83,21 @@
     stat_object          => qq{
         SELECT
-            storage_object.so_id,
-            storage_object.ext_id,
-            read_lock,
-            write_lock,
-            storage_object_attr.epoch,
-            storage_object_attr.mtime,
-            COUNT(instance.so_id) as instances
-        FROM storage_object
-        JOIN storage_object_attr
+            so.so_id,
+            so.ext_id,
+            attr.read_lock,
+            attr.write_lock,
+            attr.epoch,
+            attr.mtime,
+            COUNT(instance.so_id) as instances,
+            SUM(available) as available
+        FROM storage_object as so
+        JOIN storage_object_attr as attr
             USING (so_id)
         JOIN instance
             USING (so_id)
-        WHERE ext_id = ?
-        GROUP BY storage_object.so_id
+        LEFT JOIN mountedvol
+            USING(vol_id)
+        WHERE ext_id = ?
+        GROUP BY so.so_id
     },
     # Note: this sets an update lock
Index: /trunk/Nebulous-Server/t/10_server_stat_object.t
===================================================================
--- /trunk/Nebulous-Server/t/10_server_stat_object.t	(revision 24638)
+++ /trunk/Nebulous-Server/t/10_server_stat_object.t	(revision 24639)
@@ -8,5 +8,5 @@
 use warnings FATAL => qw( all );
 
-use Test::More tests => 12;
+use Test::More tests => 13;
 
 use lib qw( ./t ./lib );
@@ -27,5 +27,5 @@
     my $info = $neb->stat_object("foo");
 
-    is(scalar @$info, 7, "number of columns");
+    is(scalar @$info, 8, "number of columns");
 }
 
@@ -37,5 +37,5 @@
     my $info = $neb->stat_object("foo");
 
-    is(scalar @$info, 7,                       "number of columns");
+    is(scalar @$info, 8,                       "number of columns");
     is(@$info[0], 1,                           "so_id");
     is(@$info[1], "foo",                       "ext_id");
@@ -45,4 +45,5 @@
     like(@$info[5], qr/....-..-.. ..:..:../,   "mtime");
     is(@$info[6], 1,                           "instances");
+    is(@$info[7], 1,                           "available instances");
 }
 
