Index: trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13041)
+++ trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13047)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.24 2007-04-23 23:31:32 jhoblitt Exp $
+# $Id: Server.pm,v 1.25 2007-04-26 23:45:03 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -567,4 +567,43 @@
 
 
+sub find_objects {
+    my $self = shift;
+
+    my ( $pattern ) = validate_pos( @_,
+        {
+            type        => SCALAR,
+            optional    => 1,
+        },
+    );
+
+    my $log = $self->log;
+    my $sql = $self->sql;
+    my $db  =$self->db;
+
+    $log->debug( "entered - @_" );
+
+    my $query;
+
+    eval {
+        $query = $db->prepare_cached( $sql->find_objects );
+        $query->execute( $pattern );
+    };
+    $log->logdie( "database error: $@" ) if $@;
+
+    my @keys;
+
+    while ( my $row = $query->fetchrow_hashref ) {
+        my $key = $row->{ 'ext_id' };
+        push @keys, $key if $key;
+    }
+
+    $log->debug( "no keys found" ) unless ( scalar @keys );
+
+    $log->debug( "leaving" );
+
+    return \@keys;
+}
+
+
 sub find_instances {
     my $self = shift;
@@ -744,4 +783,8 @@
     my $query;
     eval {
+        # ask the db to generate the table of mounted Nebulous volume 
+        $query = $db->prepare_cached("call getmountedvol()");
+        $query->execute();
+
         # TODO cache this?
         my $rows;
@@ -759,5 +802,5 @@
         }
 
-        $volume = $query->fetchrow_hashref->{ 'mountpoint' };
+        $volume = $query->fetchrow_hashref->{ 'volume' };
 
         $query->finish;
@@ -769,4 +812,6 @@
         $log->logdie( "database error: $@" ) if $@;
     }
+
+    $log->logdie( "failed to find a suitable volume" ) unless defined $volume;
 
     $log->debug( "leaving" );
Index: trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13041)
+++ trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13047)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.26 2007-04-26 20:27:33 jhoblitt Exp $
+# $Id: SQL.pm,v 1.27 2007-04-26 23:45:03 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -116,9 +116,7 @@
     get_storage_volume_byname   => qq{
         SELECT
-            mountpoint,
+            path as volume,
             total - used as free
-        FROM volume
-        JOIN mount      -- join limits us to currently mounted volumes
-            ON volume.path = mount.mountpoint
+        FROM mountedvol
         WHERE
             used / total < ?
@@ -129,9 +127,7 @@
     get_storage_volume          => qq{
         SELECT
-            mountpoint,
+            path as volume,
             total - used as free
-        FROM volume
-        JOIN mount      -- join limits us to currently mounted volumes
-            ON volume.path = mount.mountpoint
+        FROM mountedvol
         WHERE
             used / total < ?
@@ -152,4 +148,9 @@
         FROM volume
         WHERE name = ?
+    },
+    find_objects => qq{
+        SELECT *
+        FROM storage_object
+        WHERE ext_id REGEXP ?
     },
 );
@@ -315,5 +316,5 @@
     ) ENGINE=MEMORY;
 
-    -- iterator over the volume table finding the coresponding entry in the
+    -- iterate over the volume table finding the coresponding entry in the
     -- mount table and inserting union of the volume & mount row into the
     -- mountedvol table
