# # Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary AntivirusEngine Task Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::STask::AntivirusEngine; use strict; use warnings; use base qw(NACL::C::AntivirusEngine NACL::STask::STask); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Params::Validate qw(validate SCALAR BOOLEAN); use NATE::Exceptions::Argument qw(:try); use NACL::APISet::Exceptions::ResponseException (); use constant DEFAULT_TIMEOUT => 3600; use constant POLL_DELTA => 10; use Class::MethodMaker [ scalar => [ { -type => 'NACL::C::Job' }, 'job_component', ], ]; =head1 NAME NACL::STask::AntivirusEngine =head1 DESCRIPTION C provides a number of well-defined but potentially complex or multi-step methods related to AntivirusEngine in ONTAP. It builds on top of, and is a derived class of C, and so it also provides methods that are more in the scope of individual AntivirusEngine-related commands. See C for details. This also means that a C object may generally be used in place of a component object. =head1 ATTRIBUTES =head2 command_interface (Required) A component object that represents the host to which to send commands. =head2 job_component (Optional) A job component (NACL::C::Job) representing the job used to enable the antivirus engine. =head1 METHODS =head2 modify NACL::STask::AntivirusEngine->modify( command_interface => $command_interface, vendor => $vendor_name, nacltask_verify => 0|1 # defaults to 0, %other_options ); (Class method) Modifies the Antivirus Engine with the vendor configuration. Also verify that all attributes got set to the specified values if C is set to 1. =over =item C<< nacltask_verify => 0|1 >> (Optional, defaults to 0) When set to 1, it verifies that the engine has been configured with all of the attributes specified. When set to 0, verification is not performed. Note that it is also possible to perform the verification later by calling L. This can be used for cases where ONTAP chooses to not set all attributes to the exact values specified. In the call we can specify those attributes we want verified. =item other options See L for all the other options accepted by this method. =back =over =item Exceptions =over =item C This type of exception is thrown when verification for Antivirus engine has failed. =back =cut sub modify { $Log->enter(); my $pkg = shift; my %opts = $pkg->_common_validate_with( params => \@_, additional_spec => { nacltask_verify => { type => BOOLEAN, default => 0 }, }, allow_extra => 1, ); my $verify = delete $opts{'nacltask_verify'}; # Modifying the engine with the vendor specific configuration $pkg->SUPER::modify(%opts); delete $opts{password} if ( $opts{password} ); # Verify the engine has been modified if 'nacltask_verify' is set to 1 if ($verify) { $pkg->verify_state(%opts); } $Log->exit(); } =head2 enable NACL::STask::AntivirusEngine->enable( command_interface => $command_interface, vendor => $vendor_name, nacltask_wait => 1, #default 1 nacltask_if_enabled => $action, #default "die" %other_options, ); (Class method) This method enables the antivirus engine. =over =item Options =over =item B<< nacltask_wait=>0|1 >> (Optional) If 1 (the default), wait for this AntivirusEngine to be enabled. This option also provides verification that the engine is enabled. If 0, do not wait any longer than necessary (any longer than the AntivirusEngine enable command waits). =item B<< nacltask_if_enabled=>die|pass >> (Optional) If "die", exception is thrown if antivirus engine is already enabled. If "pass", exits quietly if antivirus engine is already enabled. =item C<< "method-timeout" => $timeout >> (Optional) As component method-timeout, controls how long the command will wait before completing. However, the default timeout has been raised to 3600 seconds. =item other options See L for all the other options accepted by this method. =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to enable antivirus engine when it is already enabled. =back =cut sub enable { $Log->enter(); my $pkg = shift; my %opts = $pkg->_common_validate_with( params => \@_, additional_spec => { nacltask_wait => { type => BOOLEAN, default => 1 }, nacltask_if_enabled => $pkg->_if_action_completed_already_validate_spec(), }, allow_extra => 1, ); my $command_interface = $opts{command_interface}; $opts{'method-timeout'} ||= DEFAULT_TIMEOUT; my $wait = delete $opts{nacltask_wait}; my $if_enabled = delete $opts{nacltask_if_enabled}; my $pass = undef; my %wait_for_status_opts; $pkg->_copy_common_component_params_with_ci( source => \%opts, target => \%wait_for_status_opts ); my $job_ref; $opts{job_component} ||= \$job_ref; # Call the component enable method try { $pkg->SUPER::enable(%opts, allow_extra => 1); } catch NACL::APISet::Exceptions::CommandFailedException with { my $ex = shift; if ( $ex->text() =~ /The antivirus service is already enabled/ ) { $Log->debug( "The Antivirus Service is already enabled" ); if ( $if_enabled =~ /die/ ) { $ex->throw(); $Log->exit(); } elsif ( $if_enabled =~ /pass/ ) { $pass = 1; } # Continue further } else { $Log->exit(); $ex->throw(); } }; if ($pass) { $Log->exit(); return; } $wait_for_status_opts{job_component} = ${$opts{job_component}}; # If nacltask_wait flag is set, then we wait until the engine is enabled if ($wait) { $pkg->wait_for_status( %wait_for_status_opts, ); } $Log->exit(); } =head2 disable NACL::STask::AntivirusEngine->disable( command_interface => $command_interface, nacltask_if_disabled => $action, #default "die" %other_options, ); (Class method) This method disables the antivirus engine. =over =item Options =over =item B<< nacltask_if_disabled=>die|pass >> (Optional) If "die", exception is thrown when antivirus engine is already disabled If "pass", exits quietly when antivirus engine is already disabled =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to disable an antivirus engine when it is disabled already. =back =cut sub disable { $Log->enter(); my $pkg = shift; my %opts = $pkg->_common_validate_with( params => \@_, additional_spec => { nacltask_if_disabled => $pkg->_if_action_completed_already_validate_spec(), }, allow_extra => 1, ); my $if_disabled = delete $opts{nacltask_if_disabled}; my $command_interface = $opts{command_interface}; my $pass = undef; # Call the component disable method try { $pkg->SUPER::disable( %opts ); } catch NACL::APISet::Exceptions::CommandFailedException with { my $ex = shift; if ( $ex->text() =~ /The antivirus service is already disabled/ ) { $Log->debug( "The Antivirus Service is already disabled" ); if ( $if_disabled =~ /die/ ) { $ex->throw(); } elsif ( $if_disabled =~ /pass/ ) { $pass = 1; } # Continue further } else { $Log->exit(); $ex->throw(); } }; if ($pass) { $Log->exit(); return; } $Log->exit(); } =head2 wait_for_status $pkg_or_obj->wait_for_status( 'method-timeout' => $time_to_wait, till_value => $till_value, polling_interval => $interval ); (Class or instance method)This method is used to wait for enabling the antivirus engine. =over =item Options =over =item C<< polling_interval => $interval >> (Optional) This is the interval at which to show the progress of the job the interval at which to poll the filer for the value of the "state" field. =item C<< command_interface => $ci >> (Required) This is a component/task object that represents the host to which to send commands. See L. =item C<< "method-timeout" => $timeout >> (Optional) As component method-timeout, controls how long the command will wait before completing. However, the default timeout has been raised to 3600 seconds. =item command_interface, apiset_must, apiset_should etc. =back =back =cut sub wait_for_status { $Log->enter(); my $pkg_or_obj = shift; my %opts = $pkg_or_obj->_common_validate_with( params => \@_, additional_spec => { polling_interval => { type => SCALAR, default => 1 }, job_component => { isa => 'NACL::C::Job', optional => 1 }, }, ); $opts{'method-timeout'} ||= DEFAULT_TIMEOUT; my $timeout = delete $opts{'method-timeout'}; my $polling_interval = delete $opts{'polling_interval'} || POLL_DELTA; my $command_interface = $opts{command_interface}; my $pkg = ref $pkg_or_obj || $pkg_or_obj; $pkg->wait_for_completion( %opts, job_component => $opts{job_component}, attribute_to_check => 'state', till_value => 'on', polling_interval => $polling_interval, 'method-timeout' => $timeout, ); $Log->exit(); } ## end sub wait_for_status 1;