# # Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary NetworkPort ComponentState Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::NetworkPort =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP NetworkPort. A related class is L, which represents access to an ONTAP NetworkPort. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the NetworkPort element are the attributes of the NetworkPort ComponentState. =over =item C<< "aggr_node" >> Filled in for CMode CLI. =item C<< "aggr_distr_func" >> Filled in for CMode CLI. =item C<< "autonegotiate_oper" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "vlan_node" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "ifgrp_mode" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "node" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "duplex_oper" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "vlan_tag" >> Filled in for CMode CLI. =item C<< "speed_actual" >> Filled in for CMode CLI. =item C<< "vlan_port" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "speed_admin" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "mac" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "mtu" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "link" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "ifgrp_node" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "ifgrp_port" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "speed_oper" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "port" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "flowcontrol_admin" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "autonegotiate_admin" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "ifgrp_distr_func" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "flowcontrol_oper" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "aggr_lacp" >> Filled in for CMode CLI. =item C<< "up_admin" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "duplex_admin" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "type" >> Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< "aggr_port" >> Filled in for CMode CLI. =item C<< "role" >> B. Use C instead. Filled in for CMode CLI/ZAPI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< autorevert_delay >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< ipspace >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: ipspace =item C<< remote_device_id >> Remote Device ID Filled in for CMode CLI. =item C<< dcb_state >> DCB State possible value(s) are, incapable,capable,operational Filled in for CMode CLI. =item C<< broadcast_domain >> Broadcast Domain Filled in for CMode CLI. =back =cut package NACL::CS::NetworkPort; 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::C::_Mixins::NetworkPort qw(:all); use NACL::Exceptions::NoElementsFound qw(:try); use NACL::C::_Mixins::NetworkPort qw(:all); use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'aggr_node', scalar => 'aggr_distr_func', scalar => 'autonegotiate_oper', scalar => 'vlan_node', scalar => 'ifgrp_mode', scalar => 'node', scalar => 'duplex_oper', scalar => 'vlan_tag', scalar => 'speed_actual', scalar => 'vlan_port', scalar => 'speed_admin', scalar => 'mac', scalar => 'mtu', scalar => 'link', scalar => 'ifgrp_node', scalar => 'ifgrp_port', scalar => 'speed_oper', scalar => 'port', scalar => 'flowcontrol_admin', scalar => 'autonegotiate_admin', scalar => 'ifgrp_distr_func', scalar => 'flowcontrol_oper', scalar => 'aggr_lacp', scalar => 'up_admin', scalar => 'duplex_admin', scalar => 'type', scalar => 'aggr_port', scalar => 'autorevert_delay', scalar => 'ipspace', scalar => 'remote_device_id', scalar => 'dcb_state', scalar => 'broadcast_domain', ]; # We used to have a MethodMaker entry for role with the -read_cb generating a # warning. Unfortunately we can't use -read_cb for MethodMaker because that # ends up getting invoked while storing the value as well (so would result # in one warning per row containing this field). Hence, we need to create # new methods that mimic MethodMaker. # For every scalar field 'foo' defined in MethodMaker, the following methods # get installed: "foo" (in get/set context); "foo_isset"; "foo_reset"; "foo_clear" no strict 'refs'; *role = sub { my ($self, $value) = @_; # Method is invoked with a package name to determine the data-type. # Simply returned if invoked without an object instance. return unless ref $self; if ($value) { $self->{role} = $value; return $value; } else { $Log->warn("The 'role' accessor method was invoked on " . 'NACL::CS::NetworkPort. With the IPSPaces changes, this field ' . 'is deprecated and should not be used. Switch to using ' . "'ipspace' instead"); return $self->{role}; } }; *role_isset = sub {exists $_[0]->{role}}; *role_reset = sub {delete $_[0]->{role}}; *role_clear = sub {$_[0]->{role} = undef}; use strict 'refs'; =head1 METHODS =head2 fetch my $NetworkPort_state = NACL::CS::NetworkPort->fetch(command_interface => $ci, ...); my @NetworkPort_states = NACL::CS::NetworkPort->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. Supports "net-port-get-iter" and "net-port-get" API for CMode ZAPI. "net-port-get" is selected when 1. selected interface is "ZAPI" and 2. zapi_type is selected as "non-iter" "net-port-get-iter" is default "ZAPI" API for fetch. =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 %opts = validate @args, $pkg->_fetch_validate_spec; # Modify the requested field array if 'role' is passed if (grep {/^role$/} @{$opts{requested_fields}}) { my @requested_fields = @{$opts{requested_fields}}; foreach (@requested_fields) { s/^role$/ipspace/; } $opts{requested_fields} = \@requested_fields; } # Modify the filter option if 'role' is part of filter if (exists $opts{filter}->{role}) { my %copy_filter = %{$opts{filter}}; $pkg->_map_role_to_ipspace(\%copy_filter); $opts{filter} = \%copy_filter; } my @state_objs = $pkg->SUPER::fetch( %opts, show_cmd => 'network port show', choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', zapi_type => 'none', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', zapi_type => 'iter', }, { method => '_fetch_cmode_zapi_non_iter', interface => 'ZAPI', set => 'CMode', zapi_type => 'non-iter', check => '_base_check_non_iter', }, ], exception_text => 'No matching network port(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, %opts) = @_; my @state_objs = $pkg->SUPER::_fetch_cmode_cli(%opts, api => 'network_port_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 $common_copy = $pkg->_common_zapi_copy(); my $common_map = $pkg->_common_zapi_map(); my @state_objs = $pkg->SUPER::_fetch_cmode_zapi( @opts, api => 'net-port-get-iter', copy => $common_copy, map => $common_map, ); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi sub _fetch_cmode_zapi_non_iter { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my $zapi_map = { 'link' => 'link-status', 'autonegotiate-admin' => 'is-administrative-auto-negotiate', 'duplex-admin' => 'administrative-duplex', 'speed-admin' => 'administrative-speed', 'type' => 'port-type', 'flowcontrol-admin' => 'administrative-flowcontrol', 'ifgrp-distr-func' => 'ifgrp-distribution-function', 'up-admin' => 'is-administrative-up', 'autonegotiate-oper' => 'is-operational-auto-negotiate', 'mac' => 'mac-address', 'duplex-oper' => 'operational-duplex', 'flowcontrol-oper' => 'operational-flowcontrol', 'speed-oper' => 'operational-speed', 'vlan-tag' => 'vlan-id', }; my $zapi_copy = [ qw(port node ifgrp-mode role mtu ipspace autorevert-delay ifgrp-node ifgrp-port remote-device-id vlan-node vlan-port) ]; my $obj = $pkg->SUPER::_fetch_cmode_zapi_non_iter( @args, api => 'net-port-get', copy => $zapi_copy, map => $zapi_map, primary_keys => [qw(node port)] ); $Log->exit() if $may_exit; return $obj; } ## end sub _fetch_cmode_zapi_non_iter sub _update_state_objs_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; $pkg->SUPER::_update_state_objs_cmode_zapi( %opts, zapi_field_translations => {hyphenate_value => [qw(type)]} ); $Log->exit() if $may_exit; } 1;