# $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 NetworkPortIfgrp Component Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::NetworkPortIfgrp =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP NetworkPortIfgrp. A related class is L, which represents access to an ONTAP NetworkPortIfgrp. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the NetworkPortIfgrp element are the attributes of the NetworkPortIfgrp ComponentState. =over =item C<< "lacp" >> =item C<< "distr_func" >> Filled in for CMode CLI/ZAPI, 7Mode/Nodescope CLI. Maps to: CMode ZAPI: For "filter" Applicable, Filtering will be done by Components. For requested_fields and Output mapping: $value 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<< "down_ports" >> Filled in for CMode CLI/ZAPI and 7Mode CLI. Maps to: CMode ZAPI: For "filter" Applicable, Filtering will be done by Components. For requested_fields and Output mapping: @values 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<< "mode" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "filter" Applicable, Filtering will be done by Components. For requested_fields and Output mapping: $value 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<< "activeports" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "filter" Applicable, Filtering will be done by Components. For requested_fields and Output mapping: $value =item C<< "up_ports" >> Filled in for CMode CLI/ZAPI and 7Mode CLI. Maps to: CMode ZAPI: For "filter" Applicable, Filtering will be done by Components. For requested_fields and Output mapping: $value 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<< "node" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "filter", "requested_fields": node =item C<< "ports" >> Filled in for CMode CLI/ZAPI and 7Mode CLI. Maps to: CMode ZAPI: For "filter" Applicable, Filtering will be done by Components. For requested_fields and Output mapping: @values 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<< "mac" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "filter" Applicable, Filtering will be done by Components. For requested_fields and Output mapping: $value =item C<< "ifgrp" >> Filled in for CMode CLI/ZAPI, 7Mode/Nodescope CLI. Maps to: CMode ZAPI: For "filter", "requested_fields": ifgrp-name 7Mode CLI: For filter: ifgrp name(Programmatic name: "ifgrp-name") For "requested_fields" Not applicable, but the field will be populated in the CS object. =back =cut package NACL::CS::NetworkPortIfgrp; 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 base 'NACL::CS::ComponentState::ONTAP'; use NACL::APISet::Exceptions::CommandFailedException qw(:try); use NACL::APISet::Exceptions::InvalidParamValueException; use NACL::CS::ComponentState::ZapiSkip qw(make_zapi_skip); use NACL::CS::ComponentState::ZapiArray qw(make_zapi_array); use Class::MethodMaker [ scalar => 'lacp', scalar => 'distr_func', array => 'down_ports', scalar => 'mode', scalar => 'activeports', array => 'up_ports', scalar => 'node', array => 'ports', scalar => 'mac', scalar => 'ifgrp', ]; =head1 METHODS =head2 fetch my $NetworkPortIfgrp_state = NACL::CS::NetworkPortIfgrp->fetch(command_interface => $ci, ...); my @NetworkPortIfgrp_states = NACL::CS::NetworkPortIfgrp->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. For ZAPI, 'ifgrp' and 'node' have to be provided in the filter. (these options are mandatory for the underlying ZAPI call) Supports CMode CLI/ZAPI, 7Mode CLI. Invokes "net-port-ifgrp-get" API for CMode ZAPI. Invokes "ifgrp status" command for 7Mode/Nodescope 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, choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', check => '_check_cmode_zapi', }, { method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode|Nodescope', }, ], exception_text => 'No matching network port ifgrp(s) found', show_cmd => 'network port ifgrp 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, @args) = @_; my @state_objs = $pkg->SUPER::_fetch_cmode_cli(@args, api => 'network_port_ifgrp_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 %ports_mapping; foreach my $field (qw(ports up-ports down-ports)) { $ports_mapping{$field} = [ make_zapi_array($field), make_zapi_skip('lif-bindable') ]; } my @state_objs = $pkg->_fetch_cmode_zapi_non_iter( @args, api => 'net-port-ifgrp-get', copy => [qw(node mode)], map => { ifgrp => 'ifgrp-name', 'distr-func' => 'distribution-function', mac => 'mac-address', activeports => 'port-participation', %ports_mapping, }, primary_keys => [qw(node ifgrp)], ); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi sub _check_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, @opts) = @_; $pkg->_base_check_non_iter(@opts, _primary_keys => [qw(node ifgrp)]); $Log->exit() if $may_exit; } sub _fetch_7mode_cli { my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = delete $opts{apiset}; my %cmd_opts; 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->{ifgrp}) { $cmd_opts{'ifgrp-name'} = $filter->{'ifgrp'}; } my @state_objs; my ($response, $output, $caught_exception); try { $response = $apiset->ifgrp_status(%cmd_opts); $output = $response->get_parsed_output(); } catch NACL::APISet::Exceptions::CommandFailedException with { my $exception = shift; my $error_text = $exception->text(); $Log->trace("Caught a CommandFailedException. Error:\n$error_text"); if ($error_text =~ /No configured ifgrps present/) { $caught_exception = 1; } else { # Let any other errors propagate back $Log->exit() if $may_exit; $exception->throw(); } ## end else [ if ( $error_text =~ /No configured ifgrps present/) } ## end with catch NACL::APISet::Exceptions::InvalidParamValueException with { $Log->trace('Caught an InvalidParamValueException'); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my $row; foreach $row (@$output) { my $obj = $pkg->new(); my @ports; my $active_ports; my @down_ports; my @up_ports; my $temp = $$row{'interfaces'}; my $no_active_ports = 0; foreach my $interface (@$temp) { push @ports, $$interface{'interface_name'}; if ($$interface{'state'} eq "up") { $no_active_ports++; } if ($$interface{'indication'} eq "down") { push @down_ports, $$interface{'interface_name'}; } if ($$interface{'indication'} eq "up") { push @up_ports, $$interface{'interface_name'}; } } ## end foreach my $interface (@$temp) my $row_modified = $pkg->_hash_copy( source => $row, map => { 'ifgrp_name' => 'ifgrp', 'transmit' => 'distr-func', 'ifgrp_type' => 'mode', }, ); if ($no_active_ports == 0) { $$row_modified{'activeports'} = 'none'; } elsif ($no_active_ports == @$temp) { $$row_modified{'activeports'} = 'full'; } else { $$row_modified{'activeports'} = 'partial'; } $$row_modified{'up-ports'} = \@up_ports; $$row_modified{'down-ports'} = \@down_ports; $$row_modified{'ports'} = \@ports; $$row_modified{'command_interface'} = $opts{'command_interface'}; $obj->_set_fields(row => $row_modified); push @state_objs, $obj; } ## end foreach $row (@$output) return @state_objs; } ## end sub _fetch_7mode_cli 1;