Index: /trunk/Nebulous-Server/Changes
===================================================================
--- /trunk/Nebulous-Server/Changes	(revision 13046)
+++ /trunk/Nebulous-Server/Changes	(revision 13047)
@@ -2,4 +2,5 @@
 
 0.05
+    - add Nebulous::Server->find_keys()
     - add neb-touch
     - add neb-df
Index: /trunk/Nebulous-Server/MANIFEST
===================================================================
--- /trunk/Nebulous-Server/MANIFEST	(revision 13046)
+++ /trunk/Nebulous-Server/MANIFEST	(revision 13047)
@@ -84,4 +84,5 @@
 t/10_server_is_valid_volume_name.t
 t/11_server_is_valid_class_id.t
+t/12_server_find_objects.t
 t/50_client_new.t
 t/51_client_create.t
Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13046)
+++ /trunk/Nebulous-Server/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-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13046)
+++ /trunk/Nebulous-Server/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
Index: /trunk/Nebulous-Server/t/12_server_find_objects.t
===================================================================
--- /trunk/Nebulous-Server/t/12_server_find_objects.t	(revision 13047)
+++ /trunk/Nebulous-Server/t/12_server_find_objects.t	(revision 13047)
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+# Copryight (C) 2004-2005  Joshua Hoblitt
+#
+# $Id: 12_server_find_objects.t,v 1.1 2007-04-26 23:45:03 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use Test::More tests => 6;
+
+use lib qw( ./t ./lib );
+
+use Nebulous::Server;
+use Nebulous::Util qw( :standard );
+use Test::Nebulous;
+
+my $neb = Nebulous::Server->new(
+    dsn         => "DBI:mysql:database=test:host=localhost",
+    dbuser      => "test",
+    dbpasswd    => "",
+);
+
+Test::Nebulous->setup;
+
+# search for a regex of '' should match nothing
+{
+    # key
+    my $uri = $neb->create_object("foo");
+
+    my $keys = $neb->find_objects();
+
+    is(scalar @$keys, 0, 'number of keys found');
+}
+
+Test::Nebulous->setup;
+
+{
+    # key
+    my $uri = $neb->create_object("foo");
+
+    my $keys = $neb->find_objects("foo");
+
+    is(scalar @$keys, 1, 'number of keys found');
+    is($keys->[0], "foo", "key name");
+}
+
+Test::Nebulous->setup;
+
+{
+    # key
+    my $uri1 = $neb->create_object("foo");
+    my $uri2 = $neb->replicate_object("foo");
+
+    my $keys = $neb->find_objects("foo");
+
+    is(scalar @$keys, 1, 'number of keys found');
+    is($keys->[0], "foo", "key name");
+}
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->find_objects("foo", 3);
+};
+like($@, qr/1 was expected/, "too many params");
+
+Test::Nebulous->cleanup;
Index: /trunk/Nebulous/Changes
===================================================================
--- /trunk/Nebulous/Changes	(revision 13046)
+++ /trunk/Nebulous/Changes	(revision 13047)
@@ -2,4 +2,5 @@
 
 0.05
+    - add Nebulous::Server->find_keys()
     - add neb-touch
     - add neb-df
Index: /trunk/Nebulous/MANIFEST
===================================================================
--- /trunk/Nebulous/MANIFEST	(revision 13046)
+++ /trunk/Nebulous/MANIFEST	(revision 13047)
@@ -84,4 +84,5 @@
 t/10_server_is_valid_volume_name.t
 t/11_server_is_valid_class_id.t
+t/12_server_find_objects.t
 t/50_client_new.t
 t/51_client_create.t
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13046)
+++ /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 13046)
+++ /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
Index: /trunk/Nebulous/nebclient/nebulous.wsdl
===================================================================
--- /trunk/Nebulous/nebclient/nebulous.wsdl	(revision 13046)
+++ /trunk/Nebulous/nebclient/nebulous.wsdl	(revision 13047)
@@ -60,4 +60,12 @@
     </message>
 
+    <message name="find_ObjectsRequest">
+        <part name="pattern" type="xsd:string" />
+    </message>
+    <message name="find_ObjectsResponse">
+        <!-- fixme -->
+        <part name="result" type="tns:ArrayOfString" />
+    </message>
+
     <message name="find_instancesRequest">
         <part name="key" type="xsd:string" />
@@ -114,4 +122,11 @@
             -->
         </operation>
+        <operation name="find_objects">
+            <input  message="tns:find_objectsRequest" />
+            <output message="tns:find_objectsResponse" />
+            <!--
+                <fault name="" message="" />
+            -->
+        </operation>
         <operation name="find_instances">
             <input  message="tns:find_instancesRequest" />
@@ -175,4 +190,15 @@
         <operation name="unlock_object">
             <soap:operation soapAction="urn:Nebulous/Server/SOAP#unlock_object" />
+            <input>
+                <soap:body use="encoded" namespace="urn:Nebulous/Server/SOAP"
+                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
+            </input>
+            <output>
+                <soap:body use="encoded" namespace="urn:Nebulous/Server/SOAP"
+                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
+            </output>
+        </operation>
+        <operation name="find_objects">
+            <soap:operation soapAction="urn:Nebulous/Server/SOAP#find_objects" />
             <input>
                 <soap:body use="encoded" namespace="urn:Nebulous/Server/SOAP"
Index: /trunk/Nebulous/t/12_server_find_objects.t
===================================================================
--- /trunk/Nebulous/t/12_server_find_objects.t	(revision 13047)
+++ /trunk/Nebulous/t/12_server_find_objects.t	(revision 13047)
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+# Copryight (C) 2004-2005  Joshua Hoblitt
+#
+# $Id: 12_server_find_objects.t,v 1.1 2007-04-26 23:45:03 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use Test::More tests => 6;
+
+use lib qw( ./t ./lib );
+
+use Nebulous::Server;
+use Nebulous::Util qw( :standard );
+use Test::Nebulous;
+
+my $neb = Nebulous::Server->new(
+    dsn         => "DBI:mysql:database=test:host=localhost",
+    dbuser      => "test",
+    dbpasswd    => "",
+);
+
+Test::Nebulous->setup;
+
+# search for a regex of '' should match nothing
+{
+    # key
+    my $uri = $neb->create_object("foo");
+
+    my $keys = $neb->find_objects();
+
+    is(scalar @$keys, 0, 'number of keys found');
+}
+
+Test::Nebulous->setup;
+
+{
+    # key
+    my $uri = $neb->create_object("foo");
+
+    my $keys = $neb->find_objects("foo");
+
+    is(scalar @$keys, 1, 'number of keys found');
+    is($keys->[0], "foo", "key name");
+}
+
+Test::Nebulous->setup;
+
+{
+    # key
+    my $uri1 = $neb->create_object("foo");
+    my $uri2 = $neb->replicate_object("foo");
+
+    my $keys = $neb->find_objects("foo");
+
+    is(scalar @$keys, 1, 'number of keys found');
+    is($keys->[0], "foo", "key name");
+}
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->find_objects("foo", 3);
+};
+like($@, qr/1 was expected/, "too many params");
+
+Test::Nebulous->cleanup;
