# $Id$ # # Copyright (c) 2001-2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary ClusterImage ComponentState Module (auto-generated by CGT) ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::ClusterImage =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP ClusterImage. A related class is L, which represents access to an ONTAP ClusterImage. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the ClusterImage element are the attributes of the ClusterImage ComponentState. Additionally, the command_interface used to obtain the ComponentState object is also an attribute of the object. This makes it easier to obtain the component object corresponding to the CS object, using L. =over =item command_interface The command_interface with which the CS object was obtained. (Available in all CS objects regardless of requested_fields and the mode/interface) =item C<< version >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: Input: If this option is specified in, * For 'filter', current-version doesn't support this in the input options, so filtering for this option would be done by Component layer itself. * 'requested_fields', it would translate to $value Output: $value =item C<< date >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: Input: If this option is specified in, * For 'filter', date-installed doesn't support this in the input options, so filtering for this option would be done by Component layer itself. * 'requested_fields', it would translate to $value Output: $value =item C<< node >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: Input: If this option is specified in, * For 'filter', this would be invoked on the specified node passed. It maps to node-id in CMode ZAPI. * 'requested_fields', it would translate to $value Output: $value =item C<< previous_version >> Previous Version Filled in for CMode CLI. =back =cut package NACL::CS::ClusterImage; 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::Exceptions::NoElementsFound qw(:try); use NACL::Exceptions::InvalidChoice qw(:try); use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'version', scalar => 'date', scalar => 'node', scalar => 'previous_version', ]; =head1 METHODS =head2 fetch my $ClusterImage_state = NACL::CS::ClusterImage->fetch(command_interface => $ci, ...); my @ClusterImage_states = NACL::CS::ClusterImage->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/ZAPI. Invokes "cluster-image-get" API for CMode ZAPI. =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. =item C When node-name is not provided in the filter field & if apiset_must choice for 'interface' is set to ZAPI 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_cmode_cli', interface => 'CLI', set => 'CMode' }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', check => '_check_node_filter', } ], exception_text => 'No matching cluster image(s) found', show_cmd => 'cluster image show', ); $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 => 'cluster_image_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 @state_objs; my $cli_to_zapi_map = { 'node' => 'node-id', 'version' => 'current-version', 'date' => 'date-installed', }; try { my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $ci = $opts{command_interface}; my $apiset = $opts{apiset}; my $filter = $opts{filter}; my @requested_fields = @{$opts{requested_fields}}; my $requested_options = {}; my $desired_attributes = {}; foreach my $req_field (@requested_fields) { if (exists $cli_to_zapi_map->{$req_field}) { $desired_attributes->{$cli_to_zapi_map->{$req_field}} = 1; } } if (keys %$desired_attributes) { $requested_options->{'desired-attributes'} = $desired_attributes; } $pkg->_hash_copy( source => $filter, map => {'node' => 'node-id'}, target => $requested_options, ); my $cluster_response = $apiset->cluster_image_get(%$requested_options); my $cluster_output = $cluster_response->get_parsed_output(); foreach my $row ( @{$cluster_output->[0]{'attributes'}[0]{'cluster-image-info'}}) { %$cli_to_zapi_map = reverse %$cli_to_zapi_map; my $state_fields = $pkg->_zapi_hash_copy( source => $row, map => [%$cli_to_zapi_map], ); my $obj = $pkg->new(command_interface => $opts{command_interface}); $obj->_set_fields(row => $state_fields); push @state_objs, $obj; } } catch NACL::APISet::Exceptions::CommandNotFoundException with { @state_objs = $pkg->SUPER::_fetch_cmode_zapi( @args, api => 'cluster_image_get_iter', map => $cli_to_zapi_map, ); }; $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi sub _check_node_filter { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; if (!defined($opts{filter}->{node})) { $Log->exit() if $may_exit; NACL::Exceptions::InvalidChoice->throw( 'Could not use ZAPI, since the ZAPI cluster-image-get needs name of' . ' the node to fetch the cluster image information, but node ' . 'is not specified in the filter'); } $Log->exit() if $may_exit; } ## end sub _check_node_filter 1;