AIX-LVM
view release on metacpan or search on metacpan
lib/AIX/LVM.pm view on Meta::CPAN
"FREE PPs:",
"HOT SPARE:",
"USED PPs:",
"MAX REQUEST:",
"FREE DISTRIBUTION:",
"USED DISTRIBUTION:",
"MIRROR POOL:"
);
sub new
{
my $class = shift;
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
{
my $self = shift;
return sort keys %{$self};
}
sub get_logical_volumes
{
my $self = shift;
return map {keys %{$self->{$_}->{lvol}}}keys %{$self};
}
sub get_physical_volumes
{
my $self = shift;
return map {keys %{$self->{$_}->{pvol}}}keys %{$self};
}
sub get_volume_group_properties
{
my $self = shift;
my $vg = shift;
croak "Pass values for Volume Group\n" unless $vg;
exists $self->{$vg}->{prop}? %{$self->{$vg}->{prop}}:undef;
}
sub get_logical_volume_properties
{
my $self = shift;
my ($vg, $lv) = (shift, shift);
croak "Pass values for Volume Group\n" unless $vg;
croak "Pass values for Logical Volume Group\n" unless $lv;
exists $self->{$vg}->{lvol}->{$lv}->{prop}? %{$self->{$vg}->{lvol}->{$lv}->{prop}} : undef;
}
sub get_physical_volume_properties
{
my $self = shift;
my ($vg, $pv) = (shift, shift);
croak "Pass values for Volume Group\n" unless $vg;
croak "Pass values for Physical Volume Group\n" unless $pv;
exists $self->{$vg}->{pvol}->{$pv}->{prop}? %{$self->{$vg}->{pvol}->{$pv}->{prop}} : undef;
}
sub get_PV_PP_command
{
my $self = shift;
my ($vg, $pv) = (shift, shift);
croak "Pass values for Volume Group\n" unless $vg;
croak "Pass values for Physical Volume Group\n" unless $pv;
exists $self->{$vg}->{pvol}->{$pv}->{PV_PP_CMD_OUT}? $self->{$vg}->{pvol}->{$pv}->{PV_PP_CMD_OUT} : undef;
}
sub get_PV_LV_command
{
my $self = shift;
my ($vg, $pv) = (shift, shift);
croak "Pass values for Volume Group\n" unless $vg;
croak "Pass values for Physical Volume Group\n" unless $pv;
exists $self->{$vg}->{pvol}->{$pv}->{PV_LV_CMD_OUT}? $self->{$vg}->{pvol}->{$pv}->{PV_LV_CMD_OUT} : undef;
}
sub get_LV_logical_command
{
my $self = shift;
my ($vg, $lv) = (shift, shift);
croak "Pass values for Volume Group\n" unless $vg;
croak "Pass values for Logical Volume Group\n" unless $lv;
exists $self->{$vg}->{lvol}->{$lv}->{LV_LOGICAL_CMD_OUT}? $self->{$vg}->{lvol}->{$lv}->{LV_LOGICAL_CMD_OUT} : undef;
}
sub get_LV_M_command
{
my $self = shift;
my ($vg, $lv) = (shift, shift);
croak "Pass values for Volume Group\n" unless $vg;
croak "Pass values for Logical Volume Group\n" unless $lv;
exists $self->{$vg}->{lvol}->{$lv}->{LV_MIRROR_CMD_OUT}? $self->{$vg}->{lvol}->{$lv}->{LV_MIRROR_CMD_OUT} : undef;
}
#### 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+)/);
lib/AIX/LVM.pm view on Meta::CPAN
$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;
lib/AIX/LVM.pm view on Meta::CPAN
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;
my @defp = @_;
my %prop;
foreach my $defp (@defp) {
my $str = join '|', grep {"$_" ne $defp} @defp;
if ($prop=~/\Q$defp\E([^\n]*?)($str|\n|$)/s) {
my $value = $1;
$value =~s/^\s+|\s+$//g;
$prop{$defp} = $value;
} else {
carp "Property $defp not have value. Probably due to inconsistent identifier output\n";
}
}
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();
lib/AIX/LVM.pm view on Meta::CPAN
$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;
}
__END__
( run in 0.250 second using v1.01-cache-2.11-cpan-4d50c553e7e )