# $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 LunIgroup ComponentState Module ## @author vikas.p@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SysManager::LunIgroup =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP LunIgroup. A related class is L, which represents access to an ONTAP LunIgroup. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the LunIgroup element are the attributes of the LunIgroup ComponentState. =over =item C<< "vserver" >> =item C<< "initiators" >> =item C<< "igroup" >> =back =cut package NACL::CS::SysManager::LunIgroup; use strict; use warnings; use Params::Validate qw(validate); use NACL::ComponentUtils qw(_dump_one Dumper); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use NACL::Exceptions::NoElementsFound qw(:try); use base 'NACL::CS::ComponentState::SysManager'; use NACL::C::SysManager::LunIgroup; use NACL::Exceptions::NoElementsFound qw(:try); # Import Exception class use NACL::APISet::Exceptions::ResponseException qw(:try); use NACL::APISet::Exceptions::CommandFailedException; use Class::MethodMaker [ scalar => 'igroup', scalar => 'vserver', scalar => 'initiators', scalar => 'portset', scalar => 'os', scalar => 'type', ]; =head1 METHODS =head2 fetch my $LunIgroup_state = NACL::CS::SysManager::LunIgroup->fetch(command_interface => $ci, ...); my @LunIgroup_states = NACL::CS::SysManager::LunIgroup->fetch(command_interface => $ci, ...); see L. Uses a CMode GUI or a 7Mode GUI APISet. (Works only when igroup and vserver parameters are passed under filter option). =cut ####################### GUI Fetch ############################### 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", }, { method => '_fetch_7mode_gui', set => 'SysManager_7Mode', }, ], exception_text => 'No matching igroup found', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch ####################### GUI CMode Fetch ############################### sub _fetch_cmode_gui { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; my $lun_igroup_args = $pkg->_hash_copy( source => $filter, map => { "igroup" => "-igroupname", "vserver" => "-vservername", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(igroup vserver)], ); my ( $response, $caught_exception, $parsed_output ); try { # caling the gui api to get igroup status $response = $apiset->get_igroup_info(%$lun_igroup_args); $parsed_output = $response->get_parsed_output(); } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the igroup 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 igroup does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my %state_base_field_settings; $state_base_field_settings{'igroup'} = $lun_igroup_args->{'-igroupname'}; $state_base_field_settings{'vserver'} = $lun_igroup_args->{'-vservername'}; my %final_attributes = ( %state_base_field_settings, %$parsed_output ); 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 ####################### GUI 7Mode Fetch ############################### sub _fetch_7mode_gui { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; my $lun_igroup_args = $pkg->_hash_copy( source => $filter, map => { "igroup" => "-igroupname", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(igroup)], ); my ( $response, $caught_exception, $parsed_output ); try { # caling the gui api to get igroup status $response = $apiset->get_igroup_info(%$lun_igroup_args); $parsed_output = $response->get_parsed_output(); } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the igroup 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 igroup does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my %state_base_field_settings; $state_base_field_settings{'igroup'} = $lun_igroup_args->{'-igroupname'}; my %final_attributes = ( %state_base_field_settings, %$parsed_output ); my $obj = $pkg->new( command_interface => $command_interface ); $obj->_set_fields( row => \%final_attributes ); $Log->exit() if $may_exit; return $obj; } ## end sub _fetch_7mode_gui 1;