Index: trunk/Nebulous-Server/bin/neb-voladm
===================================================================
--- trunk/Nebulous-Server/bin/neb-voladm	(revision 20143)
+++ trunk/Nebulous-Server/bin/neb-voladm	(revision 20147)
@@ -3,5 +3,5 @@
 # Copyright (C) 2008  Joshua Hoblitt
 #
-# $Id: neb-voladm,v 1.2 2008-10-14 20:13:17 jhoblitt Exp $
+# $Id: neb-voladm,v 1.3 2008-10-14 21:56:04 jhoblitt Exp $
 
 use strict;
@@ -20,5 +20,16 @@
 use Pod::Usage qw( pod2usage );
 
-my ($db, $dbhost, $dbuser, $dbpass, $vname, $vhost);
+my (
+    $allocate,
+    $available,
+    $db,
+    $dbhost,
+    $dbpass,
+    $dbuser,
+    $debug,
+    $vhost,
+    $vname,
+    $xattr,
+);
 
 $db     = $ENV{'NEB_DB'} unless $db;
@@ -28,15 +39,29 @@
 
 GetOptions(
+    'allocate=i'        => \$allocate,
+    'available=i'       => \$available,
     'db|d=s'            => \$db,
+    'debug'             => \$debug,
     'host=s'            => \$dbhost,
+    'pass|p=s'          => \$dbpass,
     'user|u=s'          => \$dbuser,
-    'pass|p=s'          => \$dbpass,
+    'vhost=s'           => \$vhost,
     'vname|n=s'         => \$vname,
-    'vhost=s'           => \$vhost,
+    'xattr=i'           => \$xattr,
 ) || pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
-    unless $db && $dbuser && $dbpass;
+    unless defined $db && defined $dbuser && defined $dbpass;
+
+# are we listing the volumes or updating?
+if (defined $allocate or defined $available or defined $xattr) {
+    pod2usage( -msg => "Options: --allocate, --avaiable, and --xattr Require options --vhost or --vname", -exitval => 2 )
+        unless defined $vhost or defined $vname;
+    pod2usage( -msg => "Options: --allocate, --avaiable, and --xattr Must be 0 or 1", -exitval => 2)
+        if (defined $allocate and $allocate !~ m/^[01]$/)
+        or (defined $available and $available !~ m/^[01]$/)
+        or (defined $xattr and $xattr !~ m/^[01]$/);
+}
 
 my $dbh = DBI->connect(
@@ -51,14 +76,39 @@
 );
 
+my %constraint;
+$constraint{'v.host'} = $vhost if defined $vhost;
+$constraint{'v.name'} = $vname if defined $vname;
+
+my %set;
+$set{'v.allocate'} = $allocate if defined $allocate;
+$set{'v.available'} = $available if defined $available;
+$set{'v.xattr'} = $xattr if defined $xattr;
+
+if (%set) {
+    my ($q, @bind) = sql_interp("UPDATE volume AS v SET", \%set, "WHERE", \%constraint);
+    warn "$q\n" if $debug;
+    my $query = $dbh->prepare($q);
+    $query->execute(@bind);
+} 
+
 my $sql = Nebulous::Server::SQL->new();
-
-my %constraint;
-$constraint{host} = $vhost if defined $vhost;
-$constraint{name} = $vname if defined $vname;
-
-my $select = sql_inerp($sql->get_volumes . " WHERE", \%constraint);
-
-my $query = $dbh->prepare($select);
-$query->execute();
+my ($q, @bind);
+if (%constraint) {
+    ($q, @bind) = sql_interp($sql->get_volumes . "WHERE", \%constraint);
+} else {
+    $q = $sql->get_volumes;
+}
+
+warn "$q\n" if $debug;
+my $query = $dbh->prepare($q);
+$query->execute(@bind);
+
+my $format  = "%-15s %-15s %-10s %-10s %-10s %-10s\n";
+my @columns = qw(host name mounted allocate available xattr);
+printf($format, @columns);
+
+while (my $row = $query->fetchrow_hashref) {
+    printf($format, @$row{@columns});
+}
 
 __END__
@@ -68,5 +118,5 @@
 =head1 NAME
 
-neb-addvol - add a storage volume to a Nebulous server
+neb-voladm - manage Nebulous server storage volumes
 
 =head1 SYNOPSIS
