# # Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary AntivirusOnAccessPolicy Task Module ## @author swati.bajaj@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::STask::AntivirusOnAccessPolicy; use strict; use warnings; use base qw(NACL::C::AntivirusOnAccessPolicy 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 SCALARREF BOOLEAN); use NATE::Exceptions::Argument qw(:try); use NACL::C::Exceptions::AntivirusOnAccessPolicy::AlreadyExists (); use NACL::C::Exceptions::AntivirusOnAccessPolicy::DoesNotExist (); =head1 NAME NACL::STask::AntivirusOnAccessPolicy =head1 DESCRIPTION C provides a number of well-defined but potentially complex or multi-step methods related to AntivirusOnAccessPolicy 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 AntivirusOnAccessPolicy-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 name (Required) Name of the policy. =head1 METHODS =head2 create my $AntivirusOnAccessPolicy_obj = NACL::STask::AntivirusOnAccessPolicy->create( command_interface => $command_interface, name => $policy_name, nacltask_if_exists => $action, # default 'die' nacltask_verify => 0|1, # default '0' %other_options ); (Class method) Create an AntivirusOnAccessPolicy. This method provides additional services beyond what's inherent to the product's AntivirusOnAccessPolicy creation commands, as controlled and described by the new C and C options. =over =item Options =over =item C<< nacltask_if_exists => $action >> (Optional, defaults to "die") Specifies an action to be taken if the AntivirusOnAccessPolicy already exists. =over =item C When set to "die", an exception is thrown if the AntivirusOnAccessPolicy already exists. =item C If a AntivirusOnAccessPolicy of the same name already exists, reuse it. =item C If a AntivirusOnAccessPolicy of the same name already exists, purge it and create a new one. =back =item C<< nacltask_verify => 0|1 >> (Optional, defaults to 0) When set to 0, verification is not performed. When set to 1, it is verified that the created AntivirusOnAccessPolicy has all of the attributes specified. =back 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. All of the other various options are described in L<< NACL::C::AntivirusOnAccessPolicy->create|lib-NACL-C-AntivirusOnAccessPolicy-pm/create >> =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to create an AntivirusOnAccessPolicy when it already exists. =item C This type of exception is thrown when verification fails for the created antivirus on-access policy. =back =back =cut sub create { $Log->enter() if $may_enter; my $pkg = shift; my %opts = $pkg->_common_validate_with( params => \@_, additional_spec => { nacltask_if_exists => $pkg->_if_exists_validate_spec(), nacltask_verify => { type => SCALAR, default => 0 }, _was_created => { type => SCALARREF, optional => 1 }, }, allow_extra => 1, ); my $nacltask_if_exists = delete $opts{nacltask_if_exists}; my $command_interface = $opts{command_interface}; my $verify = delete $opts{nacltask_verify}; my $self; my $was_created = delete $opts{_was_created}; $$was_created = 0; CREATE: { use warnings qw(exiting); try { $self = $pkg->SUPER::create(%opts); $$was_created = 1; # Verify that the AntivirusOnAccessPolicy was created if ($verify) { $pkg->taskverify_create(%opts); } } ## end try catch NACL::C::Exceptions::AntivirusOnAccessPolicy::AlreadyExists with { my $exception = shift; $Log->trace('The on-access policy already exists'); $self = $pkg->_element_exists_handler( create_opts => \%opts, nacltask_if_exists => $nacltask_if_exists, exception => $exception ); if ( !$self ) { no warnings qw(exiting); redo CREATE; } }; } ## end CREATE: $Log->exit() if $may_exit; return $self; } ## end sub create =head2 purge NACL::STask::AntivirusOnAccessPolicy->purge( command_interface => $command_interface, name => $policy_name, %other_options, ); or $AntivirusOnAccessPolicy_obj->purge(); (Class or instance method) This method deletes the on-access policy. =over =item C<< nacltask_if_purged=>die|pass >> (Optional) If "die", exception is thrown when on-access policy to be deleted does not exist If "pass", exits quietly when on-access policy to be deleted does not exist =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to delete an AntivirusOnAccessPolicy that does not exists. =back =back =cut sub purge { $Log->enter() if $may_enter; my ($pkg_or_obj,@args) = @_; my $pkg = ref($pkg_or_obj) || $pkg_or_obj; my %opts = $pkg_or_obj->_common_validate_with( params => \@args, additional_spec => { nacltask_if_purged => $pkg_or_obj->_if_action_completed_already_validate_spec(), }, allow_extra => 1, ); my $command_interface = $opts{command_interface}; my $if_purged = delete $opts{nacltask_if_purged}; # Call the component delete method for on-access policy try { $pkg->delete(%opts); } catch NACL::C::Exceptions::AntivirusOnAccessPolicy::DoesNotExist with { my $ex = shift; if ( $if_purged !~ /pass/i ) { $Log->exit() if $may_exit; $ex->throw(); } }; $Log->exit() if $may_exit; } ## end sub purge 1;