# # # Copyright (c) 2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # # ## @summary DiscoveryProtocol ComponentState Module ## @author rawat@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here ################################################################################ =head1 NAME NACL::CS::Switch::DiscoveryProtocol =head1 DESCRIPTION C is a derived class of L. It represents the state of DiscoveryProtocol element. A related class is L, which represents access to a DiscoveryProtocol element. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the DiscoveryProtocol element are the individual attributes of the DiscoveryProtocol ComponentState =over =item C<< device_id=>$string >> Filled in for CiscoNetwork and NetAppNetwor 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<< holdtime=>$string >> Filled in for CiscoNetwork and NetAppNetwor 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<< interface=>$string >> Filled in for CiscoNetwork and NetAppNetwor CLI. For 'filter': interface (Programmatic name:interface ) For 'requested_fields', Not applicable, but the field will be populated in the CS object. =item C<< port_id=>$string >> Filled in for CiscoNetwork and NetAppNetwor 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<< platform=>$string >> Filled in for CiscoNetwork and NetAppNetwor 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<< capability=>$array >> Filled in for CiscoNetwork and NetAppNetwor 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::DiscoveryProtocol; ################### # 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::Exceptions::NoElementsFound qw(:try); use NACL::APISet::Exceptions::InvalidParamValueException; use base 'NACL::CS::ComponentState::Switch'; use Class::MethodMaker [ # Common Components scalar => "device_id", scalar => "holdtime", scalar => "interface", scalar => "port_id", scalar => "platform", array => "capability", ]; =head1 METHODS =head2 fetch my $dps = NACL::CS::Switch::DiscoveryProtocol->fetch(command_interface=>$ci,...); my @dps = NACL::CS::Switch::DiscoveryProtocol->fetch(command_interface=>$ci,...); see L Supports CiscoNetwork and NetAppNetwork CLI. =over Invokes "show cdp neigbhors" command for CiscoNetwork CLI. Invokes "show isdp neigbhors" command for NetAppNetwork CLI. =back =cut sub fetch { $Log->enter(); my ($pkg, @opts) = @_; my @state_objs = $pkg->SUPER::fetch( @opts, choices => [ { method => "_fetch_cisconetwork_cli", interface => "CLI", set => "CiscoNetwork" }, { method => "_fetch_netappnetwork_cli", interface => "CLI", set => "NetAppNetwork" }, ], exception_text => 'No matching elements found' ); $Log->exit(); return wantarray ? @state_objs : $state_objs[0]; } sub _fetch_cisconetwork_cli { $Log->enter(); my ($pkg, @opts) = @_; my %opts = validate @opts, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my @state_objs; # get Discovery Protocol neighbors my $response = $apiset->show_cdp_neighbors(); my $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; } $Log->exit(); return @state_objs; } sub _fetch_netappnetwork_cli { $Log->enter(); my ($pkg, @opts) = @_; my %opts = validate @opts, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my @state_objs; 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 ($response, $caught_exception); try { if (defined $filter->{interface}) { $response = $apiset->show_isdp_neighbors( interface => $filter->{interface} ); } else { $response = $apiset->show_isdp_neighbors(); } } catch NACL::APISet::Exceptions::InvalidParamValueException with { $caught_exception = 1; }; if ($caught_exception) { $Log->exit(); return; } my $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; } $Log->exit(); return @state_objs; } 1;