IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20147


Ignore:
Timestamp:
Oct 14, 2008, 11:56:04 AM (18 years ago)
Author:
jhoblitt
Message:

fwv

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/neb-voladm

    r20143 r20147  
    33# Copyright (C) 2008  Joshua Hoblitt
    44#
    5 # $Id: neb-voladm,v 1.2 2008-10-14 20:13:17 jhoblitt Exp $
     5# $Id: neb-voladm,v 1.3 2008-10-14 21:56:04 jhoblitt Exp $
    66
    77use strict;
     
    2020use Pod::Usage qw( pod2usage );
    2121
    22 my ($db, $dbhost, $dbuser, $dbpass, $vname, $vhost);
     22my (
     23    $allocate,
     24    $available,
     25    $db,
     26    $dbhost,
     27    $dbpass,
     28    $dbuser,
     29    $debug,
     30    $vhost,
     31    $vname,
     32    $xattr,
     33);
    2334
    2435$db     = $ENV{'NEB_DB'} unless $db;
     
    2839
    2940GetOptions(
     41    'allocate=i'        => \$allocate,
     42    'available=i'       => \$available,
    3043    'db|d=s'            => \$db,
     44    'debug'             => \$debug,
    3145    'host=s'            => \$dbhost,
     46    'pass|p=s'          => \$dbpass,
    3247    'user|u=s'          => \$dbuser,
    33     'pass|p=s'          => \$dbpass,
     48    'vhost=s'           => \$vhost,
    3449    'vname|n=s'         => \$vname,
    35     'vhost=s'           => \$vhost,
     50    'xattr=i'           => \$xattr,
    3651) || pod2usage( 2 );
    3752
    3853pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    3954pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
    40     unless $db && $dbuser && $dbpass;
     55    unless defined $db && defined $dbuser && defined $dbpass;
     56
     57# are we listing the volumes or updating?
     58if (defined $allocate or defined $available or defined $xattr) {
     59    pod2usage( -msg => "Options: --allocate, --avaiable, and --xattr Require options --vhost or --vname", -exitval => 2 )
     60        unless defined $vhost or defined $vname;
     61    pod2usage( -msg => "Options: --allocate, --avaiable, and --xattr Must be 0 or 1", -exitval => 2)
     62        if (defined $allocate and $allocate !~ m/^[01]$/)
     63        or (defined $available and $available !~ m/^[01]$/)
     64        or (defined $xattr and $xattr !~ m/^[01]$/);
     65}
    4166
    4267my $dbh = DBI->connect(
     
    5176);
    5277
     78my %constraint;
     79$constraint{'v.host'} = $vhost if defined $vhost;
     80$constraint{'v.name'} = $vname if defined $vname;
     81
     82my %set;
     83$set{'v.allocate'} = $allocate if defined $allocate;
     84$set{'v.available'} = $available if defined $available;
     85$set{'v.xattr'} = $xattr if defined $xattr;
     86
     87if (%set) {
     88    my ($q, @bind) = sql_interp("UPDATE volume AS v SET", \%set, "WHERE", \%constraint);
     89    warn "$q\n" if $debug;
     90    my $query = $dbh->prepare($q);
     91    $query->execute(@bind);
     92}
     93
    5394my $sql = Nebulous::Server::SQL->new();
    54 
    55 my %constraint;
    56 $constraint{host} = $vhost if defined $vhost;
    57 $constraint{name} = $vname if defined $vname;
    58 
    59 my $select = sql_inerp($sql->get_volumes . " WHERE", \%constraint);
    60 
    61 my $query = $dbh->prepare($select);
    62 $query->execute();
     95my ($q, @bind);
     96if (%constraint) {
     97    ($q, @bind) = sql_interp($sql->get_volumes . "WHERE", \%constraint);
     98} else {
     99    $q = $sql->get_volumes;
     100}
     101
     102warn "$q\n" if $debug;
     103my $query = $dbh->prepare($q);
     104$query->execute(@bind);
     105
     106my $format  = "%-15s %-15s %-10s %-10s %-10s %-10s\n";
     107my @columns = qw(host name mounted allocate available xattr);
     108printf($format, @columns);
     109
     110while (my $row = $query->fetchrow_hashref) {
     111    printf($format, @$row{@columns});
     112}
    63113
    64114__END__
     
    68118=head1 NAME
    69119
    70 neb-addvol - add a storage volume to a Nebulous server
     120neb-voladm - manage Nebulous server storage volumes
    71121
    72122=head1 SYNOPSIS
Note: See TracChangeset for help on using the changeset viewer.