# # Copyright (c) 2001-2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary VolumeSnapshotAutodelete ComponentState Module (auto-generated by CGT) ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::VolumeSnapshotAutodelete =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP VolumeSnapshotAutodelete. A related class is L, which represents access to an ONTAP VolumeSnapshotAutodelete. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the VolumeSnapshotAutodelete element are the attributes of the VolumeSnapshotAutodelete ComponentState. =over =item C<< "delete_order" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "trigger" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "volume" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "defer_delete_prefix" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "destroy_list" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "vserver" >> Filled in for CMode CLI. =item C<< "target_free_space" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "commitment" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "defer_delete" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< "enabled" >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For 'requested_fields', Not applicable, but the field will be populated in the CS object =item C<< is_constituent >> Filled in for CMode CLI. =back =cut package NACL::CS::VolumeSnapshotAutodelete; use strict; use warnings; use Params::Validate qw(validate); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use NACL::APISet::Exceptions::InvalidParamValueException qw(:try); use NACL::Exceptions::InvalidChoice; use base 'NACL::CS::ComponentState::ONTAP'; use NACL::C::_Mixins::VolumeSnapshotAutodelete qw(:all); use NACL::CS::Volume; use Class::MethodMaker [ scalar => 'delete_order', scalar => 'trigger', scalar => 'volume', scalar => 'defer_delete_prefix', scalar => 'destroy_list', scalar => 'vserver', scalar => 'target_free_space', scalar => 'commitment', scalar => 'defer_delete', scalar => 'enabled', scalar => 'is_constituent', ]; =head1 METHODS =head2 fetch my $VolumeSnapshotAutodelete_state = NACL::CS::VolumeSnapshotAutodelete->fetch(command_interface => $ci, ...); my @VolumeSnapshotAutodelete_states = NACL::CS::VolumeSnapshotAutodelete->fetch(command_interface => $ci, ...); (Class method) Discovers which elements are present and returns their state in ComponentState objects. Called in scalar context it returns only one state object, in list context it returns all state objects. See L for a more detailed description along with a complete explanation of the options it accepts. Supports CMode CLI, CMode-ZAPI, 7Mode CLI. Invokes snapshot-autodelete-list-info for CMode-ZAPI. Invokes "snap autodelete" command for 7Mode CLI. =over =item Exceptions =over =item C When there are no elements matching the query specified or elements of that type doesn't exist, then this exception will be thrown. =back =back =cut sub fetch { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my @state_objs = $pkg->SUPER::fetch( @args, show_cmd => 'volume snapshot autodelete show', choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', check => '_check_zapi', }, { method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode', } ], exception_text => 'No matching volume snapshot autodelete(s) found' ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_cmode_cli { $Log->enter() if $may_enter; my $pkg = shift; my @state_objs = $pkg->SUPER::_fetch_cmode_cli(@_, api => 'volume_snapshot_autodelete_show'); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_cli sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $command_interface = $opts{command_interface}; my %zapi_override; $pkg->_handle_zapi_vserver_context( api_opts => \%zapi_override, vserver => $opts{filter}{vserver}, command_interface => $command_interface, ); my ($response, $caught_exception); try { $response = $apiset->snapshot_autodelete_list_info( volume => $opts{filter}{volume}, %zapi_override, ); } catch NACL::APISet::Exceptions::NoMatchingEntriesException with { $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my $output = $response->get_parsed_output(); my $row = $output->[0]{options}[0]{'snapshot-autodelete-info'}; # Output will be like: # [ # { 'option-name' => 'commitment', 'option-value' => 'try' }, # { 'option-name' => 'trigger', 'option-value' => 'volume' }, # ] # We transform this into a hash keyed by the option-name: # { commitment => 'try', trigger => 'volume' } # This will allow mapping into the state object. my %output_options; foreach my $option_hash (@$row) { $output_options{$option_hash->{'option-name'}} = $option_hash->{'option-value'}; } # CLI returns value with "%" at the end $output_options{target_free_space} .= '%'; my $state = $output_options{state}; my $final_state; if ($state eq 'on') { $final_state = 'true'; } elsif ($state eq 'off') { $final_state = 'false'; } else { $final_state = $state; } $output_options{state} = $final_state; my %cs_values = (volume => $opts{filter}{volume}, vserver => $zapi_override{'vserver-override-name'}); $pkg->_hash_copy( source => \%output_options, target => \%cs_values, copy => $pkg->_common_zapi_copy(), map => {reverse %{$pkg->_common_zapi_map()}}, ); my $cs = $pkg->new(command_interface => $command_interface); $cs->_set_fields(row => \%cs_values); $Log->exit() if $may_exit; return $cs; } # ZAPI allows querying only for an individual volume sub _check_zapi { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my $filter = $opts{filter}; my $single_check = sub { my ($opt_name, $opt_val) = @_; if (!defined $opt_val || $pkg->_check_relational_regex_filter(filter_value => $opt_val)) { my $msg = "Field '$opt_name' was not provided in the filter " . "but the ZAPI 'snapshot-autodelete-list-info' requires it " . 'to be provided, hence the ZAPI implementation could not be used'; $Log->comment($msg); $Log->exit() if $may_exit; NACL::Exceptions::InvalidChoice->throw($msg); } }; $single_check->('volume', $filter->{volume}); my %zapi_field; try { $pkg->_handle_zapi_vserver_context( api_opts => \%zapi_field, vserver => $filter->{vserver}, command_interface => $opts{command_interface}, ); } catch NATE::BaseException with {}; $single_check->('vserver', $zapi_field{'vserver-override-name'}); $Log->exit() if $may_exit; } sub _fetch_7mode_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my ($response, $caught_exception, $output, @vol_list, @all_vol, %row, %output, @state_objs); my $filter = $opts{filter}; if (exists($filter->{volume})) { push(@all_vol, $filter->{volume}); } else { my @cs = NACL::CS::Volume->fetch( command_interface => $opts{command_interface}, filter => {state => 'online'}, requested_fields => [qw(state)] ); foreach (@cs) { push @all_vol, $_->volume(); } } ## end else [ if ( exists( $filter->... foreach my $vol (@all_vol) { try { $response = $apiset->snap_autodelete('vol-name' => $vol); } catch NACL::APISet::Exceptions::InvalidParamValueException with { $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } $output = $response->get_parsed_output(); push(@vol_list, $output); } ## end foreach my $vol (@all_vol) foreach my $vol (@vol_list) { my @vol = @$vol; my $final_attributes = $pkg->_hash_copy( source => $vol[0], copy => [ qw( volume commitment trigger target_free_space delete_order defer_delete destroy_list ) ], map => { "prefix" => "defer-delete-prefix", "state" => "enabled", } ); if ($final_attributes->{enabled} eq 'on') { $final_attributes->{enabled} = 'true'; } else { $final_attributes->{enabled} = 'false'; } my $obj = $pkg->new(command_interface => $opts{command_interface}); $obj->_set_fields(row => $final_attributes); push(@state_objs, $obj); } ## end foreach my $vol (@vol_list) $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli 1;