# $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 Disk ComponentState Module ## @author Neethu.George@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SysManager::Disk =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP Disk present on the System Manger GUI Screen. A related class is L, which represents access to an ONTAP Disk present on the System Manger GUI Screen. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the disk element are the attributes of the disk ComponentState. =over =item C<< disk >> The name of the disk element whose state is being represented. =item C<< aggregate >> =item C<< vendor_id >> =item C<< serial_no >> =item C<< zeroing_pcnt >> =item C<< broken_details >> =back =cut package NACL::CS::SysManager::Disk; 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::Disk; use NACL::APISet::Exceptions::ResponseException qw(:try); use NACL::APISet::Exceptions::CommandFailedException; use Class::MethodMaker [ scalar => 'disk', scalar => 'aggregate', scalar => 'vendor_id', scalar => 'serial_no', scalar => 'zeroing_pcnt', scalar => 'broken_details', ]; =head1 METHODS =head2 fetch my $disk_state = NACL::CS::SysManager::Disk->fetch(command_interface => $ci,...); my @disk_states = NACL::CS::SysManager::Disk->fetch(command_interface => $ci,...); see L. Uses a CMode GUI or a 7Mode GUI APISet. (Works only when disk parameter is 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", }, { method => '_fetch_7mode_gui', set => 'SysManager_7Mode', }, ], exception_text => 'No matching disks 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 $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; my $disk_args = $pkg->_hash_copy( source => $filter, map => { "disk" => "-diskname", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(disk)], ); my ( $response, $caught_exception, $parsed_output ); try { # caling the gui api to get disk status $response = $apiset->get_disk_info(%$disk_args); $parsed_output = $response->get_parsed_output(); } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the disk 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 disk does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my %state_base_field_settings; $state_base_field_settings{'disk'} = $disk_args->{'-diskname'}; 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 $disk_args = $pkg->_hash_copy( source => $filter, map => { "disk" => "-diskname", } ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(disk)], ); my ( $response, $caught_exception, $parsed_output ); try { # caling the gui api to get disk status $response = $apiset->get_disk_info(%$disk_args); $parsed_output = $response->get_parsed_output(); } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the disk 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 disk does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my %state_base_field_settings; $state_base_field_settings{'disk'} = $disk_args->{'-diskname'}; $state_base_field_settings{'aggregate'} = $parsed_output->{'diskaggr'}; $state_base_field_settings{'vendor_id'} = $parsed_output->{'diskvendorid'}; $state_base_field_settings{'serial_no'} = $parsed_output->{'diskserialno'}; $state_base_field_settings{'broken_details'} = $parsed_output->{'diskbrokendetails'}; $state_base_field_settings{'zeroing_pcnt'} = $parsed_output->{'diskzeroingpercentage'}; 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;