#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

@@ -98,6 +98,12 @@ sub set_canonical_ip {
return if $new_ip eq $old_ip;
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)
or die "cannot renumber to: $new_ip"; # rollback