keep port custom_fields in place across device discovery

This commit is contained in:
Oliver Gorwits
2022-12-11 16:54:07 +00:00
parent 97f40539e9
commit 22210b26b7

View File

@@ -371,6 +371,12 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
vars->{'hook_data'}->{'ports'} = [values %deviceports];
schema('netdisco')->resultset('DevicePort')->txn_do_locked(sub {
# backup the custom_fields
my @fields = grep {exists $deviceports{$_->{port}}} $device->ports
->search(undef, {columns => [qw/port custom_fields/]})->hri->all;
$deviceports{$_->{port}}->{custom_fields} = $_->{custom_fields}
for @fields;
my $gone = $device->ports->delete({keep_nodes => 1});
debug sprintf ' [%s] interfaces - removed %d interfaces',
$device->ip, $gone;