# $Id: //depot/prod/test/main/lib/NACL/CS/Smtape.pm#1 $ # # Copyright (c) 2010 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Smtape ComponentState Module ## @author dl-dpg-nb-automation;dl-nacl-dev ## @status public ## @pod here package NACL::CS::Smtape; 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::NoMatchingEntriesException qw(:try); 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 => 'sequence_no', scalar => 'job_id', scalar => 'progress', scalar => 'status', scalar => 'last_update_time', scalar => 'path', scalar => 'job_end', scalar => 'device', scalar => 'job_begin', scalar => 'type', scalar => 'volume_path', ]; =head1 METHODS =head2 fetch my $Smtape_state = NACL::CS::Smtape->fetch(command_interface => $ci, ...); my @Smtape_states = NACL::CS::Smtape->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', }, ], exception_text => 'No matching smtape(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 ( $caught_exception, %api_args ); my ( $status_response, $jobid_status, $status_response_output ); my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my $requested_fields = $opts{requested_fields}; if ( exists $filter->{'job-id'} ) { $api_args{'job-id'} = $filter->{'job-id'}; } elsif ( exists $filter->{path} ) { $api_args{path} = $filter->{path}; } if ($pkg->_want_any_field_of( requested_fields => $requested_fields, filter => $filter, fields_filled_by_api => [qw(job-begin job-end last-update-time)] ) ) { $api_args{'long-status'} = 1; } try { #invoking appropiate API $status_response = $apiset->smtape_status(%api_args); } catch NACL::APISet::Exceptions::NoMatchingEntriesException with { $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my @state_objs; #retrieve the parsed output $status_response_output = $status_response->get_parsed_output(); foreach $jobid_status ( @{$status_response_output} ) { my $obj = $pkg->new( command_interface => $opts{command_interface} ); #creating a object $obj->_set_fields( row => $jobid_status ); # push the above created object to an array push @state_objs, $obj; } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli 1;