App-Netdisco

 view release on metacpan or  search on metacpan

lib/App/Netdisco/DB/ResultSet/Device.pm  view on Meta::CPAN

package App::Netdisco::DB::ResultSet::Device;
use base 'App::Netdisco::DB::ResultSet';

use strict;
use warnings;

use Try::Tiny;
use Regexp::Common 'net';
use NetAddr::IP::Lite ':lower';
use NetAddr::MAC ();

require Dancer::Logger;

=head1 ADDITIONAL METHODS

=head2 device_ips_with_address_or_name( $address_or_name )

Returns a correlated subquery for the set of C<device_ip> entries for each
device. The IP alias or dns matches the supplied C<address_or_name>, using
C<ILIKE>.

=cut

sub device_ips_with_address_or_name {
  my ($rs, $q, $ipbind) = @_;
  $q ||= '255.255.255.255/32';

  return $rs->search(undef,{
    # NOTE: bind param list order is significant
    join => ['device_ips_by_address_or_name'],
    bind => [$q, $ipbind, $q],
  });
}

=head2 with_module_serials

Adds the C<module_serials.serial> field to the results using
C<module_serials> relation.

=cut

sub with_module_serials {
  my $rs = shift;
  return $rs->search(undef, {
    join => 'module_serials',
    '+columns' => [ qw/ module_serials.ip module_serials.index module_serials.serial / ],
    collapse => 1,
    distinct => 0,
  });
}

=head2 ports_with_mac( $mac )

Returns a correlated subquery for the set of C<device_port> entries for each
device. The port MAC address matches the supplied C<mac>, using C<ILIKE>.

=cut

sub ports_with_mac {
  my ($rs, $mac) = @_;
  $mac ||= '00:00:00:00:00:00';

  return $rs->search(undef,{
    # NOTE: bind param list order is significant
    join => ['ports_by_mac'],
    bind => [$mac],
  });



( run in 0.465 second using v1.01-cache-2.11-cpan-39bf76dae61 )