# Copyright (c) 2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Aggregate Fill Upto Percentage Task Module ## @author rbasavar@netapp.com ## @status shared ## @pod here package NACL::MTask::VolumeGrowth; use strict; use warnings; use base qw(NACL::STask::Volume); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Params::Validate qw(validate :types); use NACL::STask::Aggregate; use NACL::CS::Aggregate; use NATE::BaseException qw(:try); use NACL::STask::Volume; use NACL::STask::Vserver; use NACL::ComponentUtils qw(Dumper _optional_scalars); use Class::MethodMaker [ scalar => 'vserver', scalar => 'volume', ]; =head1 NAME NACL::MTask::VolumeGrowth =head1 DESCRIPTION C This task is used to create a Volume and fill Volume to specified percentage. (It fills dataspace , snapshot-reserved-space is ignored). Eg : If 100m volume is created with defaul percent snapshot space i.e 5% and percent_to_fill parameter is passed as 50%, then 50% of 95mb is filled ignoring 5mb snapshot space. It can be also used to modify the percentage space to be filled in same Volume . =head1 METHOD : create_and_fill =head2 Usage use NACL::MTask::VolumeGrowth; my $vol_obj = NACL::MTask::VolumeGrowth->create_and_fill( command_interface => $command_interface, Volume => $Volume, vserver => $Vserver, size => $size, aggregate => $Aggregate, nacltask_percent_to_fill => $percent, %other_options ); (Class method) Creates an Volume and fills it upto some percentage specified as a parameter . =head2 Parameters =over =item C<< command_interface => $command_interface >> (Required) As C. A component object that represents the host to which to send commands. =item C<< Volume => $Volume >> (Optional) If this is not specified, a random name is generated using L. =item C<< size => $Size > (Optional) In 7Mode, the "size" is defaulted to "20M". (CMode ONTAP defaults the value of "size" to 20M if not provided) =item C<< vserver => $Vserver > In CMode, if the vserver argument is not provided, a data-vserver is searched for and the one matching the aggr-list restriction of the aggregate chosen/provided is the one that's chosen. If there is no suitable aggregate/vserver combination satisifying the aggr-list requirements, then a L exception is thrown. =item C<< percent_to_fill => $percent >> (Required) This is percentage of Volume which needs to be filled before returning Volume Object . =item C<< other_options => %other_options >> These are apiset_must, apiset_should, method-timeout etc . =back =head2 Returns: Volume Object with specified percent filled. =head2 Exceptions: Throws the following exceptions directly: NACL::Exceptions::MissingArg and other exceptions as well. =cut sub create_and_fill { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my %opts = $pkg->_common_validate_with( params => \@args, additional_spec => { percent_to_fill => { type => SCALAR, optional => 0 }, }, allow_extra => 1, ignore_primary_keys => 1, ); my ( $percent, $command_interface, $file_size,$vserver, $vol_s_obj,$vol_obj, $self ); $percent = delete $opts{percent_to_fill}; if ( $percent == 100 || $percent == 0) { $Log->exit() if $may_exit; NATE::BaseException->throw( "Error: Given percent to fill number must " . "not be 100% or 0%. You gave $percent" ); } ## end if ( $percent_to_fill ...) $command_interface = $opts{command_interface}; $vserver = $opts{vserver}; $vol_obj = NACL::STask::Volume->create(%opts); $vol_s_obj = $vol_obj->state(); $vol_s_obj->{percent_snapshot_space} =~ /\d+/; my $percent_snapshot_space = $&; if($percent_snapshot_space == 0) { $file_size = int (( $vol_s_obj->size * ($percent/100) )/20 ); } else { $file_size = int((( $vol_s_obj->size - ( ( $percent_snapshot_space / 100 ) * $vol_s_obj->size ) ) * $percent/100)/20) ; } for ( my $i = 0 ; $i < 20 ; $i++ ) { NACL::STask::VolumeFile->create( command_interface => $command_interface, vserver => $vserver, path => "/vol/".$vol_obj->volume."/file$i", size => $file_size, ); } $opts{volume} = $vol_obj->volume; $opts{vserver} = $vserver; my %args; $pkg->_hash_copy( source => \%opts, copy => [qw(volume vserver command_interface)], target => \%args, ); $self = $pkg->new(%args); $Log->exit() if $may_exit; return $self; } =head1 METHOD : modify =head2 Usage $vol_obj->modify( nacltask_percent_to_fill => $percent,); (Instance method) Modifies percentage of Volume to be filled . =head2 Parameters =over =item C<< percent_to_fill => $percent >> (Required) This is percentage of Volume which needs to be filled . =back =head2 Returns: None. =head2 Exceptions: Throws the following exceptions directly: NACL::Exceptions::MissingArg and other exceptions as well. =cut sub modify { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my %opts = $pkg->_common_validate_with( params => \@args, additional_spec => { percent_to_fill => { type => SCALAR, optional => 0 }, }, allow_extra => 1, ignore_primary_keys => 1, ); my ( $percent, $command_interface, $volume, $vserver, $file_size ,$percent_snapshot_space ); $percent = delete $opts{percent_to_fill}; $volume = $opts{volume}; $vserver = $opts{vserver}; $command_interface = $opts{command_interface}; if ( $percent == 100 ) { $Log->exit() if $may_exit; NATE::BaseException->throw( "Error: Given percent to fill number must " . "not be 100%. You gave $percent" ); } ## end if ( $percent_to_fill ...) for ( my $i = 0 ; $i < 20 ; $i++ ) { NACL::STask::VolumeFile->purge( command_interface => $command_interface, vserver => $vserver, path => "/vol/$volume/file$i", ); } my $vol_obj = NACL::CS::Volume->fetch( command_interface => $command_interface, filter => { volume => $volume , vserver => $vserver}, requested_fields => [qw(size percent-snapshot-space)], ); $vol_obj->{percent_snapshot_space} =~ /\d+/; $percent_snapshot_space = $& ; if($percent_snapshot_space == 0) { $file_size = int (( $vol_obj->{size} * ($percent/100) )/20 ); } else { $file_size = int((( $vol_obj->{size} - ( ( $percent_snapshot_space / 100 ) * $vol_obj->{size} ) ) * $percent/100)/20) ; } for ( my $i = 0 ; $i < 20 ; $i++ ) { NACL::STask::VolumeFile->create( command_interface => $command_interface, vserver => $vserver, path => "/vol/$volume/file$i", size => $file_size, ); } $Log->exit() if $may_exit; } =head1 METHOD : purge =head2 Usage $vol_obj->purge(); (Instance method) Deletes the volume created in create_and_fill method =head2 Parameters None . =head2 Returns: None. =head2 Exceptions =over =item C This type of exception is thrown when an attempt is made to delete volume that does not exists. =item C This type of exception is thrown when verification fails for the deleted volume. =back =cut sub purge { $Log->enter() if $may_enter; my ($vol_obj , $command_interface, $volume, $vserver); $vol_obj = shift; $command_interface = $vol_obj->command_interface; $volume = $vol_obj->volume; $vserver = $vol_obj->vserver; NACL::STask::Volume->purge( command_interface => $command_interface, volume => $volume, vserver => $vserver, ); $Log->exit() if $may_exit; } sub new { my ( $pkg, %opts ) = @_; my $self = bless {}, $pkg; while ( my ( $key, $value ) = each %opts ) { $self->$key($value); } return $self; } 1;