# # Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary VserverServicesUnixUser Task Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::STask::VserverServicesUnixUser; use strict; use warnings; use base qw(NACL::C::VserverServicesUnixUser 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::VserverServicesUnixUser =head1 DESCRIPTION C provides a number of well-defined but potentially complex or multi-step methods related to VserverServicesUnixUser 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 VserverServicesUnixUser-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_user = NACL::STask::VserverServicesUnixUser->create( command_interface => $ci, name => $unix_user_name, nacltask_if_exists => $action, # default 'die' ); (Class method) Create a new unix user element, and return a new unix user stask object that refers to it. Does not wait for unix user 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_user_name >> (Required) Name of unix user to create. =item C<< id=>$integer >> (Required) Integer number to represent a unix user. =item C<< nacltask_if_exists=>$action >> (Optional) What to do if the unix user to be created already exists. If $action is "die" (the default), then fail with an exception (in the same way that the VserverServicesUnixUser component would have: by trying the VserverServicesUnixUser create and letting the product complain about the unix user already existing). If action is "reuse", then do nothing (return a task object referring to the existing VserverServicesUnixUser). If action is "purge", then delete the VserverServicesUnixUser (see the C method, below) before creating a new one. =item C The options accepted for MCC configuration replication verification is documented at L. =item C<< purge_if_duplicate_by_id=0|1 >> (Optional) Unix User user 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 command_interface, apiset_must, apiset_should etc. All of the other various options to L<< NACL::C::VserverServicesUnixUser->create|lib-NACL-C-VserverServicesUnixUser-pm/create >> =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to create vserver unix user that already exists. =item C This type of exception is thrown when verification fails for the created vserver unix user. =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-user', 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_user->purge(%other_options); NACL::STask::VserverServicesUnixUser->purge( command_interface => $command_interface, name => $name, %other_options ); (Class or instance method) This method deletes an vserver services unix user, =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_user_name >> (Required for class method, Not Applicable for instance method) Name of Unix user. =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 user 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 user which does not exist is suppressed. =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. =item C The options accepted for MCC configuration replication verification is documented at L. =back =over =item Exceptions =over =item C This type of exception is thrown when an attempt is made to delete vserver unix user that does not exists. =item C This type of exception is thrown when verification fails for the deleted vserver unix user. =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 $unix_user_name = $opts{user}; my $vserver = $opts{vserver}; NACL::C::VserverServicesNameServiceGetxxbyyy->getpwbyname( username => $unix_user_name, node => 'local', vserver => $vserver, %common_params, ); } ## end sub _replay_check 1;