# # 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 dl-nacl-dev@netapp.com ## @status shared ## @pod here ################################################################################ =head1 NAME NACL::CS::Client::Vlan =head1 DESCRIPTION C is a derived class of L. It represents the state of Vlan. A related class is L, which represents access to an interface. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Vlan element are the attributes of the Vlan ComponentState. =over =item C<< interface >> Filled in for Linux CLI, Solaris CLI. =item C<< vlan-id >> Filled in for Linux CLI, Solaris CLI. =item C<< vlan-interface => $vlan_interface >> Filled in for Linux CLI, Solaris CLI. =item C<< rx_dropped >> Filled in for Linux CLI, Solaris CLI. =item C<< rx_packets >> Filled in for Linux CLI, Solaris CLI. =item C<< status >> Filled in for Linux CLI, Solaris CLI. =item C<< collisions >> Filled in for Linux CLI, Solaris CLI. =item C<< metric >> Filled in for Linux CLI, Solaris CLI. =item C<< hwaddr >> Filled in for Linux CLI, Solaris CLI. =item C<< link_encap >> Filled in for Linux CLI, Solaris CLI. =item C<< rx_frame >> Filled in for Linux CLI, Solaris CLI. =item C<< tx_bytes >> Filled in for Linux CLI, Solaris CLI. =item C<< txqueuelen >> Filled in for Linux CLI, Solaris CLI. =item C<< property >> Filled in for Linux CLI, Solaris CLI. =item C<< mtu >> Filled in for Linux CLI, Solaris CLI. =item C<< tx_carrier >> Filled in for Linux CLI, Solaris CLI. =item C<< tx_packets >> Filled in for Linux CLI, Solaris CLI. =item C<< rx_overruns >> Filled in for Linux CLI, Solaris CLI. =item C<< tx_dropped >> Filled in for Linux CLI, Solaris CLI. =item C<< rx_bytes >> Filled in for Linux CLI, Solaris CLI. =item C<< rx_errors >> Filled in for Linux CLI, Solaris CLI. =item C<< inet6_info >> Filled in for Linux CLI, Solaris CLI. =item C<< tx_overruns >> Filled in for Linux CLI, Solaris CLI. =item C<< tx_errors >> Filled in for Linux CLI, Solaris CLI. =cut package NACL::CS::Client::Vlan; use strict; use warnings; use base qw(NACL::CS::ComponentState::Client NACL::C::_Mixins::Vlan); use Params::Validate qw(validate SCALAR ); use NACL::APISet::Exceptions::ResponseException qw/:try/; use NACL::APISet::Exceptions::CommandFailedException; use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Class::MethodMaker [ scalar => 'vlan_id', scalar => 'vlan_interface', scalar => 'interface', scalar => 'rx_dropped', scalar => 'rx_packets', scalar => 'status', scalar => 'collisions', scalar => 'metric', scalar => 'hwaddr', scalar => 'link_encap', scalar => 'rx_frame', scalar => 'tx_bytes', scalar => 'txqueuelen', scalar => 'property', scalar => 'mtu', scalar => 'tx_carrier', scalar => 'tx_packets', scalar => 'rx_overruns', scalar => 'tx_dropped', scalar => 'rx_bytes', scalar => 'rx_errors', array => 'inet6_info', scalar => 'tx_overruns', scalar => 'tx_errors', ]; =head1 METHODS =head2 fetch my $vlan = NACL::CS::Client::Vlan->fetch(command_interface=>$ci,...); my @vlan = NACL::CS::Client::Vlan->fetch(command_interface=>$ci,...); see L Supports Linux/Solaris CLI. Invokes "ifconfig" command for Linux/Solaris 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_linux_cli", interface => "CLI", set => 'Linux', }, { method => '_fetch_solaris_cli', interface => 'CLI', set => 'Solaris', }, ], exception_text => 'Device not found' ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_linux_cli { my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; my %api_args; if (defined $filter->{'vlan-interface'}) { $api_args{'interface'} = $filter->{'vlan-interface'}; } elsif (defined $filter->{interface} && defined $filter->{'vlan-id'}) { $api_args{'interface'} = $pkg->_get_vlan_interface( command_interface => $opts{command_interface}, %$filter ); } my $apiset = $opts{apiset}; my ($caught_exception, @state_objs, $output, $response); try { $response = $apiset->ifconfig(%api_args); } catch NACL::APISet::Exceptions::CommandFailedException with { my $exception = shift; if ($exception->text() =~ /Device not found/) { $caught_exception = 1; } else { $Log->exit() if $may_exit; $exception->throw(); } }; if ($caught_exception) { $Log->exit() if $may_exit; return; } $output = $response->get_parsed_output(); foreach my $row (@$output) { if ($row->{interface} =~ /(\w+)\.(\d+)/) { $row->{vlan_id} = $2; $row->{vlan_interface} = delete $row->{interface}; $row->{interface} = $1; my $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; } ## end sub _fetch_linux_cli sub _fetch_solaris_cli { my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; my @state_obj; my %api_args; if (defined $filter->{'vlan-interface'}) { $api_args{'interface'} = $filter->{'vlan-interface'}; } elsif (defined $filter->{interface} && defined $filter->{'vlan-id'}) { $api_args{'interface'} = $pkg->_get_vlan_interface( command_interface => $opts{command_interface}, %$filter ); } my $apiset = $opts{apiset}; my ($caught_exception, @state_objs, $output, $response); try { if (!exists $api_args{'interface'}) { $response = $apiset->ifconfig(all => 1); } else { $response = $apiset->ifconfig(%api_args); } } catch NACL::APISet::Exceptions::CommandFailedException with { my $exception = shift; if ($exception->text() =~ /(no\s+such\s+interface)/) { $caught_exception = 1; } else { $Log->exit() if $may_exit; $exception->throw(); } }; if ($caught_exception) { $Log->exit() if $may_exit; return; } $output = $response->get_parsed_output(); foreach my $row (@$output) { my $res = $apiset->execute_raw_command( command => "dladm show-link $row->{interface}"); if ($res =~ /type: vlan/) { my $obj = $pkg->new(command_interface => $opts{command_interface}); $res =~ /^(\w+).*vlan\s+(\d+).*device:\s+(\w+)/; $row->{vlan_interface} = $1; $row->{vlan_id} = $2; $row->{interface} = $3; $obj->_set_fields(row => $row); push @state_objs, $obj; } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_solaris_cli 1;