AFS-Command
view release on metacpan or search on metacpan
lib/AFS/Command/VOS.pm view on Meta::CPAN
#
# $Id$
#
# (c) 2003-2004 Morgan Stanley and Co.
# See ..../src/LICENSE for terms of distribution.
#
package AFS::Command::VOS;
use strict;
use English;
use AFS::Command::Base;
use AFS::Object;
use AFS::Object::VLDB;
use AFS::Object::VLDBEntry;
use AFS::Object::VLDBSite;
use AFS::Object::Volume;
use AFS::Object::VolumeHeader;
use AFS::Object::VolServer;
use AFS::Object::FileServer;
use AFS::Object::Partition;
use AFS::Object::Transaction;
our @ISA = qw(AFS::Command::Base);
our $VERSION = '1.99';
sub examine {
my $self = shift;
my (%args) = @_;
my $result = AFS::Object::Volume->new();
my $entry = AFS::Object::VLDBEntry->new( locked => 0 );
$self->{operation} = "examine";
return unless $self->_parse_arguments(%args);
return unless $self->_save_stderr();
my $errors = 0;
$errors++ unless $self->_exec_cmds();
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
#
# These two lines are part of the verbose output
#
next if /Fetching VLDB entry/;
next if /Getting volume listing/;
#
# This code parses the volume header information. If we match
# this line, then we go after the information we expect to be
# right after it. We also test for this first, because we
# might very well have several of these chunks of data for RO
# volumes.
#
if ( /^\*{4}/ ) {
my $header = AFS::Object::VolumeHeader->new();
if ( /Volume (\d+) is busy/ ) {
$header->_setAttribute
(
id => $1,
status => 'busy',
attached => 1,
);
} elsif ( /Could not attach volume (\d+)/ ) {
$header->_setAttribute
(
id => $1,
status => 'offline',
attached => 0,
);
}
$result->_addVolumeHeader($header);
next;
} elsif ( /^(\S+)\s+(\d+)\s+(RW|RO|BK)\s+(\d+)\s+K/ ) {
my $header = AFS::Object::VolumeHeader->new();
if ( /^(\S+)\s+(\d+)\s+(RW|RO|BK)\s+(\d+)\s+K\s+([\w-]+)/ ) {
$header->_setAttribute
(
lib/AFS/Command/VOS.pm view on Meta::CPAN
author => $author,
);
}
$result->_addVolumeHeader($header);
next;
}
#
# The rest of the information we get will be from the
# VLDB. This will start with the volume ids, which we DO want
# to check against those found above, since they are from a
# different source, and a conflict is cause for concern.
#
if ( /^\s+RWrite:\s+(\d+)/ ) {
if ( /RWrite:\s+(\d+)/ ) { $entry->_setAttribute( rwrite => $1 ); }
if ( /ROnly:\s+(\d+)/ ) { $entry->_setAttribute( ronly => $1 ); }
if ( /Backup:\s+(\d+)/ ) { $entry->_setAttribute( backup => $1 ); }
if ( /RClone:\s+(\d+)/ ) { $entry->_setAttribute( rclone => $1 ); }
next;
} # if ( /^\s+RWrite:....
#
# Next we are looking for the number of sites, and then we'll
# suck that data in as well.
#
# NOTE: Because there is more interesting data after the
# locations, we fall through to the next test once we are done
# parsing them.
#
if ( /^\s+number of sites ->\s+(\d+)/ ) {
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
last unless m:^\s+server\s+(\S+)\s+partition\s+(/vicep\w+)\s+([A-Z]{2})\s+Site\s*(--\s+)?(.*)?:;
my $site = AFS::Object::VLDBSite->new
(
server => $1,
partition => $2,
type => $3,
status => $5,
);
$entry->_addVLDBSite($site);
}
}
#
# Last possibility (that we know of) -- volume might be
# locked.
#
if ( /LOCKED/ ) {
$entry->_setAttribute( locked => 1 );
next;
}
#
# Actually, this is the last possibility... The volume name
# leading the VLDB entry stanza.
#
if ( /^(\S+)/ ) {
$entry->_setAttribute( name => $1 );
}
}
$result->_addVLDBEntry($entry);
$errors++ unless $self->_reap_cmds();
$errors++ unless $self->_restore_stderr();
return if $errors;
return $result;
}
sub listaddrs {
my $self = shift;
my (%args) = @_;
my @result = ();
$self->{operation} = "listaddrs";
return unless $self->_parse_arguments(%args);
return unless $self->_save_stderr();
my $errors = 0;
$errors++ unless $self->_exec_cmds();
if ( $args{printuuid} ) {
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
if ( /^UUID:\s+(\S+)/ ) {
my $fileserver = AFS::Object::FileServer->new( uuid => $1 );
my @addresses = ();
my $hostname = "";
while ( defined($_ = $self->{handle}->getline()) ) {
s/^\s*//g;
s/\s*$//g;
last if /^\s*$/;
chomp;
if ( /^\d+\.\d+\.\d+\.\d+$/ ) {
lib/AFS/Command/VOS.pm view on Meta::CPAN
}
}
$errors++ unless $self->_reap_cmds();
$errors++ unless $self->_restore_stderr();
return if $errors;
return @result;
}
sub listpart {
my $self = shift;
my (%args) = @_;
my $result = AFS::Object::FileServer->new();
$self->{operation} = "listpart";
return unless $self->_parse_arguments(%args);
return unless $self->_save_stderr();
my $errors = 0;
$errors++ unless $self->_exec_cmds();
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
next unless m:/vice:;
s/^\s+//g;
s/\s+$//g;
foreach my $partname ( split ) {
my $partition = AFS::Object::Partition->new( partition => $partname );
$result->_addPartition($partition);
}
}
$errors++ unless $self->_reap_cmds();
$errors++ unless $self->_restore_stderr();
return if $errors;
return $result;
}
sub listvldb {
my $self = shift;
my (%args) = @_;
$self->{operation} = "listvldb";
my $locked = 0;
my $result = AFS::Object::VLDB->new();
return unless $self->_parse_arguments(%args);
return unless $self->_save_stderr();
my $errors = 0;
$errors++ unless $self->_exec_cmds();
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
next if /^\s*$/; # If it starts with a blank line, then
# its not a volume name.
#
# Skip the introductory lines of the form:
# "VLDB entries for all servers"
# "VLDB entries for server ny91af01"
# "VLDB entries for server ny91af01 partition /vicepa"
#
next if /^VLDB entries for /;
s/\s+$//g; # Might be trailing whitespace...
#
# We either get the total number of volumes, or we assume the
# line is a volume name.
#
if ( /Total entries:\s+(\d+)/ ) {
$result->_setAttribute( total => $1 );
next;
}
my $name = $_;
my $entry = AFS::Object::VLDBEntry->new( name => $name );
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
last if /^\s*$/; # Volume info ends with a blank line
#
# Code to parse this output lives in examine.pl. This
# will need to be made generic and used here to parse and
# return the full vldb entry.
#
if ( /RWrite:\s+(\d+)/ ) { $entry->_setAttribute( rwrite => $1 ); }
if ( /ROnly:\s+(\d+)/ ) { $entry->_setAttribute( ronly => $1 ); }
if ( /Backup:\s+(\d+)/ ) { $entry->_setAttribute( backup => $1 ); }
if ( /RClone:\s+(\d+)/ ) { $entry->_setAttribute( rclone => $1 ); }
if ( /^\s+number of sites ->\s+(\d+)/ ) {
my $sites = $1;
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
next unless m:^\s+server\s+(\S+)\s+partition\s+(/vicep\w+)\s+([A-Z]{2})\s+Site\s*(--\s+)?(.*)?:;
$sites--;
my $site = AFS::Object::VLDBSite->new
(
server => $1,
partition => $2,
type => $3,
status => $5,
);
$entry->_addVLDBSite( $site );
last if $sites == 0;
}
}
#
# Last possibility (that we know of) -- volume might be
# locked.
#
if ( /LOCKED/ ) {
$entry->_setAttribute( locked => 1 );
$locked++;
}
}
$result->_addVLDBEntry( $entry );
}
$result->_setAttribute( locked => $locked );
$errors++ unless $self->_reap_cmds();
$errors++ unless $self->_restore_stderr();
return if $errors;
return $result;
}
sub listvol {
my $self = shift;
my (%args) = @_;
my $result = AFS::Object::VolServer->new();
$self->{operation} = "listvol";
return unless $self->_parse_arguments(%args);
return unless $self->_save_stderr();
my $errors = 0;
$errors++ unless $self->_exec_cmds();
if ( delete $args{extended} ) {
$self->_Carp("vos listvol: -extended is not supported by this version of the API");
}
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
next if /^\s*$/; # Blank lines are not interesting
next unless /^Total number of volumes on server \S+ partition (\/vice[\w]+): (\d+)/;
my $partition = AFS::Object::Partition->new
(
partition => $1,
total => $2,
);
while ( defined($_ = $self->{handle}->getline()) ) {
chomp;
last if /^\s*$/ && $args{fast};
next if /^\s*$/;
s/\s+$//;
if ( /^Total volumes onLine (\d+) ; Total volumes offLine (\d+) ; Total busy (\d+)/ ) {
$partition->_setAttribute
(
online => $1,
( run in 2.194 seconds using v1.01-cache-2.11-cpan-d06a3f9ecfd )