IBM-StorageSystem

 view release on metacpan or  search on metacpan

lib/IBM/StorageSystem/Enclosure.pm  view on Meta::CPAN

        $args{id} or croak 'Constructor failed: mandatory id argument not supplied';
	weaken( $self->{__ibm} = $ibm );

        foreach my $attr ( @ATTR ) { $self->{$attr} = $args{$attr} }

        return $self
}

foreach my $obj ( keys %{ $OBJ } ) {
	{
		no strict 'refs';
		my $m = 'get_'.$obj.'s';

		*{ __PACKAGE__ ."::$obj" } = sub {
			my( $self, $id ) = @_;
			defined $id or return;
			return ( $self->{$obj}->{$id} ? $self->{$obj}->{$id} : $self->$m( $id ) )
		};
		
		*{ __PACKAGE__ .'::get_'. $obj } = sub { return $_[0]->$m( $_[1] ) };

		*{ __PACKAGE__ ."::$m" } = sub {
			my( $self, $id ) = @_;

			my @objects = map { ( split /:/, $_ )[1] . " $self->{id}" } 
				      split /\n/, $self->{__ibm}->__cmd( $OBJ->{$obj}->{bcmd} ." $self->{id}" );

			my %a = ( objects => [@objects], cmd => $OBJ->{$obj}->{cmd}, class => $OBJ->{$obj}->{class}, nocache => 1 );

			@objects = $self->{__ibm}->__get_ml_objects( %a );

			foreach my $object ( @objects ) { $self->{ $OBJ->{$obj}->{type} }->{ $object->{ $OBJ->{$obj}->{id} } } = $object }

			return ( defined $id ? $self->{ $OBJ->{$obj}->{type} }->{$id} : @objects )
		}
	}
}

1;

__END__

=pod

=head1 NAME

IBM::StorageSystem::Enclosure - Class for operations with a IBM Storwize enclosure

=head1 VERSION

Version 0.01

=head1 SYNOPSIS

IBM::StorageSystem is a utility class for operation with an IBM Storwize enclosure.

	use IBM::StorageSystem;
	
	my $ibm = IBM::StorageSystem->new(	user		=> 'admin',
					host		=> 'my-v7000',
					key_path	=> '/path/to/my/.ssh/private_key'
				) or die "Couldn't create object! $!\n";
	
	# Print the status of each enclosure in our system.
	foreach my $enclosure ( $ibm->get_enclosures ) {
		print "Enclosure ", $enclosure->id, " status: ", $enclosure->status, "\n"
	}

	# Print the status of a specific enclosure
	print "Enclosure two status is " . $ibm->enclosure(2)->status . "\n";

	# Get all PSUs in an enclosure as L<IBM::StorageSystem::Enclosure::PSU> objects.
	my @psus = $ibm->enclosure(1)->psus;

	# Plus much more

=head1 METHODS

=head3 new 

Constructor method - note that under normal circumstances you shouldn't need to explicitly call 
this method - rather a L<IBM::StorageSystem::Enclosure> object is created for you via calls to methods
in other classes like B<get_enclosure> in L<IBM::StorageSystem>.

=head3 psu( $id )

	# Get the first PSU of the first enclosure and print the redundancy status
	my $enclosure = $ibm->enclosure(1);
	my $psu = $enclosure->psu(1);
	print $psu->redundant;

	# Alternately
	print $ibm->enclosure(1)->psu(1)->redundant;

Returns the PSU as specified by the value of the id parameter as a L<IBM::StorageSystem::Enclosure::PSU>
object.  

Note that this method implements object caching when possible - please refer to the B<Caching>
section in the L<IBM::StorageSystem> documentation for further detail.

=head3 get_psu( $id )

	my $psu = $enclosure->get_psu(2);

Returns the PSU as specified by the value of the id parameter as a L<IBM::StorageSystem::Enclosure::PSU>
object.

=head3 get_psus

	my @psus = $enclosure->get_psus;

Returns an all PSUs in the specified enclosure as an array of L<IBM::StorageSystem::Enclosure::PSU> objects.

=head3 battery( $id )

	# Print the percentage charged status of the first battery in the second enclosure
	print $ibm->enclosure(2)->battery(1)->percent_charged;

Returns the enclosure battery as specified by the value of the given id parameter as a 
L<IBM::StorageSystem::Enclosure::Battery> object.



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