# $Id //depot/prod/test/UM6.0_integ/lib/NACL/CS/DFM/Option.pm$ # # Copyright (c) 2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Option ComponentState Module (auto-generated by CGT) ## @author vinothg,dl-mpo-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::DFM::Option =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP Option. A related class is L, which represents access to an ONTAP Option. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Option element are the attributes of the Option ComponentState. =over =item C<< object_type >> =item C<< option_names >> (Array) =item C<< option_value >> =item C<< option_name >> =back =cut package NACL::CS::DFM::Option; use strict; use warnings; use Params::Validate qw(validate validate_with SCALAR ARRAYREF HASHREF); use NACL::ComponentUtils qw(Dumper); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use base 'NACL::CS::ComponentState::DFM'; use Class::MethodMaker [ new => [ '-hash', 'new' ], scalar => 'object_type', array => 'option_names', scalar => 'option_value', scalar => 'option_name', scalar => 'default_value', scalar => 'long_name', scalar => 'value', scalar => 'name', scalar => 'pretty_default_value', scalar => 'pretty_value', scalar => 'requires_restart', ]; =head1 METHODS =head2 list NACL::CS::DFM::Option->list( command_interface => $ci, ...); or $Option_object->list(...); =for html (Class or instance method) This method is used to lists dfm options and their current values. This will only return values for hidden options if they are not the default value or are explicitly requested by name.

Options can be listed globally, or for a specific object. To list option values for a specific object, specify object-name-or-id and object-type. To list available options for a specific type of object, specify only object-type (output option values will not be returned in this case)

If you do not specify an object, then the option values returned will be the global option values, and the default values returned will be the global option defaults.

If you do specify an object, then the option values returned will be the values as applied to the specified object, and the default values returned will be the global option values.

For example, thresholds are defined globally, but can be overridden for specific objects.

To determine if the option value is overridden for a specific object, you can compare the value to the default value. Uses a DFM ZAPI APISet. =over =item Options =over =item C<< command_interface => $command_interface >> (Required for class method, Not Applicable for instance method) See L =item C<< apiset_must => $ruleset >> (Optional) See L =item C<< apiset_should => $ruleset >> (Optional) See L =item C<< 'option-names' => [ $option-name1, $option-name2, ... ] >> (Arrayref, even if only a single value is to be sent it should specified as an arrayref containing that single value) =item C<< 'object-type' => $hashref >> (Hashref, can be a reference to a hash or hashofarrays or hashofhashes) =item C<< 'method-timeout' => $time_in_seconds >> (Optional) The default NATE timeout is 60 seconds. If the command might take more time to complete, this option can be used to specify a larger timeout value. The value should be provided in seconds. =back =back =cut sub list { $Log->enter() if $may_enter; my $pkg_or_obj = shift; $Log->debug( "Opts to 'list' front end are:\n" . Dumper( \@_ ) ); my %opts = $pkg_or_obj->_common_validate_with( params => \@_, additional_spec => { 'object-type' => { type => HASHREF, optional => 1 }, 'option-names' => { type => ARRAYREF, optional => 1 }, _optional_scalars( qw( resource-key ) ), }, ); $pkg_or_obj->call_on_apiset( %opts, choices => [ { method => '_list_zapi', interface => 'ZAPI', set => 'DFM', }, ], ); $Log->exit() if $may_exit; } sub _list_zapi { $Log->enter() if $may_enter; my $pkg_or_obj = shift; my %opts = $pkg_or_obj->_validate_backend_opts(@_); delete $opts{command_interface}; my $apiset = delete $opts{apiset}; my $allowed_options = [ qw( object-type option-names resource-key ) ]; my %args; $pkg_or_obj->_hash_copy( source => \%opts, copy => $allowed_options, target => \%args, ); foreach my $array_element ('option-names') { if ( defined $args{$array_element} ) { $args{$array_element} = join ',', @{ $args{$array_element} }; } } $pkg_or_obj->_api_call_log_debug_opts( api => 'option_list', api_opts => \%args, ); $apiset->option_list(%args); $Log->exit() if $may_exit; } =head2 fetch my $Option_state = NACL::CS::DFM::Option->fetch(command_interface => $ci, ...); my @Option_states = NACL::CS::DFM::Option->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. =cut sub fetch { $Log->enter() if $may_enter; my $pkg = shift; my @state_objs = $pkg->SUPER::fetch( @_, choices => [ { method => '_fetch_zapi', interface => 'ZAPI', set => 'DFM', }, ], exception_text => 'No matching Option(s) found.', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } sub _fetch_zapi { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $command_interface = delete $opts{command_interface}; my $apiset = delete $opts{apiset}; my $allowed_options = [qw( object-type option-names resource-key )]; my %args; $pkg->_hash_copy( source => $opts{filter}, copy => $allowed_options, target => \%args, ); my $response = $apiset->option_list(%args); my $parsed_output = $response->get_parsed_output(); my @state_objs; my $outer_row; my $option_present_flag = 0; if ( defined $opts{'object-name'} || defined $opts{'object-type'} ) { $pkg->_hash_copy( source => $parsed_output->[0], target => $outer_row, copy => [qw( object-type object-name )] ); # Set flag $option_present_flag = 1; } my $output = $parsed_output->[0]->{'option-list'}->[0]->{'option'}; foreach my $row ( @{$output} ) { my $obj = $pkg->new(); $row->{'option-name'} = $row->{'name'}; $obj->_set_fields( row => $row ); # For the extra fields when some input is given if ($option_present_flag) { $obj->_set_fields( row => $outer_row ); } push( @state_objs, $obj ); } $Log->exit() if $may_exit; return @state_objs; } # Provide extra filter field sub _extra_filter_fields { $Log->enter() if $may_enter; $Log->exit() if $may_exit; return [qw( resource-key option-names )]; } # NOTE: This function can be removed if not needed # Overriding the implementation of ithe super class sub _check_for_invalid_requested_filter_fields { $Log->enter() if $may_enter; my ( $pkg, %temp_opts ) = @_; # De-referencing the original filter which is a user-defined # one so that that's not modified my %filter = %{ $temp_opts{'filter'} }; $temp_opts{filter} = \%filter; # Moving out all the fields which are not MethodMaker fields # but are allowed in filter $pkg->_hash_move( source => $temp_opts{'filter'}, move => [ qw( ) ] ); # Now call the base class implementation to check for any # invalid fields $pkg->SUPER::_check_for_invalid_requested_filter_fields(%temp_opts); $Log->exit() if $may_exit; } 1;