# $Id$ # # Copyright (c) 2001-2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Users ComponentState Module ## @author vikas.p@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SysManager::Users =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP Users. A related class is L, which represents access to an ONTAP Users. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Users element are the attributes of the users ComponentState. =over =item C<< username >> The name of the username element whose state is being represented. =item C<< route >> =item C<< user >> =item C<< account_locked >> =item C<< application_name >> =item C<< application >> =item C<< authentication >> =item C<< vserver >> =back =cut package NACL::CS::SysManager::Users; use strict; use warnings; use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Data::Dumper; use Params::Validate qw(validate); use base 'NACL::CS::ComponentState::SysManager'; use NACL::C::SysManager::Users; # Import Exception class use NACL::APISet::Exceptions::ResponseException qw(:try); use NACL::APISet::Exceptions::CommandFailedException; use Class::MethodMaker [ scalar => 'vserver', scalar => 'route', scalar => 'role', scalar => 'username', scalar => 'account_locked', scalar => 'application', scalar => 'authentication', ]; =head1 METHODS =head2 fetch my $users_state = NACL::CS::SysManager::Users->fetch(command_interface => $ci,...); my @users_states = NACL::CS::SysManager::Users->fetch(command_interface => $ci,...); see L. Uses a CMode GUI APISet. (Works only when username and vserver parameters are passed under filter option). =cut sub fetch { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my @state_objs = $pkg->SUPER::fetch( @args, choices => [ { method => "_fetch_cmode_gui", set => "SysManager_CMode", }, ], exception_text => 'No matching users or role found', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_cmode_gui { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my ( $user_args, $parsed_output_users, $parsed_output_advance_users, $advance_user_args, $advance_users_field, $response, $caught_exception, ); $advance_users_field = 0; my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; $user_args = $pkg->_hash_copy( source => $filter, map => { "username" => "-username", "route" => "-workflow", "vserver" => "-vservername", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(username route vserver)], ); try { # caling the gui api to get user status $response = $apiset->get_user_info(%$user_args); $parsed_output_users = $response->get_parsed_output(); } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the user being looked for # does not exist. We catch the exception and return immediately. # The 'fetch' frontend decides whether to throw a NoElementsFound # exception based on the value of 'allow_empty' $Log->debug( 'CommandFailedException caught. Requested user does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } if ( exists( $filter->{'application'} ) ) { $advance_user_args = $pkg->_hash_copy( source => $filter, map => { "username" => "-username", "application" => "-applicationname", "route" => "-workflow", "vserver" => "-vservername", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(username application route vserver)], ); try { # caling the gui api to get advance user status $response = $apiset->get_user_login_info(%$advance_user_args); $parsed_output_advance_users = $response->get_parsed_output(); $advance_users_field = 1; } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the application name being looked for # does not exist. We catch the exception and return immediately. # The 'fetch' frontend decides whether to throw a NoElementsFound # exception based on the value of 'allow_empty' $Log->debug( 'CommandFailedException caught. Requested application name does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } } ## end if ( exists( $filter->...)) my %state_base_field_settings; my %final_attributes; $state_base_field_settings{'username'} = $user_args->{'-username'}; $state_base_field_settings{'route'} = $user_args->{'-workflow'}; $state_base_field_settings{'vserver'} = $user_args->{'-vservername'}; %final_attributes = ( %final_attributes, %$parsed_output_users ); if ( $advance_users_field == 1 ) { $state_base_field_settings{'application'} = $advance_user_args->{'-applicationname'}; %final_attributes = ( %final_attributes, %$parsed_output_advance_users ); } ## end if ( $advance_users_field...) %final_attributes = ( %state_base_field_settings, %final_attributes ); my $obj = $pkg->new( command_interface => $command_interface ); $obj->_set_fields( row => \%final_attributes ); $Log->exit() if $may_exit; return $obj; } ## end sub _fetch_cmode_gui 1;