# # # Copyright (c) 2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # # ## @summary Mac ComponentState Module ## @author rawat@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here ################################################################################ =head1 NAME NACL::CS::Switch::Mac =head1 DESCRIPTION C is a derived class of L. It represents the state of Mac element. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Mac element are the individual attributes of the Mac ComponentState =over =item C<< 'address'=>$string >> (Required) MAC C<< address >> for which information is needed Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork CLI: For "filter": address (Programmatic name:address ) For 'requested_fields', Not applicable, but the field will be populated in the CS object. =item C<< 'mac_address'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'type'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'vlans'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'ports'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'age'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'learn'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'protocols'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'ntfy'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'secure'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'entry_type'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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<< 'seconds_since_last_seen'=>$string >> Filled in for CiscoNetwork CLI. Maps to: CiscoNetwork 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. =back =cut ################### # Package package NACL::CS::Switch::Mac; ################### # Everytime use strict; use warnings; ################### # Module includes 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::ComponentUtils qw (_dump_one); use NACL::Exceptions::NoElementsFound qw(:try); use NACL::APISet::Exceptions::InvalidParamValueException; use base 'NACL::CS::ComponentState::Switch'; use Class::MethodMaker [ # Primary Key scalar => "address", # Fields common to both IOS and Nexus OS scalar => "mac_address", scalar => "type", array => "vlans", array => "ports", # Fields for IOS scalar => "age", scalar => "learn", scalar => "protocols", # only on IOS 12.2(54)SG # Fields for Nexus OS scalar => "ntfy", scalar => "secure", scalar => "entry_type", scalar => "seconds_since_last_seen", ]; =head1 METHODS =head2 fetch my $mac = NACL::CS::Switch::Mac->fetch(command_interface=>$ci,...); my @macs = NACL::CS::Switch::Mac->fetch(command_interface=>$ci,...); see L Supports CiscoNetwork CLI. Invokes "show mac address table" command for CiscoNetwork CLI. =cut sub fetch { my $pkg = shift; my @state_objs = $pkg->SUPER::fetch( @_, choices => [ { method => "_fetch_cisconetwork_cli", interface => "CLI", set => "CiscoNetwork" }, ], exception_text => 'No matching elements found' ); return wantarray ? @state_objs : $state_objs[0]; } sub _fetch_cisconetwork_cli { my $pkg = shift; $Log->enter() if $may_enter; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my @state_objs; my ($output, $response, $obj, $caught_exception); # get MAC address table try { if (defined $filter->{address}) { $response = $apiset->show_mac_address_table(address => $filter->{address}); } else { $response = $apiset->show_mac_address_table(); } } catch NACL::APISet::Exceptions::InvalidParamValueException with { $caught_exception = 1; }; return if $caught_exception; $output = $response->get_parsed_output(); my @ports = @{$output->[0]->{ports}}; my $i = 0; foreach my $port (@ports) { $output->[0]->{ports}->[$i++]->{interface_type} = $pkg->_expand_interface_type($port->{interface_type}); } foreach my $row (@$output) { $obj = $pkg->new( command_interface => $opts{command_interface} ); $obj->_set_fields( row => $row ); push @state_objs, $obj; } $Log->exit() if $may_exit; return @state_objs; } 1;