#Id$: //depot/prod/test/nacldev/lib/NACL/CS/MagneticTape.pm# $ # # Copyright (c) 2001-2010 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary MagneticTape ComponentState Module ## @author dl-dpg-nb-automation, dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::MagneticTape =head1 DESCRIPTION C is a derived class of L. It represents the status of Magnetic Tapes attached to the filer. A related class is L, which represents access to a Magnetic Tape device on a Filer. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Magnetic Tapes are the attributes of the MagneticTape ComponentState. =over =item C<< tape_name >> The name of the Magnetic Tape alias element represented =item C<< tape_drive >> The model of the tape drive =item C<< device_type >> The tape device type =item C<< slot >> The slot on the storage system that the tape drive is attached to =item C<< scsi_id >> The SCSI id number =item C<< status >> Whether the tape drive is ready and write-enabled =item C<< format >> The number of bytes per inch, total capacity in gigabytes, and whether data compression is used =item C<< file_number >> The current tape file number; numbering starts at 0 =item C<< block_number >> The current block number =item C<< resid >> The number of bytes that the drive attempted to write or read but could not because the end of tape was reached =back =cut package NACL::CS::MagneticTape; use strict; use warnings; use Params::Validate qw(validate); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use base 'NACL::CS::ComponentState::ONTAP'; #defining class methodmaker for all the attribute that is all the keys of the parsed output use Class::MethodMaker [ scalar => 'tape_name', scalar => 'tape_drive', scalar => 'device_type', scalar => 'slot', scalar => 'scsi_id', scalar => 'status', scalar => 'format', scalar => 'fileno', scalar => 'blockno', scalar => 'resid', ]; =head1 METHODS =head2 fetch my $MagneticTape_state = NACL::CS::MagneticTape->fetch(command_interface => $ci, ...); my @MagneticTape_states = NACL::CS::MagneticTape->fetch(command_interface => $ci, ...); (Class method) Discovers which elements are present and returns their state in ComponentState objects. Called in scalar context it returns only one state object, in list context it returns all state objects. See L for a more detailed description along with a complete explanation of the options it accepts. =over =item Exceptions =over =item C When there are no elements matching the query specified or elements of that type doesn't exist, then this exception will be thrown. =back =back =cut sub fetch { $Log->enter() if $may_enter; my $pkg = shift; my @state_objs = $pkg->SUPER::fetch( @_, choices => [ { #Command for MagneticTape management i.e. mt is #available in 7Mode and Nodescope method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode|Nodescope', }, ], exception_text => 'No matching magnetic tape(s) found' ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } sub _fetch_7mode_cli { $Log->enter() if $may_enter; my $pkg = shift; my ( $sysconfig_output, @status_output, $caught_exception, %api_args ); my ( $tape_alias, $tape_nm, %tape_device, $num_non_qualified ); my ( $status_response, $sysconfig_response ); my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; # applying filter so that we can retrieve tape status for a # particular tape name #invoking appropiate API $sysconfig_response = $apiset->sysconfig( "tape-drive" => 1 ); #retrieve the parsed output $sysconfig_output = $sysconfig_response->get_parsed_output(); #Getting the status for each tape alias. foreach $tape_alias (@$sysconfig_output) { #invoking appropiate API if ( exists( $tape_alias->{'non_qualified'} ) ) { $num_non_qualified++; next; } $status_response = $apiset->mt( 'tape-device-switch2' => 1, 'tape-name' => $tape_alias->{'device_info'}->[0]->{'name'}, 'status' => 1 ); #retrieve the parsed output $status_output[ $#status_output + 1 ] = $status_response->get_parsed_output(); } #Checking if number of non-qualified tape devices found are equal to number of tapes #on the filer. If both are equal, just return. if ( defined $num_non_qualified && $num_non_qualified == @$sysconfig_output ) { $Log->exit() if $may_exit; return; } my @state_objs; my $i; $i = 0; #reading sysconfig parsed output foreach $tape_alias (@$sysconfig_output) { foreach $tape_nm ( @{ $tape_alias->{'device_info'} } ) { my $obj = $pkg->new( command_interface => $opts{command_interface} ); my $state_fields; my %tape_device_info = %{$tape_nm}; # Renaming 'name' to 'tape_name' $tape_device_info{tape_name} = delete $tape_device_info{name}; #Copying scsi_id and slot information from "sysconfig -t" #output to the new object hash $obj->_hash_copy( source => $tape_alias, copy => [qw(scsi_id slot)], target => \%tape_device_info, ); #Copying "mt -t status" output to the new object hash $obj->_hash_copy( source => $status_output[$i]->[0], copy => [qw(tape_drive status blockno fileno resid)], target => \%tape_device_info, ); #creating a object $obj->_set_fields( row => \%tape_device_info ); # push the above created object to an array push @state_objs, $obj; } $i++; } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli 1;