AIX-LVM

 view release on metacpan or  search on metacpan

lib/AIX/LVM.pm  view on Meta::CPAN

	$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;
	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();
    $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;
}


__END__


=head1 NAME

AIX::LVM - Perl extension to handle AIX LVM Structure.

=head1 SYNOPSIS

  use AIX::LVM;

   my $lvm = AIX::LVM->new;

   my @volume_group = $lvm->get_logical_volume_group(); #List all the Volume groups present.

   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



( run in 1.772 second using v1.01-cache-2.11-cpan-39bf76dae61 )