# # Copyright (c) 2001-2014 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Options ComponentState Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::Options =head1 DESCRIPTION C is a derived class of L. It represents the values of 7Mode/Node-scope options. If cluster-wide options need to be queried, then use L. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Options element are the attributes of the Options ComponentState. =over =item C<< name >> =item C<< value >> =item C<< cluster_constraint >> For ZAPI only. =back =cut package NACL::CS::Options; use strict; use warnings; use Params::Validate qw(validate); use base qw(NACL::CS::ComponentState::ONTAP); use NACL::APISet::Exceptions::InvalidParamValueException qw(:try); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Class::MethodMaker [ scalar => 'name', scalar => 'value', scalar => 'cluster_constraint', # Left behind for backwards compatibility, but are not used any more scalar => 'vserver', ]; # Purely for backwards compatibility no strict 'refs'; *option_name = *name; *option_value = *value; use strict 'refs'; =head1 METHODS =head2 fetch my $option_state = NACL::CS::Options->fetch(command_interface=>$ci,...); my @option_states = NACL::CS::Options->fetch(command_interface=>$ci,...); see L Uses a 7Mode/Nodescope CLI or a 7Mode ZAPI APISet. =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, choices => [ { method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode|Nodescope', }, { method => '_fetch_7mode_zapi', interface => 'ZAPI', set => '7Mode|Nodescope', }, ], exception_text => 'No matching options(s) found' ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_7mode_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = delete $opts{apiset}; my $filter_opts = delete $opts{filter}; my (%options_args, $output, $caught_exception); if (defined $filter_opts->{name}) { $options_args{'show-options'} = $filter_opts->{name}; } try { my $response = $apiset->options(%options_args); $output = $response->get_parsed_output(); } catch NACL::APISet::Exceptions::InvalidParamValueException with { $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my @state_objs; foreach my $key (keys %{$output->[0]}) { my $obj = $pkg->new(command_interface => $opts{command_interface}); my $modified_row = {name => $key, value => $output->[0]{$key}}; $obj->_set_fields(row => $modified_row); push @state_objs, $obj; } ## end foreach my $key ( keys %{ $output...}) $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli sub _fetch_7mode_zapi { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my @state_objs; my $response = $apiset->options_list_info(); my $output = $response->get_parsed_output(); foreach my $row (@{$output->[0]{options}[0]{'option-info'}}) { my $obj = $pkg->new(command_interface => $opts{command_interface}); my $row_modified = $pkg->_hash_copy( source => $row, copy => [qw(name value cluster_constraint)], ); $obj->_set_fields(row => $row_modified); push @state_objs, $obj; } ## end foreach my $row ( @{ $output...}) $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_zapi 1;