# # Copyright (c) 2001-2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Volume ComponentState Module ## @author vikas.p@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SysManager::Volume =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP Volume present on the System Manger GUI Screen. A related class is L, which represents access to an ONTAP Volume present on the System Manger GUI Screen. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Volume element are the attributes of the volume ComponentState. =over =item C<< volume >> The name of the volume element whose state is being represented. =item C<< vserver >> =item C<< status >> =item C<< max >> =item C<< curfile >> =item C<< create_uni >> =item C<< split_status >> =item C<< state >> =back =cut package NACL::CS::SysManager::Volume; 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'; use NACL::C::SysManager::Volume; use NACL::Exceptions::NoElementsFound qw(:try); # Import Exception class use NACL::APISet::Exceptions::ResponseException qw(:try); use Class::MethodMaker [new => ['-hash', 'new'], scalar => 'vserver', scalar => 'volume', scalar => 'status', scalar => 'max', scalar => 'curfile', scalar => 'create_uni', scalar => 'split_status', scalar => 'aggregate', scalar => 'compression', scalar => 'thinprovision', scalar => 'percentageused', scalar => 'state', scalar => 'autogrow_maxsize', scalar => 'autogrow_increment', scalar => 'snapshot_autodelete', scalar => 'total_space', scalar => 'snapshot_space',]; =head1 METHODS =head2 fetch my $volume_state = NACL::CS::SysManager::Volume->fetch(command_interface => $ci,...); my @volume_states = NACL::CS::SysManager::Volume->fetch(command_interface => $ci,...); see L. Uses a CMode GUI or a 7Mode GUI APISet. (Works only if volume and vserver parameters are passed under filter option). =cut sub fetch { $Log->enter() if $may_enter; my $pkg = shift; my @state_objs = $pkg->SUPER::fetch( @_, choices => [{method => "_fetch_cmode_gui", set => "SysManager_CMode",}, {method => '_fetch_7mode_gui', set => 'SysManager_7Mode',},], exception_text => 'No matching volumes 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 = shift; my %opts = validate @_, $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 $vol_args = $pkg->_hash_copy(source => $filter, map => { "volume" => "-volname", "vserver" => "-vservername",}); my ($response, $caught_exception, $parsed_output); try { # caling the gui api to get volume status $response = $apiset->get_volume_info(%$vol_args); $parsed_output = $response->get_parsed_output(); } catch NACL::APISet::Exceptions::ResponseException with { # A caught exception indicates that the volume 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( 'ResponseException caught. Requested volume does ' . 'not exist'); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my %state_base_field_settings; $state_base_field_settings{'volume'} = $vol_args->{'-volname'}; $state_base_field_settings{'vserver'} = $vol_args->{'-vservername'}; $state_base_field_settings{'state'} = $parsed_output->{'status'}; 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 sub _fetch_7mode_gui { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $vol_args = $pkg->_hash_copy(source => $filter, map => {"volume" => "-volname",}); my ($response, $caught_exception, $parsed_output); try { # caling the gui api to get volume status $response = $apiset->get_volume_info(%$vol_args); $parsed_output = $response->get_parsed_output(); } catch NACL::APISet::Exceptions::ResponseException with { # A caught exception indicates that the volume 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( 'ResponseException caught. Requested volume does ' . 'not exist'); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my %state_base_field_settings; $state_base_field_settings{'volume'} = $vol_args->{'-volname'}; $state_base_field_settings{'state'} = $parsed_output->{'status'}; my %final_attributes = (%state_base_field_settings, %$parsed_output); my $obj = $pkg->new(command_interface => $opts{command_interface}); $obj->_set_fields(row => \%final_attributes); $Log->exit() if $may_exit; return $obj; } ## end sub _fetch_7mode_gui 1;