AIX-LVM
view release on metacpan or search on metacpan
lib/AIX/LVM.pm view on Meta::CPAN
my $self = {};
bless $self, $class;
return $self->init(@_);
}
sub init
{
my $self = shift;
my ($result, %lslv, %lspv, %lsvg, @lslv, @lsvg, @lspv);
my ($lsvg, $lsvg_error) = $self->_exec_open3("lsvg -o");
croak "Error found during execution of lsvg -o: $lsvg_error\n" if $lsvg_error;
@lsvg = $self->_splitter($lsvg, qr'\n+');
foreach my $lvg (@lsvg) {
$self->{$lvg}= $self->_get_lv_pv_props($lvg); #Hierarchy is lsvg -> lslv and lspv
}
return $self;
}
sub get_logical_volume_group
{
lib/AIX/LVM.pm view on Meta::CPAN
#### Private methods ####
# This subroutine is used to populate LV Values, PV Values and Properties of Volume Groups
sub _get_lv_pv_props
{
my $self = shift;
my $lvg = shift;
croak "Logical volume group is not found\n" unless $lvg;
my (@lv, @pv, %lvg_hash);
my ($lslv, $lslv_error) = $self->_exec_open3("lsvg -l $lvg"); # Populate LV Values
croak "Error found during execution of lsvg -l $lvg: $lslv_error\n" if $lslv_error;
my @lslv = $self->_splitter($lslv, qr'\n+');
foreach my $lslv_l (@lslv[2..$#lslv]) {
push @lv, $1 if ($lslv_l=~/^(\S+)/);
}
foreach my $lv (@lv) {
$lvg_hash{lvol}->{$lv}= $self->_get_lslv_l_m_prop($lv);
}
my ($lspv, $lspv_error) = $self->_exec_open3("lsvg -p $lvg"); # Populate PV Values
croak "Error found during execution of lsvg -p $lvg: $lspv_error\n" if $lspv_error;
my @lspv = $self->_splitter($lspv, qr'\n+');
foreach my $lspv_l (@lspv[2..$#lspv]) {
push @pv, $1 if ($lspv_l=~/^(\S+)/);
}
foreach my $pv (@pv) {
$lvg_hash{pvol}->{$pv}= $self->_get_lspv_l_m_prop($pv);
}
my ($prop, $prop_error) = $self->_exec_open3("lsvg $lvg"); # Populate Properties
croak "Error found during execution of lsvg $lvg: $prop_error\n" if $prop_error;
$lvg_hash{prop} = $self->_parse_properties($prop, @lsvg_prop);
return \%lvg_hash;
}
# This subroutine is used to populate LV Logical Values, LV Physical Values and Properties of Logical Volumes
sub _get_lslv_l_m_prop
{
my $self = shift;
my $lv = shift;
croak "Logical volume is not found\n" unless $lv;
my (@lv, @pv, %lslv);
my ($lslv, $lslv_error) = $self->_exec_open3("lslv -l $lv"); # Populate LV Logical Values
croak "Error found during execution of lslv -l $lv: $lslv_error\n" if $lslv_error;
$lslv{"LV_LOGICAL_CMD_OUT"} = $lslv;
my ($lspv, $lspv_error) = $self->_exec_open3("lslv -m $lv"); # Populate LV Mirror Values
croak "Error found during execution of lslv -m $lv: $lspv_error\n" if $lspv_error;
$lslv{"LV_MIRROR_CMD_OUT"} = $lspv;
my ($prop, $prop_error) = $self->_exec_open3("lslv $lv"); # Populate LV Properties
croak "Error found during execution of lslv $lv: $prop_error\n" if $prop_error;
$lslv{prop} = $self->_parse_properties($prop, @lslv_prop);
return \%lslv;
}
# # This subroutine is used to populate PV Logical Values, PV PP Values and Properties of Physical Volumes
sub _get_lspv_l_m_prop
{
my $self = shift;
my $pv = shift;
croak "Physical volume is not found\n" unless $pv;
my (@lv, @pv, %lspv);
my ($lslv, $lslv_error) = $self->_exec_open3("lspv -l $pv"); # Populate PV Logical Values
croak "Error found during execution of lspv -l $pv: $lslv_error\n" if $lslv_error;
$lspv{"PV_LOGICAL_CMD_OUT"} = $lslv;
my ($lspv, $lspv_error) = $self->_exec_open3("lspv -M $pv"); # Populate PV in LV Values
croak "Error found during execution of lspv -M $pv: $lspv_error\n" if $lspv_error;
$lspv{"PV_LV_CMD_OUT"} = $lspv;
my ($lspp, $lspp_error) = $self->_exec_open3("lspv -p $pv"); # Populate PV Physical Partitions Values
croak "Error found during execution of lspv -p $pv: $lspp_error\n" if $lspp_error;
$lspv{"PV_PP_CMD_OUT"} = $lspp;
my ($prop, $prop_error) = $self->_exec_open3("lspv $pv"); # Populate PV Properties
croak "Error found during execution of lspv $pv: $prop_error\n" if $prop_error;
$lspv{prop} = $self->_parse_properties($prop, @lspv_prop);
return \%lspv;
}
# This subroutine performs parsing the output of the commands for passed array values.
sub _parse_properties
{
my $self = shift;
my $prop = shift;
lib/AIX/LVM.pm view on Meta::CPAN
}
}
return \%prop;
}
# This subroutine is used to execute the commands using open3 to capture Error stream.
sub _exec_open3
{
my $self = shift;
my ($result, $error);
my $writer_h = new IO::Handle;
my $reader_h = new IO::Handle;
my $error_h = new IO::Handle;
my $pid = open3($writer_h, $reader_h, $error_h, @_) or croak "Not able to open3: $! \n";
$reader_h->autoflush();
$error_h->autoflush();
my $selector = IO::Select->new();
$selector->add($reader_h, $error_h); ## Add the handlers to select call ##
while( my @ready = $selector->can_read ){
foreach my $fh ( @ready ){
if( fileno($fh) == fileno($reader_h) ){
my $ret = $reader_h->sysread($_, 1024);
$result .= $_;
$selector->remove($fh) unless $ret;
}
if( fileno($fh) == fileno($error_h) ){
my $ret = $error_h->sysread($_, 1024);
$error .= $_;
$selector->remove($fh) unless $ret;
}
}
}
$reader_h->autoflush();
$error_h->autoflush();
waitpid $pid, 0;
my $rc = $? >> 8;
carp "Error in executing the command\n" if ($rc);
return $result, $error;
}
# Splitter based on pattern
sub _splitter
{
my $self = shift;
my ($string, $pat) = (shift, shift);
return split /$pat/, $string;
}
t/AIX-LVM.t view on Meta::CPAN
SKIP: {
skip "Environment is not AIX", 6 if $^O!~/aix/i;
eval {
$lvm = new AIX::LVM;
};
isa_ok($lvm,"AIX::LVM");
ok(!$@,"Loaded Module AIX::LVM") or diag("Error is $@") ;
isa_ok( $lvm, "AIX::LVM" );
SKIP: {
skip "Module itself have errors", 3 if $@;
ok(grep(/rootvg/,$lvm->get_logical_volume_group),"Get Volume Groups");
ok(scalar($lvm->get_physical_volumes), "Physical Volume Presence");
ok(scalar($lvm->get_logical_volumes), "Logical Volume Presence");
}
}
( run in 1.410 second using v1.01-cache-2.11-cpan-49f99fa48dc )