# $Id: //depot/prod/DOT/dev/test/lib/NACL/CS/AggregateSnapshot.pm#2 $ # # Copyright (c) 2001-2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary AggregateSnapshot ComponentState Module ## @author sangavai@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::AggregateSnapshot =head1 DESCRIPTION C is a derived class of L. It represents the state of ONTAP AggregateSnapshot. A related class is L, which represents access to ONTAP volume snapshot. It supports 7-Mode CLI and Nodescope CLI for C-Mode. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the AggregateSnapshot element are the attributes of the AggregateSnapshot ComponentState. =over =item C<< name >> =item C<< snapshot >> =item C<< aggregate >> =item C<< fsrev >> =item C<< ownblks >> =item C<< usedblocks >> =item C<< date >> =item C<< status >> =item C<< owners >> =item C<< snapid >> =item C<< release >> =item C<< blocks >> =back =cut package NACL::CS::AggregateSnapshot; 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 NACL::APISet::Exceptions::InvalidParamValueException qw(:try); use NACL::ComponentUtils qw(Dumper); use base 'NACL::CS::ComponentState::ONTAP'; use NACL::C::UnitNormalization; use Class::MethodMaker [ scalar => 'name', scalar => 'snapshot', scalar => 'aggregate', scalar => 'fsrev', scalar => 'ownblks', scalar => 'date', array => 'owners', scalar => 'status', scalar => 'release', scalar => 'snapid', scalar => 'blocks', scalar => 'usedblocks', scalar => 'snap_date', scalar => 'retention_date', ]; =head1 METHODS =head2 fetch my $AggregateSnapshot_state = NACL::CS::AggregateSnapshot->fetch(command_interface => $ci, ...); my @AggregateSnapshot_states = NACL::CS::AggregateSnapshot->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_7mode_cli', interface => 'CLI', set => '7Mode|Nodescope', }, ], exception_text => 'No snapshot(s) exist' ); $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 %opts = validate @_, $pkg->_fetch_backend_validate_spec(); 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 $req_field_filter; $req_field_filter->{'requested_fields'} = $requested_fields; $req_field_filter->{'filter'} = \%copy_filter; my $apiset = $opts{apiset}; my ($snap_status_response, $snap_list_b_response, $snap_list_l_response, $snap_list_response, $caught_exception ); my %snap_status; $snap_status{'aggregate-name'} = $req_field_filter->{'filter'}->{'aggregate'}; $snap_status{aggregate} = 1; my %snap_status_normal = %snap_status; if (!$pkg->_want_any_field_of(%{$req_field_filter}, fields_filled_by_api => [ qw(blocks usedblocks) ])) { $snap_status_normal{'no-snapshot-space-consumption'} = 1; } try { $snap_list_response = $apiset->snap_list(%snap_status_normal); } catch NACL::APISet::Exceptions::InvalidParamValueException with { $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } if ($pkg->_want_any_field_of(%{$req_field_filter}, fields_filled_by_api => [ qw(owners) ])) { $snap_list_b_response = $apiset->snap_list(%snap_status, busy => 1); } if ($pkg->_want_any_field_of(%{$req_field_filter}, fields_filled_by_api => [ qw(snapid status ownblks fsrev release date) ])) { $snap_status_response = $apiset->snap_status(%snap_status); } my @state_objs; my $flag = 0; my ($snap_status_output, $snap_list_output, $snap_list_b_output); if(defined ($snap_status_response)) { $snap_status_output = $snap_status_response->get_parsed_output(); } if(defined ($snap_list_response)) { $snap_list_output = $snap_list_response->get_parsed_output(); } if(defined ($snap_list_b_response)) { $snap_list_b_output = $snap_list_b_response->get_parsed_output(); } for ( my $row = 0; $row < @$snap_list_output; $row++ ) { my (@snap_status, @snap_list, @snap_list_b); if(defined ($snap_status_output)) { @snap_status = @{ $snap_status_output->[$row]->{snapshot_status} }; } if(defined ($snap_list_output)) { @snap_list = @{ $snap_list_output->[$row]->{snapshot_info} }; } if(defined ($snap_list_b_output)) { @snap_list_b = @{ $snap_list_b_output->[$row]->{snapshot_info} }; } for ( my $status = 0; $status < @snap_list; $status++ ) { if ((defined $filter->{snapshot}) && ($req_field_filter->{'filter'}->{'snapshot'} eq $snap_list[$status]->{'name'})) { $flag = 1; } my %temp_attributes; if(!defined ($snap_status[$status])) { foreach my $value ('snapid', 'status', 'ownblks', 'fsrev', 'release', 'date') { $snap_status[$status]->{$value} = "Not requested"; } } if(!defined($snap_list[$status])) { $snap_list[$status]->{date} = "Not requested"; } if(!defined($snap_list_b[$status])) { $snap_list_b[$status]->{owners} = "Not requested"; } %temp_attributes = ( %{ $snap_status[$status] }, %{ $snap_list[$status] }, %{ $snap_list_b[$status] }, ); $temp_attributes{aggregate} = $snap_list_output->[$row]->{aggregate}; my $final_attributes = $pkg->_hash_copy( source => \%temp_attributes, copy => [qw(aggregate date status name fsrev ownblks release snapid owners )], map => { "name" => "snapshot", "%/total" => "blocks", "%/used" => "usedblocks", }, ); my $obj = $pkg->new( command_interface => $opts{command_interface} ); $obj->_set_fields( row => $final_attributes ); push @state_objs, $obj; if($flag == 1) { last; } } ## end of for my $status } ## end for my $row $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli 1;