# Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary LunIgroup ComponentState Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::LunIgroup =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP LunIgroup. A related class is L, which represents access to an ONTAP LunIgroup. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the LunIgroup element are the attributes of the LunIgroup ComponentState. =over =item C<< "initiator_group_vsa_enabled" >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< "uuid" >> Filled in for CMode CLI/ZAPI and 7M CLI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value 7M 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<< "igroup" >> Filled in for CMode CLI/ZAPI and 7Mode CLI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value 7M CLI: initiator group name (Programmatic name: "initiator-group") 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<< "ostype" >> Filled in for CMode CLI/ZAPI and 7M CLI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value 7M 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<< "init_details" >> (Array) Filled in for CMode CLI/ZAPI and 7M CLI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: @values 7M 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<< "iscsi" >> Filled in for CMode CLI. =item C<< "init_status" >> Filled in for CMode CLI. =item C<< "vserver" >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< "fcp" >> Filled in for CMode CLI. =item C<< "force" >> Filled in for CMode CLI. =item C<< "portset" >> Filled in for CMode CLI/ZAPI and 7M CLI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value 7M 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<< "initiator" >> (Array) Filled in for CMode CLI/ZAPI. Maps to : CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< "initiator_group_throttle_borrow" >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< "alua" >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< "initiator_group_throttle_reserve" >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< "init_alias" >> Filled in for CMode CLI. =item C<< "initiator_group_use_partner" >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< "lun_id" >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value =item C<< protocol >> Filled in for CMode CLI/ZAPI and 7Mode CLI. Maps to: CM ZAPI: For 'requested_fields', "filter" and Output mapping: $value 7M 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_uuid >> Vserver UUID Filled in for CMode CLI. =back =cut package NACL::CS::LunIgroup; use strict; use warnings; use Params::Validate qw(validate); use NACL::ComponentUtils qw(_dump_one Dumper); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use NACL::CS::ComponentState::ZapiSkip qw(make_zapi_skip); use NACL::CS::ComponentState::ZapiArray qw(make_zapi_array); use NACL::Exceptions::NoElementsFound qw(:try); use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'initiator_group_vsa_enabled', scalar => 'uuid', scalar => 'igroup', scalar => 'ostype', scalar => [ { -default_ctor => sub { return $_[0]->protocol(); } }, 'protocol_type' ], array => 'init_details', scalar => 'iscsi', scalar => 'init_status', scalar => 'vserver', scalar => 'fcp', scalar => 'force', scalar => 'portset', array => 'initiator', scalar => 'initiator_group_throttle_borrow', scalar => 'alua', scalar => 'initiator_group_throttle_reserve', scalar => 'init_alias', scalar => 'initiator_group_use_partner', scalar => 'lun_id', scalar => 'protocol', scalar => 'vserver_uuid', ]; =head1 METHODS =head2 fetch my $LunIgroup_state = NACL::CS::LunIgroup->fetch(command_interface => $ci, ...); my @LunIgroup_states = NACL::CS::LunIgroup->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, 7Mode CLI. Invokes "igroup-get-iter" API for CMode ZAPI. Invokes "igroup show" 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 = shift; my @state_objs = $pkg->SUPER::fetch( @_, show_cmd => 'lun igroup show', choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode' }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', }, { method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode' }, ], exception_text => 'No matching lun igroup(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 => 'lun_igroup_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, %opts) = @_; my @state_objs = $pkg->SUPER::_fetch_cmode_zapi( %opts, api => 'igroup_get_iter', copy => [ qw(vserver initiator-group-throttle-borrow initiator-group-throttle-reserve initiator-group-use-partner initiator-group-vsa-enabled lun-id) ], map => { "portset" => 'initiator-group-portset-name', "igroup" => 'initiator-group-name', "ostype" => 'initiator-group-os-type', "uuid" => 'initiator-group-uuid', "protocol" => 'initiator-group-type', "alua" => 'initiator-group-alua-enabled', "initiator" => [ make_zapi_array('initiators'), make_zapi_skip('initiator-info'), make_zapi_skip('initiator-name'), ], "init-details" => [ make_zapi_array('initiators'), make_zapi_skip('initiator-info'), make_zapi_skip('initiator-name'), ], }, ); my (@obj, @loggedin_intiators); my %req_field_filter = ( requested_fields => $opts{requested_fields}, filter => $opts{filter} ); if ($pkg->_want_any_field_of(%req_field_filter, fields_filled_by_api => [ qw(init-details) ])) { my $filter = {}; $filter = {vserver => $opts{filter}{vserver}} if defined $opts{filter}{vserver}; my %protocols_hash = map {$_->protocol() => 1} @state_objs; if (exists $protocols_hash{'iscsi'}) { require NACL::CS::VserverIscsiInitiator; @obj = NACL::CS::VserverIscsiInitiator->fetch( command_interface => $opts{command_interface}, apiset_should => {interface => 'ZAPI'}, filter => $filter, requested_fields => [qw(initiator-name)], allow_empty => 1, ); if (@obj) { foreach my $init_name (@obj) { push @loggedin_intiators, $init_name->initiator_name() if $init_name->initiator_name(); } } } if (exists $protocols_hash{'fcp'}) { require NACL::CS::VserverFcpInitiator; @obj = NACL::CS::VserverFcpInitiator->fetch( command_interface => $opts{command_interface}, apiset_should => {interface => 'ZAPI'}, filter => $filter, requested_fields => [qw(igroup)], allow_empty => 1, ); if (@obj) { foreach my $init_name (@obj) { push @loggedin_intiators, $init_name->wwpn() if $init_name->wwpn(); } } } } foreach my $obj (@state_objs) { my $init_array = $obj->init_details(); foreach my $init (@$init_array) { if ($init ne '-') { if (grep { $init eq $_ } @loggedin_intiators) { $init = "\"" . $init . " (logged in)\""; } else { $init = "\"" . $init . " (not logged in)\""; } } } $obj->init_details(@$init_array); } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi sub _fetch_7mode_cli { my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = delete $opts{apiset}; my %cmd_opts; my $caught_exception = 0; my %copy_filter = %{$opts{filter}}; my @copy_requested_fields = @{$opts{requested_fields}}; my $deleted_filter = $pkg->_remove_relational_regex_filters( filter => \%copy_filter, requested_fields => \@copy_requested_fields ); my $filter = \%copy_filter; my $requested_fields = \@copy_requested_fields; if ( ($filter->{'initiator-group-throttle-borrow'}) || ($filter->{'initiator-group-throttle-reserve'})) { $cmd_opts{'info-throttles'} = 1; } $cmd_opts{'initiator-group'} = $filter->{'igroup'}; my @state_objs; my $response; my $output; try { $response = $apiset->igroup_show(%cmd_opts); } catch NACL::APISet::Exceptions::CommandFailedException with { $caught_exception = 1; }; return if ($caught_exception); $output = $response->get_parsed_output(); foreach my $row (@$output) { my $obj = $pkg->new(); my $row_modified = $pkg->_hash_copy( source => $row, map => { 'initiator_group' => 'igroup', 'initiator_group_os' => 'ostype', 'initiator_group_uuid' => 'uuid', 'initiator_group_type' => 'protocol', 'port_set' => 'portset', 'initiator_group_node' => 'init_details', }, ); $row_modified->{'command_interface'} = $opts{'command_interface'}; $obj->_set_fields(row => $row_modified); push @state_objs, $obj; } ## end foreach my $row (@$output) return @state_objs; } ## end sub _fetch_7mode_cli 1;