# # Copyright (c) 2001-2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary SystemNodeAutosupport ComponentState Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SystemNodeAutosupport =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP SystemNodeAutosupport. A related class is L, which represents access to an ONTAP SystemNodeAutosupport. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the SystemNodeAutosupport element are the attributes of the SystemNodeAutosupport ComponentState. =over =item C<< "last_subject" >> Last Subject Sent Filled in for CMode-CLI, CMode-ZAPI. Maps to: CMode ZAPI: last-subject =item C<< "local_perf" >> Filled in for CMode-CLI. =item C<< "state" >> Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Possible values are "enable" and "disable". Maps to: CMode ZAPI: is-enabled 7Mode CLI: The "autosupport.enable" option =item C<< "perf" >> Performance Data Enable Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Possible values are "enable" and "disable". Maps to: CMode ZAPI: "is-perf-data-enabled" 7Mode CLI: The "autosupport.performance_data.enable" option =item C<< "local_nht" >> Filled in for CMode CLI. =item C<< "partner_address" >> (Array) List of Partner Addresses Since this is an array field, the value can be obtained in either scalar or list context: # Scalar context, returns an array-reference. my $address_arrayref = $cs_obj->partner_address(); # List context, returns an array. my @address_array = $cs_obj->partner_address(); Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: partner-address 7Mode CLI: The "autosupport.partner.to" option =item C<< "url" >> Support URL for HTTP/HTTPS Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: post-url 7Mode CLI: The "autosupport.support.url" option =item C<< "max_smtp_size" >> Maximum SMTP Size Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: max-smtp-size 7Mode CLI: The "autosupport.max_smtp_size" option =item C<< "remove_private_data" >> Filled in for CMode-CLI and CMode-ZAPI. Maps to: CMode ZAPI: is-private-data-removed =item C<< "reminder" >> Reminder Enable. Possible values are "true" and "false". Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: is-reminder-enabled 7Mode CLI: The "autosupport.support.reminder" option =item C<< "mail_hosts" >> (Array) SMTP Mail Hosts. Since this is an array field, the value can be obtained in either scalar or list context: # Scalar context, returns an array-reference. my $mail_hosts_arrayref = $cs_obj->mail_hosts(); # List context, returns an array. my @mail_hosts_array = $cs_obj->mail_hosts(); Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: $mailhost1 $mailhost2 ... 7Mode CLI: The "autosupport.mailhost" option =item C<< "support_for_zapi" >> Filled in for CMode-CLI. =item C<< "retry_count" >> Retry Count. Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: retry-count 7Mode CLI: The "autosupport.retry.count" option =item C<< "throttle" >> Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: is-throttle-enabled 7Mode CLI: The "autosupport.throttle" option =item C<< "foo" >> Filled in for CMode-CLI. (Note: The product documentation states this: "Unused - SMF work around") =item C<< "proxy_url" >> Support Proxy URL. Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: proxy-url 7Mode CLI: The "autosupport.support.proxy" option =item C<< "state_for_zapi" >> Filled in for CMode-CLI. =item C<< "support" >> Send AutoSupport Messages to Vendor Support. Possible values are "enable" and "disable". Filled in for CMode-CLI and CMode-ZAPI. Maps to: CMode ZAPI: is-support-enabled =item C<< "log_file_size" >> Filled in for CMode-CLI and CMode-ZAPI. Maps to: CMode ZAPI: log-file-size =item C<< "transport" >> Protocol to Contact Support. Possible values are "smtp", "http" and "https". Filled in for CMode-CLI, CMode-ZAPI and 7Mode CLI. Maps to: CMode ZAPI: transport 7Mode CLI: The "autosupport.support.transport" option =item C<< "nht" >> NHT Enable. Possible values are "true" and "false". Filled in for CMode-CLI, CMode-ZAPI and 7Mode CLI. Maps to: CMode ZAPI: is-nht-data-enabled 7Mode CLI: The "autosupport.nht_data.enable" option =item C<< "node" >> Filled in for CMode-CLI and CMode-ZAPI. Maps to: CMode ZAPI: node-name =item C<< "to" >> (Array) List of To Addresses. Since this is an array field, the value can be obtained in either scalar or list context: # Scalar context, returns an array-reference. my $to_arrayref = $cs_obj->to(); # List context, returns an array. my @to_array = $cs_obj->to(); Filled in for CMode-CLI, CMode-ZAPI and 7Mode CLI. Maps to: CMode ZAPI: to 7Mode CLI: The "autosupport.to" option =item C<< "hostname_subj" >> Filled in for CMode-CLI and CMode-ZAPI. Maps to: CMode ZAPI: is-node-in-subject =item C<< "from" >> From Address. Filled in for CMode-CLI, CMode-ZAPI and 7Mode CLI. Maps to: CMode ZAPI: from 7Mode CLI: The "autosupport.from" option =item C<< "support_address" >> (Array) Support Address. Since this is an array field, the value can be obtained in either scalar or list context: # Scalar context, returns an array-reference. my $support_address_arrayref = $cs_obj->support_address(); # List context, returns an array. my @support_address_array = $cs_obj->support_address(); Filled in for CMode-CLI and CMode-ZAPI. Maps to: CMode ZAPI: $addr1 $addr2 ... =item C<< "retry_interval" >> Retry Interval. Values are of the form hms. For example, "1h1m" = 1 hour 1 minute "1m2" = 1 minute 2 seconds "26" = 26 seconds Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: retry-interval 7Mode CLI: The "autosupport.retry.interval" option =item C<< "periodic_tx_window" >> The Transmission Window. Values are of the form hms. For example, "1h1m" = 1 hour 1 minute "1m2" = 1 minute 2 seconds "26" = 26 seconds Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: periodic-tx-window 7Mode CLI: The "autosupport.periodic.tx_window" option =item C<< "noteto" >> (Array) List of Noteto Addresses. Since this is an array field, the value can be obtained in either scalar or list context: # Scalar context, returns an array-reference. my $noteto_arrayref = $cs_obj->noteto(); # List context, returns an array. my @noteto_array = $cs_obj->noteto(); Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: noteto 7Mode CLI: The "autosupport.noteto" option =item C<< "trigger_now" >> Filled in for CMode-CLI and CMode-ZAPI. Maps to: CMode ZAPI: last-trigger. =item C<< "payload_format" >> Payload Format. Possible values are "7z" and "tgz". Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: payload-format 7Mode CLI: The "autosupport.payload_format" option =item C<< "put_url" >> Support URL for HTTP/S PUT. Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: put-url 7Mode CLI: The "autosupport.support.put_url" option =item C<< "validate_digital_certificate" >> Validate Digital Certificate Received. Possible values are "true" and "false". Filled in for CMode-CLI and 7Mode-CLI. Maps to: 7Mode CLI: The "autosupport.validate_digital_certificate" option =item C<< "last_time" >> Last Time Sent. Filled in for CMode-CLI and CMode ZAPI. Maps to: CMode ZAPI: last-timestamp =item C<< "max_http_size" >> Maximum HTTP Size. Filled in for CMode-CLI, CMode-ZAPI and 7Mode-CLI. Maps to: CMode ZAPI: max-http-size 7Mode CLI: The "autosupport.max_http_size" option =item C<< local_collection >> Continue Local Collection while Disabled. Possible values are "true" and "false". Filled in for CMode CLI, CMode-ZAPI and 7Mode CLI. Maps to: CMode ZAPI: is-local-collection-enabled 7Mode CLI: The "autosupport.local_collection" option =item C<< minimum_private_data_length >> Filled in for CMode CLI, CMode-ZAPI. Maps to: CMode ZAPI: minimum-private-data-length =item C<< ondemand_state >> AutoSupport OnDemand State. Possible values are "enable" and "disable". Filled in for CMode CLI and 7Mode CLI. Maps to: 7Mode CLI: The "autosupport.ondemand.state" option =item C<< ondemand_server_url >> AutoSupport OnDemand Server URL. Filled in for CMode CLI, CMode-ZAPI and 7Mode CLI. Maps to: CMode ZAPI: ondemand-server-url 7Mode CLI: The "autosupport.ondemand.server_url" option =item C<< ondemand_polling_interval >> AutoSupport OnDemand Polling Interval. Filled in for CMode CLI, CMode-ZAPI and 7Mode CLI. Maps to: CMode ZAPI: ondemand-polling-interval 7Mode CLI: The "autosupport.ondemand.polling_interval" option. =item C<< ondemand_remotediag_state >> *AutoSupport OnDemand Remote Diagnostics State, possible value(s) are enable,disable Filled in for CMode CLI, and 7Mode CLI. Maps to: 7Mode CLI: The "autosupport.ondemand.remotediag.state" option =item C<< max_upload_rate >> AutoSupport OnDemand Upload Throttle Setting Filled in for CMode CLI. =item C<< ondemand_download_state >> AutoSupport OnDemand Download State possible value(s) are, enable,disable Filled in for CMode CLI. =item C<< max_download_rate >> Maximum Download Rate Filled in for CMode CLI. =item C<< chunk_size >> AutoSupport chunk size Filled in for CMode CLI. =item C<< chunk_threads >> AutoSupport chunk size Filled in for CMode CLI. =item C<< diagnostic_content_delivery_state >> Diagnostic Content Default Delivery State possible value(s) are, enable,disable Filled in for CMode CLI. =item C<< http_delivery_timeout >> AutoSupport HTTP delivery timeout Filled in for CMode CLI. =item C<< diagnostic_content_state >> Diagnostic Content State possible value(s) are, enable,disable Filled in for CMode CLI. =back =cut package NACL::CS::SystemNodeAutosupport; use strict; use warnings; use Params::Validate qw(validate validate_with HASHREF ARRAYREF); 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 base 'NACL::CS::ComponentState::ONTAP'; use NACL::CS::ComponentState::ZapiSkip qw(make_zapi_skip); use NACL::CS::ComponentState::ZapiArray qw(make_zapi_array); # Import methods common to C and CS use NACL::C::_Mixins::SystemNodeAutosupport qw(:all); use Class::MethodMaker [ scalar => 'last_subject', scalar => 'local_perf', scalar => 'state', scalar => 'perf', scalar => 'local_nht', array => 'partner_address', scalar => 'url', scalar => 'max_smtp_size', scalar => 'remove_private_data', scalar => 'reminder', array => 'mail_hosts', scalar => 'support_for_zapi', scalar => 'retry_count', scalar => 'throttle', scalar => 'foo', scalar => 'proxy_url', scalar => 'state_for_zapi', scalar => 'support', scalar => 'log_file_size', scalar => 'transport', scalar => 'nht', scalar => 'node', array => 'to', scalar => 'hostname_subj', scalar => 'from', array => 'support_address', scalar => 'retry_interval', scalar => 'periodic_tx_window', array => 'noteto', scalar => 'trigger_now', scalar => 'payload_format', scalar => 'put_url', scalar => 'validate_digital_certificate', scalar => 'last_time', scalar => 'max_http_size', scalar => 'local_collection', scalar => 'minimum_private_data_length', scalar => 'ondemand_state', scalar => 'ondemand_server_url', scalar => 'ondemand_polling_interval', scalar => 'ondemand_remotediag_state', scalar => 'max_upload_rate', scalar => 'ondemand_download_state', scalar => 'max_download_rate', scalar => 'chunk_size', scalar => 'chunk_threads', scalar => 'diagnostic_content_delivery_state', scalar => 'http_delivery_timeout', scalar => 'diagnostic_content_state', ]; =head1 METHODS =head2 fetch my $SystemNodeAutosupport_state = NACL::CS::SystemNodeAutosupport->fetch(command_interface => $ci, ...); my @SystemNodeAutosupport_states = NACL::CS::SystemNodeAutosupport->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. Uses a CMode-CLI, CMode-ZAPI or 7Mode-CLI APISet. Invokes 'autosupport-config-get-iter' in CMode ZAPI. Invokes 'options autosupport' in 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, @args) = @_; my @state_objs = $pkg->SUPER::fetch( @args, 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', }, ], exception_text => 'No matching system node autosupport(s) found', show_cmd => 'system node autosupport show', ); $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, @args) = @_; my @state_objs = $pkg->SUPER::_fetch_cmode_cli(@args, api => 'system_node_autosupport_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, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $command_interface = $opts{command_interface}; my $apiset = $opts{apiset}; my $response = $apiset->options('show-options' => 'autosupport'); my $output = $response->get_parsed_output(); my @state_objs; foreach my $row (@$output) { my %row_of_output = %$row; # Remove any keys which have empty values. The parsed output could # contain "(value" if the value is empty, so let's remove those # fields as well. (see burt 627393) while (my ($key, $value) = each %$row) { if ($value =~ /^\s*$/ || $value eq '(value') { delete $row_of_output{$key}; } } # Certain fields in CMode are enable/disable, while 7Mode shows the # values as on/off. $pkg->_translate_enable_disable( options => \%row_of_output, mode_of_options => '7Mode' ); # Certain fields in CMode are true/false, while 7Mode shows the # values as on/off. $pkg->_translate_true_false( options => \%row_of_output, mode_of_options => '7Mode' ); # The values of array fields shows up in 7Mode as comma-separated # strings. Split on comma to turn into a list. my $array_fields = $pkg->_array_fields_7mode(); foreach my $array_field (@$array_fields) { if (defined $row_of_output{$array_field}) { my @arr = split ',', $row_of_output{$array_field}; $row_of_output{$array_field} = \@arr; } } my %c_to_7_map = $pkg->_c_7_fields_map(); $pkg->_hash_copy( source => \%row_of_output, target => \%row_of_output, map => {reverse %c_to_7_map} ); my $obj = $pkg->new(command_interface => $command_interface); $obj->_set_fields(row => \%row_of_output); push @state_objs, $obj; } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $enable_disable_fields = $pkg->_enable_disable_fields(); my %true_enable = (true => 'enable', false => 'disable'); # Fields which have value enable/disable in CLI have values as true/false # in ZAPI. SN onwards the ZAPI is able to understand an input of # enable/disable, but in RR it does not: RR requires the values to # be supplied as true/false. if ($opts{command_interface}->version_manager() ->is_version_lt(release => '8.2')) { my %filter = %{$opts{filter}}; my %enable_true = reverse %true_enable; foreach my $field (@$enable_disable_fields) { if (exists $filter{$field}) { my $orig_value = $filter{$field}; if (exists $enable_true{$orig_value}) { $filter{$field} = $enable_true{$orig_value}; } } } $opts{filter} = \%filter; } my $copy = $pkg->_cli_zapi_copy(); my @map = $pkg->_cli_zapi_map(); my @state_objs = $pkg->SUPER::_fetch_cmode_zapi( %opts, api => 'autosupport-config-get-iter', copy => $copy, map => @map, ); foreach my $state_obj (@state_objs) { foreach my $field (@$enable_disable_fields) { my $isset = "${field}_isset"; if ($state_obj->$isset()) { my $value = $state_obj->$field(); if (exists $true_enable{$value}) { $state_obj->$field($true_enable{$value}); } } } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi # Handle the various time-related fields (value could be a CMode-like string # or could just be a number - which would be seconds) # TODO: handle special characters, such as ">4m" or "1m..1h" sub _apply_filter { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate_with( params => \@args, spec => { filter => {type => HASHREF}, state_objs => {type => ARRAYREF}, }, allow_extra => 1 ); my %filter = %{$opts{filter}}; my $time_fields = $pkg->_time_fields(); foreach my $time_field (@$time_fields) { if (defined $filter{$time_field}) { my $updated_time = $pkg->_convert_time(time => delete $filter{$time_field}); my @new_state_objs; foreach my $state_obj (@{$opts{state_objs}}) { my $isset = "${time_field}_isset"; if ($state_obj->$isset()) { my $state_value = $pkg->_convert_time( time => $state_obj->$time_field()); if ($state_value == $updated_time) { push @new_state_objs, $state_obj; } } } @{$opts{state_objs}} = @new_state_objs; } } $pkg->SUPER::_apply_filter(%opts, filter => \%filter); $Log->exit() if $may_exit; } 1;