#317 when renumbering on discover, delete likely duplicate devices

This commit is contained in:
Oliver Gorwits
2017-06-24 16:50:41 +01:00
parent 154e37d762
commit 5a190682ed
2 changed files with 7 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
* #320 DNS subroutines are redefined * #320 DNS subroutines are redefined
* #318 ACLs with RegExp are very slow - aggressive resolver timeouts * #318 ACLs with RegExp are very slow - aggressive resolver timeouts
* #317 when renumbering on discover, delete likely duplicate devices
2.036001 - 2017-06-22 2.036001 - 2017-06-22

View File

@@ -98,6 +98,12 @@ sub set_canonical_ip {
return if $new_ip eq $old_ip; return if $new_ip eq $old_ip;
schema('netdisco')->txn_do(sub { schema('netdisco')->txn_do(sub {
# delete target device with the same vendor and serial number
schema('netdisco')->resultset('Device')->search({
ip => $new_ip, vendor => $device->vendor, serial => $device->serial,
})->delete;
# if target device exists then this will die
$device->renumber($new_ip) $device->renumber($new_ip)
or die "cannot renumber to: $new_ip"; # rollback or die "cannot renumber to: $new_ip"; # rollback