# # Copyright (c) 2014 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. ## @summary QosPolicyGroup Task Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::STask::QosPolicyGroup; use strict; use warnings; use base qw(NACL::C::QosPolicyGroup NACL::STask::STask); use feature 'state'; 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 :types); #Exceptions Used use NACL::Exceptions::VerifyFailure (); use NACL::C::Exceptions::QosPolicyGroup::AlreadyExists qw(:try); use NATE::BaseException qw(:try); =head1 NAME NACL::STask::QosPolicyGroup =head1 DESCRIPTION C provides a number of well-defined but potentially complex or multi-step methods related to QosPolicyGroup in ONTAP. It builds on top of, and is a derived class of C component. Since it is a derived class of C, we can use all the methods defined in this class. =head1 ATTRIBUTES =head2 command_interface (Required) A component object that represents the host to which to send commands. =head2 policy_group (Required) The name of the policy group to be created. =head1 METHODS =head2 create This accepts the same options and provides the same facilities as L. Additionally, the STask provides the following facilities: C, C, C. The description of these features are present at: L. =head2 purge This accepts the same options and provides the same facilities as L. Additionally, the STask provides the following facilities: C, C. The description of these features are present at: L. =cut __PACKAGE__->create_method_builder(); __PACKAGE__->purge_method_builder(); sub _element_exists_handler { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my $create_opts = $opts{create_opts}; my $exception = $opts{exception}; my $existing_qos_policy_group = $pkg->find( command_interface => $create_opts->{command_interface}, filter => {vserver => $create_opts->{vserver}, 'policy-group' => $create_opts->{'policy-group'}}, allow_empty => 1, ); if (defined $existing_qos_policy_group) { my $self = $pkg->SUPER::_element_exists_handler(%opts); $Log->exit() if $may_exit; return $self; } else { # This means that the qos policy group doesn't exist but the name is already used in a different vserver # Add new text to existing error text $exception->set_text("Name is already used but is used with a different vserver\n" . $exception->text()); $Log->exit() if $may_exit; $exception->throw(); } } =head2 modify NACL::STask::QosPolicyGroup->modify( command_interface => $command_interface, 'policy-group' => $policy_group, 'max-throughput' => $new_value # Option to be modified. nacltask_to_cleanup => 1, %other_options ); or $policy group_obj->modify(%opts); (Class or Instance method) Modify policy group options. This method will modify the options present for the specified policy group. =over =item Options =over =item C<< command_interface => $command_interface >> (Required for class method, Not Applicable for instance method) See L =item C<< 'policy-group' => $policy_group >> (Required for class method, Not Applicable for instance method) The name of the policy group to be modified. =item C<< nacltask_verify => 0|1 >> (Optional, defaults to 0) Verifies whether all of the attributes got set to the specified value. =item C<< nacltask_to_cleanup => 0|1 >> (Optional, defaults to 0(no to cleanup)) Flag indicating if this operation is to be cleaned up or not. =item C<< nacltask_cleanup_manager >> Cleanup manager to use for registering. Default : Will use the default cleanup manager. =back =back =over =item Exceptions =over =item C This type of exception is thrown when verification fails for the deleted policy group. =item other options See L for all the other options accepted by this method. =back =back =cut sub modify { $Log->enter() if $may_enter; my ($pkg_or_obj, @args) = @_; my %opts = $pkg_or_obj->_common_validate_with( params => \@args, additional_spec => {$pkg_or_obj->_cleanup_validate_spec(),}, allow_extra => 1, ); my ($opts_for_register, $register_for_cleanup, %opts_for_cleanup); $pkg_or_obj->_move_common_cleanup_opts( source => \%opts, target => \%opts_for_cleanup, nacltask_to_cleanup => \$register_for_cleanup ); if ($register_for_cleanup) { $opts_for_register = $pkg_or_obj->_common_modify_for_cleanup(%opts_for_cleanup, %opts); $pkg_or_obj->_register_for_cleanup(%{$opts_for_register}); } $pkg_or_obj->_call_method_then_verify(%opts); $Log->exit() if $may_exit; } ## end sub modify =head2 rename NACL::STask::QosPolicyGroup->rename( command_interface => $command_interface, 'policy-group' => $policy_group, 'new-name' => $new_policy_group, nacltask_to_cleanup => 1, %other_options ); or $policy group_obj->rename('new-name' => $new_policy); (Class or Instance method) Rename policy group name. =over =item Options =over =item C<< command_interface => $command_interface >> (Required for class method, Not Applicable for instance method) See L =item C<< 'policy-group' => $policy_group >> (Required for class method, Not Applicable for instance method) The name of the policy group to be renamed. =item C<< 'new-name' => $string >> (Required for class method and instance method) New policy group name =item C<< nacltask_verify => 0|1 >> (Optional, defaults to 0) Verifies whether all of the attributes got set to the specified value. =item C<< nacltask_to_cleanup => 0|1 >> (Optional, defaults to 0(no to cleanup)) Flag indicating if this operation is to be cleaned up or not. =item C<< nacltask_cleanup_manager >> Cleanup manager to use for registering. Default : Will use the default cleanup manager. =item other options See L for all the other options accepted by this method. =back =back =over =item Exceptions =over =item C This type of exception is thrown when verification fails for the renamed policy group. =item other options See L for all the other options accepted by this method. =back =back =cut sub rename { $Log->enter() if $may_enter; my ($pkg_or_obj, @args) = @_; my %opts = $pkg_or_obj->_common_validate_with( params => \@args, additional_spec => { $pkg_or_obj->_cleanup_validate_spec(), 'new-name' => {type => SCALAR}, 'policy-group' => {type => SCALAR}, nacltask_verify => {type => SCALAR, default => 1}, }, ); my $command_interface = $opts{command_interface}; my $newname = $opts{'new-name'}; my $nacltask_verify = delete $opts{nacltask_verify}; my %common_opts; $pkg_or_obj->_copy_common_component_params_with_ci( source => \%opts, target => \%common_opts, ); my (%nacltask_options, $nacltask_to_cleanup, %opts_for_cleanup); $pkg_or_obj->_copy_common_opts_for_cleanup( 'source' => \%opts, 'target' => \%opts_for_cleanup, 'nacltask_to_cleanup' => \$nacltask_to_cleanup, 'to_cleanup' => 'rename' ); $pkg_or_obj->SUPER::rename(%opts); if ($nacltask_to_cleanup) { $opts_for_cleanup{'new_opts'} = {'new-name' => $opts{'new-name'}}; $opts_for_cleanup{'orig_opts'} = {'new-name' => $opts{'policy-group'}}; $opts_for_cleanup{'policy-group'} = $opts{'new-name'}; $pkg_or_obj->_register_for_cleanup(%opts_for_cleanup); } #verifying the new-name if ($nacltask_verify) { my %common_opts; $pkg_or_obj->_copy_common_component_params_with_ci( source => \%opts, target => \%common_opts ); my $policy_obj = NACL::STask::QosPolicyGroup->find( command_interface => $command_interface, filter => {'policy-group' => $newname}, %common_opts, allow_empty => 1, ); unless ($policy_obj) { $Log->exit() if $may_exit; NACL::Exceptions::VerifyFailure->throw( "The policy group is not renamed properly"); } } $Log->exit() if $may_exit; } ## end sub rename 1;