# # Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary SystemNodeAutosupportHistory ComponentState Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SystemNodeAutosupportHistory =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP SystemNodeAutosupportHistory. A related class is L, which represents access to an ONTAP SystemNodeAutosupportHistory. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the SystemNodeAutosupportHistory element are the attributes of the SystemNodeAutosupportHistory ComponentState. =over =item C<< "last_modified" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: <$value =item C<< "status" >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -status (Programmatic name: status) For "requested_fields": -fields (Programmatic name: fields) =item C<< "destination" >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -destination (Programmatic name: destination) For "requested_fields": -fields (Programmatic name: fields) =item C<< "subject" >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -subject (Programmatic name: subject) For "requested_fields": -fields (Programmatic name: fields) =item C<< "node" >> Filled in for CMode CLI/ZAPI Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value item C<< "uri" >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -uri (Programmatic name: uri) For "requested_fields": -fields (Programmatic name: fields) =item C<< "seq_num" >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -seq-num (Programmatic name: seq-num) For "requested_fields": -fields (Programmatic name: fields) =item C<< last_update >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -last-update (Programmatic name: last-update) For "requested_fields": -fields (Programmatic name: fields) =item C<< attempt_count >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -attempt-count (Programmatic name: attempt-count) For "requested_fields": -fields (Programmatic name: fields) =item C<< error >> Filled in for CMode CLI, 7Mode CLI. 7Mode CLI: For "filter": -error (Programmatic name: error) For "requested_fields": -fields (Programmatic name: fields) =item C<< generated_on >> Time of Generation Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< trigger >> Filled in for CMode CLI/ZAPI, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": -trigger (Programmatic name: trigger) For "requested_fields": -fields (Programmatic name: fields) =item C<< upload_rate >> Rate of upload Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< percent_complete >> Percent Complete ranges from 0 to 100 Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< size >> AutoSupport Size Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< time_remaining >> Time remaining for upload Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< decompressed_size >> AutoSupport Decompressed Size Filled in for CMode CLI. =item C<< total_time >> Total Collection Time (ms) Filled in for CMode CLI. =item C<< chunk_id >> AutoSupport chunk id Filled in for CMode CLI. =back =cut package NACL::CS::SystemNodeAutosupportHistory; 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 Data::Dumper; use NACL::Exceptions::NoElementsFound qw(:try); use NACL::ComponentUtils qw (enumerate_month); use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => [ { -default_ctor => sub { $_[0]->attempt_count() if (ref $_[0]) } }, 'tx_cnt' ], scalar => [ { -default_ctor => sub { $_[0]->last_update() if (ref $_[0]); } }, 'last_modified' ], scalar => [ { -default_ctor => sub { $_[0]->error() if (ref $_[0]); } }, 'errTxt' ], scalar => 'status', scalar => 'destination', scalar => 'trigger', scalar => 'subject', scalar => 'messagename', scalar => 'node', scalar => 'uri', scalar => 'seq_num', scalar => 'last_update', scalar => 'attempt_count', scalar => 'error', scalar => 'generated_on', scalar => 'upload_rate', scalar => 'percent_complete', scalar => 'size', scalar => 'time_remaining', scalar => 'decompressed_size', scalar => 'total_time', scalar => 'chunk_id', ]; =head1 METHODS =head2 fetch my $SystemNodeAutosupportHistory_state = NACL::CS::SystemNodeAutosupportHistory->fetch(command_interface => $ci, ...); my @SystemNodeAutosupportHistory_states = NACL::CS::SystemNodeAutosupportHistory->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. Supports CMode CLI/ZAPI, 7Mode CLI. Invokes "autosupport-history-get-iter" API for CMode ZAPI. Invokes "autosupport history show" command for 7Mode CLI. =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_7mode_cli', interface => 'CLI', set => '7Mode', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', }, ], show_cmd => 'system node autosupport history show', exception_text => 'No matching system node autosupport history(s) found' ); $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, %opts) = @_; my @state_objs = $pkg->SUPER::_fetch_cmode_cli(%opts, api => 'system_node_autosupport_history_show'); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_cli sub _fetch_7mode_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $command_interface = delete $opts{command_interface}; my $apiset = delete $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 $req_field_filter; $req_field_filter->{'requested_fields'} = $requested_fields; $req_field_filter->{'filter'} = \%copy_filter; my %history_status; my @fields = qw ( seq-num destination trigger last-update status attempt-count subject uri error ); if (!@$requested_fields) { # requested_fields is [], i.e. get all fields # Join the array into a comma-separated string my $fields = join ',', @fields; $history_status{fields} = $fields; } else { @fields = (); foreach my $val (@$requested_fields) { if ($val ne "node") { push(@fields, $val); } } push(@fields, "trigger"); # requested_fields explicitly provided to be certain fields my $fields = join ',', @fields; $history_status{fields} = $fields; } ## end else [ if ( !@$requested_fields) if (exists($req_field_filter->{'filter'})) { foreach my $key (keys(%{$req_field_filter->{filter}})) { if ($key ne "node") { $history_status{$key} = $req_field_filter->{'filter'}->{$key}; } } } ## end if ( exists( $req_field_filter... my $response = $apiset->autosupport_history_show(%history_status); my $output = $response->get_parsed_output(); my @state_objs; my $final_attributes; foreach my $row (@$output) { my $obj = $pkg->new(command_interface => $command_interface); $obj->_set_fields(row => $row); push @state_objs, $obj; } ## end foreach my $row (@$output) return @state_objs; } ## end sub _fetch_7mode_cli sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my @state_objs = $pkg->SUPER::_fetch_cmode_zapi( %opts, api => "autosupport_history_get_iter", copy => [ qw(uri seq-num trigger subject attempt-count destination status percent-complete time-remaining upload-rate size) ], map => { "node" => 'node-name', "last-update" => 'last-modification-timestamp', "generated-on" => "generation-timestamp", }, ); foreach my $state_obj (@state_objs) { foreach my $time_stamp (qw( generated_on last_update )) { my $time = $state_obj->$time_stamp(); $time = scalar gmtime($time); if (defined($time) && $time =~ /(\w+)\s(\w+)\s+(\d+)\s(\d+\:\d+\:\d+)\s(\d+)/) { my $month = $pkg->enumerate_month(month => $2); my $date = $3; my $time = $4; my $year = $5; my $date_time = "$month/$date/$year $time"; $state_obj->$time_stamp($date_time); } } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi sub _update_state_objs_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; $pkg->SUPER::_update_state_objs_cmode_zapi( %opts, zapi_field_translations => { hyphenate_value => [qw(status)], }, ); $Log->exit() if $may_exit; } 1;