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:
@@ -152,7 +152,7 @@
|
|||||||
},
|
},
|
||||||
"App::Netdisco::DB" : {
|
"App::Netdisco::DB" : {
|
||||||
"file" : "lib/App/Netdisco/DB.pm",
|
"file" : "lib/App/Netdisco/DB.pm",
|
||||||
"version" : "66"
|
"version" : "67"
|
||||||
},
|
},
|
||||||
"App::Netdisco::DB::ExplicitLocking" : {
|
"App::Netdisco::DB::ExplicitLocking" : {
|
||||||
"file" : "lib/App/Netdisco/DB/ExplicitLocking.pm"
|
"file" : "lib/App/Netdisco/DB/ExplicitLocking.pm"
|
||||||
@@ -855,7 +855,7 @@
|
|||||||
},
|
},
|
||||||
"homepage" : "http://netdisco.org/",
|
"homepage" : "http://netdisco.org/",
|
||||||
"license" : [
|
"license" : [
|
||||||
"http://opensource.org/licenses/bsd-license.php"
|
"http://opensource.org/licenses/BSD-3-Clause"
|
||||||
],
|
],
|
||||||
"repository" : {
|
"repository" : {
|
||||||
"url" : "https://github.com/netdisco/netdisco"
|
"url" : "https://github.com/netdisco/netdisco"
|
||||||
|
|||||||
4
META.yml
4
META.yml
@@ -38,7 +38,7 @@ provides:
|
|||||||
file: lib/App/Netdisco/Configuration.pm
|
file: lib/App/Netdisco/Configuration.pm
|
||||||
App::Netdisco::DB:
|
App::Netdisco::DB:
|
||||||
file: lib/App/Netdisco/DB.pm
|
file: lib/App/Netdisco/DB.pm
|
||||||
version: '66'
|
version: '67'
|
||||||
App::Netdisco::DB::ExplicitLocking:
|
App::Netdisco::DB::ExplicitLocking:
|
||||||
file: lib/App/Netdisco/DB/ExplicitLocking.pm
|
file: lib/App/Netdisco/DB/ExplicitLocking.pm
|
||||||
App::Netdisco::DB::Result:
|
App::Netdisco::DB::Result:
|
||||||
@@ -593,7 +593,7 @@ resources:
|
|||||||
MailingList: https://lists.sourceforge.net/lists/listinfo/netdisco-users
|
MailingList: https://lists.sourceforge.net/lists/listinfo/netdisco-users
|
||||||
bugtracker: https://github.com/netdisco/netdisco/issues
|
bugtracker: https://github.com/netdisco/netdisco/issues
|
||||||
homepage: http://netdisco.org/
|
homepage: http://netdisco.org/
|
||||||
license: http://opensource.org/licenses/bsd-license.php
|
license: http://opensource.org/licenses/BSD-3-Clause
|
||||||
repository: https://github.com/netdisco/netdisco
|
repository: https://github.com/netdisco/netdisco
|
||||||
version: '2.050003'
|
version: '2.050003'
|
||||||
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
|
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use Time::Piece; # for OO localtime
|
|||||||
|
|
||||||
use base 'Exporter';
|
use base 'Exporter';
|
||||||
our @EXPORT = ();
|
our @EXPORT = ();
|
||||||
our @EXPORT_OK = qw/update_stats/;
|
our @EXPORT_OK = qw/pretty_version update_stats/;
|
||||||
our %EXPORT_TAGS = (all => \@EXPORT_OK);
|
our %EXPORT_TAGS = (all => \@EXPORT_OK);
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
@@ -78,10 +78,23 @@ sub update_stats {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
# take perl or pg versions and make pretty
|
=head2 pretty_version ( $versionstring , $seglen )
|
||||||
|
|
||||||
|
Splits a string (only numbers and dots allowed) into a number of parts which
|
||||||
|
are seglen long, then removes all leading zeros from each part and returns
|
||||||
|
the parts joined by dots as one string.
|
||||||
|
|
||||||
|
Returns the original versionstring if unallowed characters are found or seglen
|
||||||
|
is negative.
|
||||||
|
|
||||||
|
Returns C<undef> if seglen is zero.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub pretty_version {
|
sub pretty_version {
|
||||||
my ($version, $seglen) = @_;
|
my ($version, $seglen) = @_;
|
||||||
return unless $version and $seglen;
|
return unless $version and $seglen;
|
||||||
|
return $version unless $seglen > 0;
|
||||||
return $version if $version !~ m/^[0-9.]+$/;
|
return $version if $version !~ m/^[0-9.]+$/;
|
||||||
$version =~ s/\.//g;
|
$version =~ s/\.//g;
|
||||||
$version = (join '.', reverse map {scalar reverse}
|
$version = (join '.', reverse map {scalar reverse}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ use Dancer::Plugin::Ajax;
|
|||||||
use Dancer::Plugin::DBIC;
|
use Dancer::Plugin::DBIC;
|
||||||
use Dancer::Plugin::Auth::Extensible;
|
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 App::Netdisco::Web::Plugin;
|
||||||
use NetAddr::IP::Lite ':lower';
|
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')
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
->create({
|
->create({
|
||||||
ip => param('ip'),
|
ip => param('ip'),
|
||||||
|
dns => (hostname_from_ip(param('ip')) || ''),
|
||||||
name => param('name'),
|
name => param('name'),
|
||||||
vendor => 'netdisco',
|
vendor => 'netdisco',
|
||||||
|
model => 'pseudodevice',
|
||||||
|
num_ports => param('ports'),
|
||||||
|
os => 'netdisco',
|
||||||
|
os_ver => pretty_version($App::Netdisco::VERSION, 3),
|
||||||
layers => param('layers'),
|
layers => param('layers'),
|
||||||
last_discover => \'now()',
|
last_discover => \'now()',
|
||||||
is_pseudo => \'true',
|
is_pseudo => \'true',
|
||||||
@@ -43,8 +50,8 @@ ajax '/ajax/control/admin/pseudodevice/add' => require_role admin => sub {
|
|||||||
return unless $device;
|
return unless $device;
|
||||||
|
|
||||||
$device->ports->populate([
|
$device->ports->populate([
|
||||||
[qw/port type/],
|
[qw/port type descr/],
|
||||||
map {["Port$_", 'other']} @{[1 .. param('ports')]},
|
map {["Port$_", 'other', "Port$_"]} @{[1 .. param('ports')]},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
# device_ip table is used to show whether topo is "broken"
|
# 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) {
|
if (param('ports') > $count) {
|
||||||
my $start = $count + 1;
|
my $start = $count + 1;
|
||||||
$device->ports->populate([
|
$device->ports->populate([
|
||||||
[qw/port type/],
|
[qw/port type descr/],
|
||||||
map {["Port$_", 'other']} @{[$start .. param('ports')]},
|
map {["Port$_", 'other', "Port$_"]} @{[$start .. param('ports')]},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
elsif (param('ports') < $count) {
|
elsif (param('ports') < $count) {
|
||||||
@@ -88,9 +95,13 @@ ajax '/ajax/control/admin/pseudodevice/update' => require_role admin => sub {
|
|||||||
})->delete;
|
})->delete;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$device->update({num_ports => param('ports')});
|
||||||
|
|
||||||
# also set layers
|
# also set layers
|
||||||
$device->update({layers => param('layers')});
|
$device->update({layers => param('layers')});
|
||||||
|
|
||||||
|
# and update last_discover, since device properties changed
|
||||||
|
$device->update({last_discover => \'now()'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,10 @@ UPDATE device SET is_pseudo = false;
|
|||||||
|
|
||||||
UPDATE device SET is_pseudo = true WHERE vendor = 'netdisco';
|
UPDATE device SET is_pseudo = true WHERE vendor = 'netdisco';
|
||||||
|
|
||||||
|
UPDATE device SET model = 'pseudodevice' WHERE vendor = 'netdisco';
|
||||||
|
|
||||||
|
UPDATE device SET os_ver = '2.51.0' WHERE vendor = 'netdisco' AND os_ver IS NULL;
|
||||||
|
|
||||||
|
UPDATE device SET os = 'netdisco' WHERE vendor = 'netdisco' AND os IS NULL;
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|||||||
Reference in New Issue
Block a user