Set canonical IP failed on synthesized cols (and was wrong anyway) (closes #35)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
* Update Print media CSS to handle new UI components
|
||||
* Deadlock in Discover over access to the device_ports table
|
||||
* Set canonical IP failed on synthesized cols (and was wrong anyway) (closes #35)
|
||||
|
||||
2.018000 - 2013-10-08
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use Try::Tiny;
|
||||
use base 'Exporter';
|
||||
our @EXPORT = ();
|
||||
our @EXPORT_OK = qw/
|
||||
set_canonical_ip
|
||||
store_device store_interfaces store_wireless
|
||||
store_vlans store_power store_modules
|
||||
store_neighbors discover_new_neighbors
|
||||
@@ -48,9 +49,6 @@ sub store_device {
|
||||
my $interfaces = $snmp->interfaces;
|
||||
my $ip_netmask = $snmp->ip_netmask;
|
||||
|
||||
# find root IP
|
||||
_set_canonical_ip($device, $snmp);
|
||||
|
||||
my $hostname = hostname_from_ip($device->ip);
|
||||
$device->dns($hostname) if $hostname;
|
||||
my $localnet = NetAddr::IP::Lite->new('127.0.0.0/8');
|
||||
@@ -118,7 +116,7 @@ sub store_device {
|
||||
});
|
||||
}
|
||||
|
||||
sub _set_canonical_ip {
|
||||
sub set_canonical_ip {
|
||||
my ($device, $snmp) = @_;
|
||||
|
||||
my $oldip = $device->ip;
|
||||
@@ -131,28 +129,26 @@ sub _set_canonical_ip {
|
||||
|
||||
# remove old device and aliases
|
||||
schema('netdisco')->txn_do(sub {
|
||||
my $gone = $device->device_ips->delete;
|
||||
debug sprintf ' [%s] device - removed %s aliases',
|
||||
$oldip, $gone;
|
||||
my $copy = schema('netdisco')->resultset('Device')
|
||||
->find({ip => $oldip});
|
||||
|
||||
# our special delete which is more efficient
|
||||
schema('netdisco')->resultset('Device')
|
||||
->search({ ip => $device->ip })->delete({keep_nodes => 1});
|
||||
|
||||
# a new row object from the old one
|
||||
$device = schema('netdisco')->resultset('Device')
|
||||
->new({ $device->get_columns });
|
||||
|
||||
debug sprintf ' [%s] device - deleted self', $oldip;
|
||||
|
||||
$device = schema('netdisco')->resultset('Device')
|
||||
->create({ $copy->get_columns, ip => $newip })
|
||||
if defined $copy;
|
||||
|
||||
# make nodes follow device
|
||||
schema('netdisco')->resultset('Node')
|
||||
->search({switch => $oldip})
|
||||
->update({switch => $newip});
|
||||
});
|
||||
|
||||
$device->ip($newip);
|
||||
}
|
||||
|
||||
# either root_ip is changed or unchanged, but it exists
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
my $revname = ipv4_from_hostname($snmp->name);
|
||||
if (setting('reverse_sysname') and $revname) {
|
||||
debug sprintf ' [%s] device - changing root IP to revname %s',
|
||||
@@ -161,6 +157,10 @@ sub _set_canonical_ip {
|
||||
}
|
||||
}
|
||||
|
||||
# either root_ip is changed or unchanged, but it exists
|
||||
return $device;
|
||||
}
|
||||
|
||||
=head2 store_interfaces( $device, $snmp )
|
||||
|
||||
Given a Device database object, and a working SNMP connection, discover and
|
||||
|
||||
@@ -71,6 +71,7 @@ sub discover {
|
||||
return job_error("discover failed: could not SNMP connect to $host");
|
||||
}
|
||||
|
||||
$device = set_canonical_ip($device, $snmp);
|
||||
store_device($device, $snmp);
|
||||
store_interfaces($device, $snmp);
|
||||
store_wireless($device, $snmp);
|
||||
|
||||
Reference in New Issue
Block a user