From b208427834d2beaf2d59f5fbbce2516e60dd5578 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 26 Apr 2015 23:13:20 +0100 Subject: [PATCH] allow device renumber to an alias IP --- Netdisco/Changes | 2 ++ Netdisco/bin/netdisco-do | 12 ++++++++---- Netdisco/lib/App/Netdisco/DB/Result/Device.pm | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index af2d7fe6..200398f3 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -3,10 +3,12 @@ [ENHANCEMENTS] * THANK YOUs + * Allow renumber of device to one of its alias IPs [BUG FIXES] * [#211] Additional check for undefined SNMP::Info instance + * Re-set hostname on device after renumber 2.032002 - 2015-04-03 diff --git a/Netdisco/bin/netdisco-do b/Netdisco/bin/netdisco-do index af6f9863..db511ddc 100755 --- a/Netdisco/bin/netdisco-do +++ b/Netdisco/bin/netdisco-do @@ -103,6 +103,7 @@ unless ($action) { use App::Netdisco::Util::SNMP (); use App::Netdisco::Util::Device qw/get_device delete_device renumber_device/; + use App::Netdisco::Util::DNS 'hostname_from_ip'; with 'App::Netdisco::Daemon::Worker::Poller::Device'; with 'App::Netdisco::Daemon::Worker::Poller::Arpnip'; @@ -163,14 +164,17 @@ unless ($action) { unless ($new_ip and $new_ip->addr ne '0.0.0.0') { return ('error', "Bad host or IP: ".($extra || '0.0.0.0')); } + my $new_dev = get_device($new_ip->addr); - unless ($new_dev and not $new_dev->in_storage) { - return ('error', sprintf "Already know new device: %s.", $device->ip); + if ($new_dev and $new_dev->in_storage and ($new_dev->ip ne $device->ip)) { + return ('error', sprintf "Already know new device as: %s.", $new_dev->ip); } renumber_device($device, $new_dev->ip); - return ('done', sprintf 'Renumbered device %s from %s to %s.', - $device->ip, $old_ip, $new_dev->ip); + my $hostname = hostname_from_ip($device->ip); + $device->update({dns => $hostname}); + return ('done', sprintf 'Renumbered device %s to %s (%s).', + $device->ip, $new_dev->ip, ($hostname || '')); } sub psql { diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Device.pm b/Netdisco/lib/App/Netdisco/DB/Result/Device.pm index 0195b9d4..132abbdf 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/Device.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/Device.pm @@ -193,7 +193,7 @@ __PACKAGE__->might_have( Will update this device and all related database records to use the new IP C<$new_ip>. Returns C if $new_ip seems invalid, otherwise returns the -Device row object. +Device row object. Does NOT update the device C field. =cut