# $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 Roles ComponentState Module ## @author vikas.p@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SysManager::Roles =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP Roles. A related class is L, which represents access to an ONTAP Roles. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Roles element are the attributes of the roles ComponentState. =over =item C<< role >> The name of the role element whose state is being represented. =item C<< route >> =item C<< command_name >> =item C<< query >> =item C<< access_level >> =item C<< vserver >> =back =cut package NACL::CS::SysManager::Roles; 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::Roles; # 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 => 'command_name', scalar => 'query', scalar => 'access_level', ]; =head1 METHODS =head2 fetch my $roles_state = NACL::CS::SysManager::Roles->fetch(command_interface => $ci,...); my @roles_states = NACL::CS::SysManager::Roles->fetch(command_interface => $ci,...); see L. Uses a CMode GUI APISet. (Works only when role 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 ( $parsed_output_roles, $parsed_output_advance_roles, $role_args, $advance_role_args, $advance_roles_field, $response, $caught_exception, ); $advance_roles_field = 0; my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; $role_args = $pkg->_hash_copy( source => $filter, map => { "role" => "-rolename", "route" => "-workflow", "vserver" => "-vservername", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(role route vserver)], ); try { # caling the gui api to get role status $response = $apiset->get_role_info(%$role_args); $parsed_output_roles = $response->get_parsed_output(); } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the role 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 role does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } if ( exists( $filter->{'command_name'} ) ) { $advance_role_args = $pkg->_hash_copy( source => $filter, map => { "role" => "-rolename", "command_name" => "-commandname", "route" => "-workflow", "vserver" => "-vservername", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(role command_name route vserver)], ); try { # caling the gui api to get command name status $response = $apiset->get_role_attribute_info(%$advance_role_args); $parsed_output_advance_roles = $response->get_parsed_output(); $advance_roles_field = 1; } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the command 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 command 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{'role'} = $role_args->{'-rolename'}; $state_base_field_settings{'route'} = $role_args->{'-workflow'}; $state_base_field_settings{'vserver'} = $role_args->{'-vservername'}; %final_attributes = ( %final_attributes, %$parsed_output_roles ); if ( $advance_roles_field == 1 ) { $state_base_field_settings{'command_name'} = $advance_role_args->{'-commandname'}; %final_attributes = ( %final_attributes, %$parsed_output_advance_roles ); } ## end if ( $advance_roles_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;