AIX-LVM
view release on metacpan or search on metacpan
Revision history for Perl extension AIX::LVM.
1.1 Fixed print commands and some comments
1.0 Fri Dec 31 23:21:40 2010
- original version;
AIX-LVM version 1.0
====================
This Module is a Perl wrapper for AIX LVM and provides access to
the properties of Volume groups, Logial Volumes, Physical Volumes,
Physical Partitions. This providesaccess to LVM command equivalents.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
lib/AIX/LVM.pm view on Meta::CPAN
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 ####
lib/AIX/LVM.pm view on Meta::CPAN
$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;
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();
lib/AIX/LVM.pm view on Meta::CPAN
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;
lib/AIX/LVM.pm view on Meta::CPAN
my @pvs = $lvm->get_physical_volumes(); #List all the Physical volumes present.
my @lvs = $lvm->get_logical_volumes(); #List all the Physical volumes present.
#%vg_props consist of all the volume group properties in key=>value format.
my %vg_props = $lvm->get_volume_group_properties("rootvg");
#%lv_props consist of all the properties for logical volume "x" under volume group "rootvg";
my %lv_props = $lvm->get_logical_volume_properties("rootvg","x");
my $lslv_l_cmd = $lvm->get_LV_logical_command("rootvg","x") #Equivalent to lslv -l x
my $lslv_m_cmd = $lvm->get_LV_M_command("rootvg","x") #Equivalent to lslv -m x
=head1 DESCRIPTION
This Module is a Perl wrapper for AIX LVM and provides access to the properties
of Volume groups, Logial Volumes, Physical Volumes, Physical Partitions. This provides
access to LVM command equivalents.
=head1 METHODS
=over 4
=item get_logical_volume_group();
Returns an array of volume groups present.
=item get_physical_volumes();
lib/AIX/LVM.pm view on Meta::CPAN
Returns a hash of properties for volume group "rootvg"
=item get_logical_volume_properties("rootvg","hd5")
Returns a hash of properties for logical volume "hd5" present under volume group "rootvg"
=item get_physical_volume_properties("rootvg","hdisk0")
Returns a hash of properties for physical volume "hdisk0" present under volume group "rootvg"
=item get_LV_logical_command("rootvg","hd5")
Returns output as scalar for command equivalent of lslv -l hd5
=item get_LV_ M_command("rootvg","hd5")
Returns output as scalar for command equivalent of lslv -m hd5
=item get_PV_PP_command("rootvg","hdisk0")
Returns output as scalar for command equivalent of lspv -p hd5
=item get_PV_LV_command("rootvg","hdisk0")
Returns output as scalar for command equivalent of lspv -l hd5
=head1 CAVEATS
Needed to be executed as root user.
VG IDENTIFIER property for physical volume doesn't have proper format i.e Missing : at the end.
This may differ for different versions of AIX.
=head1 SEE ALSO
t/AIX-LVM.t view on Meta::CPAN
use AIX::LVM;
#########################
@methods = (
"get_logical_volume_group",
"get_physical_volumes",
"get_logical_volumes",
"get_volume_group_properties",
"get_logical_volume_properties",
"get_physical_volume_properties",
"get_PV_PP_command",
"get_PV_LV_command",
"get_LV_logical_command",
"get_LV_M_command"
);
foreach my $meth (@methods) {
can_ok('AIX::LVM', $meth);
}
SKIP: {
skip "Environment is not AIX", 6 if $^O!~/aix/i;
eval {
$lvm = new AIX::LVM;
};
( run in 1.492 second using v1.01-cache-2.11-cpan-d8267643d1d )