# $Id: //depot/prod/test/nacldev/lib/NACL/CS/LunStats.pm#10 $ # # Copyright (c) 2001-2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary LunStats ComponentState Module ## @author benjaram@netapp.com anbumozh@netapp.com dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::LunStats =head1 DESCRIPTION C is a derived class of L. Returns object(s) of type L =head1 ATTRIBUTES This module does not represent the state of any element, but is an object repesentation of the output obtained when the lun stats is queried =over =item C<< "lun" >> Filled in for CMode CLI/ZAPI. This method extracts lun name from lun path for CMode ZAPI. =item C<< "tracks_per_cylinder" >> =item C<< "qtree" >> Filled in for CMode CLI/ZAPI. This method extracts qtree name from lun path for CMode ZAPI. =item C<< "sectors_per_cylinder" >> =item C<< "max_resize_size" >> =item C<< "sectors_per_track" >> =item C<< "sectors" >> =item C<< "cyl_size" >> =item C<< "size" >> =item C<< "volume" >> Filled in for CMode CLI/ZAPI. This method extracts volume name from lun path for CMode ZAPI. =item C<< "cylinders" >> =item C<< "bytes_per_sector" >> =item C<< "vserver" >> Filled in for CMode CLI/ZAPI. =item C<< "dev_size" >> =item C<< "path" >> Filled in for CMode CLI/ZAPI. =item C<< last_zeroed >> Filled in for CMode CLI/ZAPI. =item C<< write_data >> Filled in for CMode CLI. =item C<< read_data >> Filled in for CMode CLI. =item C<< read_blocks >> Filled in for CMode CLI/ZAPI. =item C<< read_ops >> Filled in for CMode CLI/ZAPI. =item C<< write_blocks >> Filled in for CMode CLI/ZAPI. =item C<< write_ops >> Filled in for CMode CLI/ZAPI. =item C<< block_size >> Filled in for CMode CLI/ZAPI. =item C<< other_ops >> Filled in for CMode CLI/ZAPI. =item C<< errors >> Filled in for CMode CLI/ZAPI. Maps to scsi-errors for CMode ZAPI. =back =cut package NACL::CS::LunStats; use strict; use warnings; use Params::Validate qw(validate); use NACL::ComponentUtils qw(_dump_one); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use NACL::Exceptions::NoElementsFound qw(:try); use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'vserver', scalar => 'path', scalar => 'volume', scalar => 'qtree', scalar => 'lun', scalar => 'block_size', scalar => 'read_blocks', scalar => 'write_blocks', scalar => 'read_ops', scalar => 'write_ops', scalar => 'other_ops', scalar => 'errors', scalar => 'last_zeroed', scalar => 'write_data', scalar => 'read_data', ]; =head1 METHODS =head2 fetch my $LunStats_state = NACL::CS::LunStats->fetch(command_interface => $ci, ...); my @LunStats_states = NACL::CS::LunStats->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 => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', }, { method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode', }, ], exception_text => 'No matching lun stats(s) found', show_cmd => 'lun stats', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_cmode_cli { $Log->enter() if $may_enter; my $pkg_or_obj = shift; my @state_objs = $pkg_or_obj->SUPER::_fetch_cmode_cli(@_, api => 'lun_stats'); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_cli sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my $pkg_or_obj = shift; my @state_objs = $pkg_or_obj->SUPER::_fetch_cmode_zapi( @_, api => 'lun_stats_get_iter', copy => [ qw ( vserver path block-size read-blocks write-blocks read-ops write-ops other-ops last-zeroed ) ], map => {'errors' => 'scsi-errors'}, ); foreach my $state (@state_objs) { if (defined $state->path()) { my %path_attributes; if ($state->path() =~ /\/vol\/(\w+)(\/\w+)?\/(\w+)/) { if (defined $3) { $path_attributes{volume} = $1; $path_attributes{qtree} = $2; $path_attributes{lun} = $3; } else { $path_attributes{volume} = $1; $path_attributes{lun} = $2; } } $state->_set_fields(row => \%path_attributes); } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi sub _fetch_7mode_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my %copy_filter = %{$opts{filter}}; my @copy_requested_fields = @{$opts{requested_fields}}; my $deleted_filter = $pkg->_remove_relational_regex_filters( filter => \%copy_filter, requested_fields => \@copy_requested_fields ); my $filter = \%copy_filter; my $requested_fields = \@copy_requested_fields; my $lun_response; my %lun_get_args; if (defined $filter->{path}) { $lun_get_args{'lun-path'} = $filter->{path}; } elsif (defined $filter->{volume} && defined $filter->{lun}) { $lun_get_args{'lun-path'} = '/vol/' . $opts{volume} . '/' . $opts{lun}; } if ($pkg->_want_any_field_of( requested_fields => $requested_fields, filter => $filter, fields_filled_by_api => [qw(other_ops)] ) ) { $lun_get_args{'lun-extended-statistics'} = 1; } ## end if ( $pkg->_want_any_field_of... # find all the lun present. $lun_response = $apiset->lun_stats(%lun_get_args); my $lun_output = $lun_response->get_parsed_output(); my @state_objs; foreach my $row (@{$lun_output}) { my $state_fields = $pkg->_hash_copy( source => $row, copy => [qw( path read_ops write_ops other_ops)], map => { "read_kbyte" => "read_blocks", "write_kbyte" => "write_blocks", }, ); $$state_fields{'block_size'} = '1024'; if ($$row{'path'} =~ /\/vol\/(\w+)\/(\w+)/) { $$state_fields{'volume'} = $1; $$state_fields{'lun'} = $2; } $$state_fields{'command_interface'} = $opts{'command_interface'}; my $obj = $pkg->new(command_interface => $opts{command_interface}); $obj->_set_fields(row => $state_fields); push @state_objs, $obj; } ## end foreach my $row ( @{$lun_output... $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli 1;