1package App::Netdisco::Util::PortMAC; 2 3use Dancer qw/:syntax :script/; 4use Dancer::Plugin::DBIC 'schema'; 5 6use base 'Exporter'; 7our @EXPORT = (); 8our @EXPORT_OK = qw/ get_port_macs /; 9our %EXPORT_TAGS = (all => \@EXPORT_OK); 10 11=head1 NAME 12 13App::Netdisco::Util::PortMAC 14 15=head1 DESCRIPTION 16 17Helper subroutine to support parts of the Netdisco application. 18 19There are no default exports, however the C<:all> tag will export all 20subroutines. 21 22=head1 EXPORT_OK 23 24=head2 get_port_macs 25 26Returns a Hash reference of C<< { MAC => IP } >> for all interface MAC 27addresses supplied as array reference 28 29=cut 30 31sub get_port_macs { 32 my ($fw_mac_list) = $_[0]; 33 my $port_macs = {}; 34 return {} unless ref [] eq ref $fw_mac_list and @{$fw_mac_list} >= 1; 35 36 my $bindarray = [ { sqlt_datatype => "array" }, $fw_mac_list ]; 37 38 my $macs 39 = schema('netdisco')->resultset('Virtual::PortMacs')->search({}, 40 { bind => [$bindarray, $bindarray], select => [ 'mac', 'ip' ], group_by => [ 'mac', 'ip' ] } ); 41 my $cursor = $macs->cursor; 42 while ( my @vals = $cursor->next ) { 43 $port_macs->{ $vals[0] } = $vals[1]; 44 } 45 46 return $port_macs; 47} 48 491; 50