AIX-LVM

 view release on metacpan or  search on metacpan

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

					"VG DESCRIPTORS:",
					"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+)/);
	}
	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 



( run in 1.978 second using v1.01-cache-2.11-cpan-d80b1682f3f )