Give Pseudo Devices better OS, OS ver, Port Descr, Discovered, and DNS Name

* started pseudodevice rework
* give them a type, os, os_ver and num_ports
  * os_ver will be the netdisco version in which they were created
* give their ports the same value for device_port.descr as device_port.port
* add db update to fill out those fields if they are null, which is most likely
* update last_discover if you make changes to the device
* num_ports will not be updates by the db script, neither will device_port.descr

* use device.name, not device.dns for pseudo

* at least try and get reverse dns for pseudo, works if there is one

* add db revision to manifest

* take dns no config into account

* new meta

* new version

Co-authored-by: Oliver Gorwits <ollyg@users.noreply.github.com>
This commit is contained in:
nick n
2021-11-06 22:52:59 +01:00
committed by GitHub
parent dc1f76c1aa
commit 636aa07f2d
5 changed files with 40 additions and 10 deletions

View File

@@ -5,6 +5,8 @@ use Dancer::Plugin::Ajax;
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Util::DNS 'hostname_from_ip';
use App::Netdisco::Util::Statistics 'pretty_version';
use App::Netdisco::Web::Plugin;
use NetAddr::IP::Lite ':lower';
@@ -34,8 +36,13 @@ ajax '/ajax/control/admin/pseudodevice/add' => require_role admin => sub {
my $device = schema('netdisco')->resultset('Device')
->create({
ip => param('ip'),
dns => (hostname_from_ip(param('ip')) || ''),
name => param('name'),
vendor => 'netdisco',
model => 'pseudodevice',
num_ports => param('ports'),
os => 'netdisco',
os_ver => pretty_version($App::Netdisco::VERSION, 3),
layers => param('layers'),
last_discover => \'now()',
is_pseudo => \'true',
@@ -43,8 +50,8 @@ ajax '/ajax/control/admin/pseudodevice/add' => require_role admin => sub {
return unless $device;
$device->ports->populate([
[qw/port type/],
map {["Port$_", 'other']} @{[1 .. param('ports')]},
[qw/port type descr/],
map {["Port$_", 'other', "Port$_"]} @{[1 .. param('ports')]},
]);
# device_ip table is used to show whether topo is "broken"
@@ -68,8 +75,8 @@ ajax '/ajax/control/admin/pseudodevice/update' => require_role admin => sub {
if (param('ports') > $count) {
my $start = $count + 1;
$device->ports->populate([
[qw/port type/],
map {["Port$_", 'other']} @{[$start .. param('ports')]},
[qw/port type descr/],
map {["Port$_", 'other', "Port$_"]} @{[$start .. param('ports')]},
]);
}
elsif (param('ports') < $count) {
@@ -88,9 +95,13 @@ ajax '/ajax/control/admin/pseudodevice/update' => require_role admin => sub {
})->delete;
}
}
$device->update({num_ports => param('ports')});
# also set layers
$device->update({layers => param('layers')});
# and update last_discover, since device properties changed
$device->update({last_discover => \'now()'});
});
};