node search by mac implementation

This commit is contained in:
Oliver Gorwits
2012-01-08 17:55:53 +00:00
parent af7a74c316
commit 51c88eefdc
5 changed files with 130 additions and 13 deletions

View File

@@ -0,0 +1,26 @@
package Netdisco::DB::ResultSet::Node;
use base 'DBIx::Class::ResultSet';
sub by_mac {
my ($set, $archive, $mac) = @_;
return $set unless $mac;
return $set->search(
{
'me.mac' => $mac,
($archive ? () : (active => 1)),
},
{
order_by => {'-desc' => 'time_last'},
columns => [qw/ mac switch port oui active device.dns /],
'+select' => [
\"to_char(time_first, 'YYYY-MM-DD HH24:MI')",
\"to_char(time_last, 'YYYY-MM-DD HH24:MI')",
],
'+as' => [qw/ time_first time_last /],
join => 'device',
},
);
}
1;

View File

@@ -57,4 +57,20 @@ sub by_name {
);
}
sub by_mac {
my ($set, $archive, $mac) = @_;
return $set unless $mac;
return $set->search(
{
mac => $mac,
($archive ? () : (active => 1)),
},
{
%$search_attr,
( $set->has_dns_col ? ('+columns' => 'dns') : () ),
}
);
}
1;