# # # Copyright (c) 2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # # ## @summary Vlan ComponentState Module ## @author rawat@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here ################################################################################ =head1 NAME NACL::CS::Switch::Vlan =head1 DESCRIPTION C is a derived class of L. It represents the state of Vlan element. A related class is L, which represents access to a Vlan element. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Vlan element are the individual attributes of the Vlan ComponentState =over =item C<< 'vlan_ids'=>$string >> (Required) VLAN C<< id(s) >> for which information is needed =back =cut ################### # Package package NACL::CS::Switch::Vlan; ################### # Everytime use strict; use warnings; ################### # Module includes use Params::Validate qw (validate); use NACL::ComponentUtils qw (_dump_one); use NACL::Exceptions::NoElementsFound qw(:try); use NACL::APISet::Exceptions::InvalidParamValueException qw(:try); use base 'NACL::CS::ComponentState::Switch'; use Class::MethodMaker [ # Primary Key scalar => "vlan_id", # Fields common to both IOS and Nexus OS scalar => "name", scalar => "status", array => "ports", # Fields for IOS scalar => "mtu", scalar => "type", ]; =head1 METHODS =head2 fetch my $vlan = NACL::CS::Switch::Vlan->fetch(command_interface=>$ci,...); my @vlan = NACL::CS::Switch::Vlan->fetch(command_interface=>$ci,...); see L =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; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my @state_objs; my $hosttype = $opts{command_interface}->hostrec()->hosttype(); my ($output, $response, $caught_exception); $pkg->_exit_config_modes_cisconetwork(apiset => $apiset); # get MAC address table try { $response = $apiset->show_vlan('vlan-ids' => $filter->{'vlan-id'}); } catch NACL::APISet::Exceptions::InvalidParamValueException with { my $exception = shift; my $error_text = $exception->text(); if ($error_text =~ /VLAN.*$filter->{'vlan-id'} not found in current VLAN database/) { $caught_exception = 1; } else { $exception->throw(); } }; return if ($caught_exception); $output = $response->get_parsed_output(); foreach my $row (@$output) { my $obj = $pkg->new( command_interface => $opts{command_interface} ); $obj->_set_fields( row => $row ); push @state_objs, $obj; } return @state_objs; } 1;