allow device renumber to an alias IP

This commit is contained in:
Oliver Gorwits
2015-04-26 23:13:20 +01:00
parent dadd7ba310
commit b208427834
3 changed files with 11 additions and 5 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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<undef> if $new_ip seems invalid, otherwise returns the
Device row object.
Device row object. Does NOT update the device C<dns> field.
=cut