# # Copyright (c) 2014 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary VserverServicesUnixGroup Task Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::STask::VserverServicesUnixGroup; use strict; use warnings; use base qw(NACL::C::VserverServicesUnixGroup 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 NACL::STask::_VserverServices qw(:all !_replay_check); use NACL::C::VserverServicesNameServiceGetxxbyyy; use NACL::Exceptions::VerifyFailure (); =head1 NAME NACL::STask::VserverServicesUnixGroup =head1 DESCRIPTION C provides a number of well-defined but potentially complex or multi-step methods related to VserverServicesUnixGroup 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 VserverServicesUnixGroup-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. =head1 METHODS =head2 create my $unix_group = NACL::STask::VserverServicesUnixGroup->create( command_interface => $ci, name => $unix_group_name, nacltask_if_exists => $action, # default 'die' ); (Class method) Create a new unix group element, and return a new unix group stask object that refers to it. Does not wait for unix group creation to complete. Uses a CMode-CLI APISet. =over =item Options =over =item C<< vserver=>$vserver_name >> (Required) Name of vserver or Node. =item C<< name=>$unix_group_name >> (Required) Name of unix group to create. =item C<< id=>$integer >> (Required) Integer number to represent a unix group. =item C<< nacltask_if_exists=>$action >> (Optional) What to do if the unix group to be created already exists. If $action is "die" (the default), then fail with an exception (in the same way that the VserverServicesUnixGroup component would have: by trying the VserverServicesUnixGroup create and letting the product complain about the unix group already existing). If action is "reuse", then do nothing (return a task object referring to the existing VserverServicesUnixGroup). If action is "purge", then delete the VserverServicesUnixGroup (see the C method, below) before creating a new one. =item C<< purge_if_duplicate_by_id=0|1 >> (Optional) Unix User group in a given vserver can be a duplicate even if the id is already in use by another unix user. In cases like that, user has an option to purge the unix user whose 'id' matches the 'id' provided for "create" method. default: 0 =item C The options accepted for MCC configuration replication verification is documented at L. =item command_interface, apiset_must, apiset_should etc. All of the other various options to L<< NACL::C::VserverServicesUnixGroup->create|lib-NACL-C-VserverServicesUnixGroup-pm/create >> =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to create vserver unix group that already exists. =item C This type of exception is thrown when verification fails for the created vserver unix group. =back =cut sub create { $Log->enter() if $may_enter; my ( $pkg, %args ) = @_; my $check_ver = delete($args{'check_version'}) if(defined($args{'check_version'})); my $check_retries = 2; $check_retries = delete($args{'check_retries'}) if(defined($args{'check_retries'})); my $check_sleep = 1; $check_sleep = delete($args{'check_sleep'}) if(defined($args{'check_sleep'})); my $self = $pkg->_create_helper(%args); my $retry = 0; my $start_time = time(); SHOW: { if($check_ver) { # For create calls passing in this param, let us sleep for a small # window to increase the chance of the file counter and the rdb # counter matching on the very first try (no retry in play) sleep($check_sleep); my @objects = NACL::CS::VserverServicesNameServiceFileVersion->fetch( command_interface => $args{'command_interface'}, filter => {srctbl => 'unix-group' , vserver => $args{'vserver'}}, requested_fields => [qw(file-counter rdb-counter)], ); $retry++; foreach my $object(@objects) { if($object->rdb_counter() != $object->file_counter()) { if ($retry >= $check_retries) { my $elapsed = time() - $start_time; NACL::Exceptions::VerifyFailure->throw("Waited $elapsed seconds, entries of file and db counter still mismatch"); } sleep(1); goto SHOW; } } } } $Log->exit() if $may_exit; return $self; } =head2 purge $vserver_unix_group->purge(%other_options); NACL::STask::VserverServicesUnixGroup->purge( command_interface => $command_interface, name => $name, %other_options ); (Class or instance method) This method deletes an vserver services unix group, =over =item Options =over =item C<< command_interface=>$command_interface >> (Required for class method, Not Applicable for instance method) See L =item C<< name=>$unix_group_name >> (Required for class method, Not Applicable for instance method) Name of Unix Group. =item C<< vserver=>$vserver_name >> (Required for class method, Not Applicable for instance method) (Required) Name of vserver or Node. =item C<< nacltask_if_purged => die | pass >> (Optional, defaults to "die") Specifies what to do if the vserver services unix user group we're trying to purge no longer exists. A value of C (the default) will result in an exception being thrown. A value of C will mean that the exception that would normally occur when we're trying to delete a unix group that does not exist is suppressed. =item C The options accepted for MCC configuration replication verification is documented at L. =item C<< nacltask_verify=>$nacltask_verify_boolean >> (Optional) If '0' (default), verification will not be performed. If '1', verification will be performed to ensure that the deletion did happen successfully. =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to delete vserver unix group that does not exists. =item C This type of exception is thrown when verification fails for the deleted vserver unix group. =back =cut sub purge { $Log->enter() if $may_enter; my ( $pkg_or_obj, %args ) = @_; $pkg_or_obj->_purge_helper(%args); $Log->exit() if $may_exit; } # # _replay_check: supporting method called by _VserverServices. # Method to check if command replayed to secd. # sub _replay_check { $Log->enter() if $may_enter; my ( $pkg_or_obj, @args ) = @_; my %opts = $pkg_or_obj->_common_validate_with(params => \@args,); my %common_params; $pkg_or_obj->_copy_common_component_params_with_ci( source => \%opts, target => \%common_params ); my $group_name = $opts{name}; my $vserver = $opts{vserver}; NACL::C::VserverServicesNameServiceGetxxbyyy->getgrbyname( node => 'local', vserver => $vserver, groupname => $group_name, %common_params, ); } 1;