Hi @ollyg! Unfortunately I have found some issues with the code we finally released in #680: * get_port_macs expects an array ref but values() returns array, so the code was never called due to the return unless... check * When fw_mac_list had exactly two entries, only the second value was bound as a scalar to the parameter. This is probably due to the shorthand bind formats described in https://metacpan.org/pod/DBIx::Class::ResultSet#DBIC-BIND-VALUES, but I'm not a 100% on this. * return unless now checks for an entry in the list, with the old check the statement was also executed for empty lists In cases where only the device(_port)?.mac lookup worked for uplink detection, users of 02.044005 - 010 might get a lot of uplinks not labeled as such.
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
| package App::Netdisco::Util::PortMAC;
 | |
| 
 | |
| use Dancer qw/:syntax :script/;
 | |
| use Dancer::Plugin::DBIC 'schema';
 | |
| 
 | |
| use base 'Exporter';
 | |
| our @EXPORT = ();
 | |
| our @EXPORT_OK = qw/ get_port_macs /;
 | |
| our %EXPORT_TAGS = (all => \@EXPORT_OK);
 | |
| 
 | |
| =head1 NAME
 | |
| 
 | |
| App::Netdisco::Util::PortMAC
 | |
| 
 | |
| =head1 DESCRIPTION
 | |
| 
 | |
| Helper subroutine to support parts of the Netdisco application.
 | |
| 
 | |
| There are no default exports, however the C<:all> tag will export all
 | |
| subroutines.
 | |
| 
 | |
| =head1 EXPORT_OK
 | |
| 
 | |
| =head2 get_port_macs
 | |
| 
 | |
| Returns a Hash reference of C<< { MAC => IP } >> for all interface MAC
 | |
| addresses supplied as array reference
 | |
| 
 | |
| =cut
 | |
| 
 | |
| sub get_port_macs {
 | |
|     my ($fw_mac_list) = $_[0];
 | |
|     my $port_macs = {};
 | |
|     return {} unless ref [] eq ref $fw_mac_list and @{$fw_mac_list} >= 1;
 | |
| 
 | |
|     my $bindarray = [ { sqlt_datatype => "array" }, $fw_mac_list ];
 | |
| 
 | |
|     my $macs
 | |
|         = schema('netdisco')->resultset('Virtual::PortMacs')->search({},
 | |
|         { bind => [$bindarray], select => [ 'mac', 'ip' ], group_by => [ 'mac', 'ip' ] } );
 | |
|     my $cursor = $macs->cursor;
 | |
|     while ( my @vals = $cursor->next ) {
 | |
|         $port_macs->{ $vals[0] } = $vals[1];
 | |
|     }
 | |
| 
 | |
|     return $port_macs;
 | |
| }
 | |
| 
 | |
| 1;
 |