rename all the things

This commit is contained in:
Oliver Gorwits
2017-08-05 16:53:16 +01:00
parent 464c42d1f5
commit fd80096ca2
4 changed files with 230 additions and 222 deletions

View File

@@ -8,38 +8,38 @@ use App::Netdisco::Util::Permission qw/check_acl_no check_acl_only/;
use Scope::Guard;
use Try::Tiny;
Dancer::Factory::Hook->instance->install_hooks(
map {("before_$_", $_, "after_$_")}
@{ setting('core_phases') }
);
register 'register_core_driver' => sub {
my ($self, $driverconf, $code) = @_;
return error "bad param to register_core_driver"
unless ((ref sub {} eq ref $code) and (ref {} eq ref $driverconf)
and exists $driverconf->{phase} and exists $driverconf->{driver}
and Dancer::Factory::Hook->instance->hook_is_registered($driverconf->{phase}));
register 'register_core_worker' => sub {
my ($self, $workerconf, $code) = @_;
return error "bad param to register_core_worker"
unless ((ref sub {} eq ref $code) and (ref {} eq ref $workerconf)
and exists $workerconf->{driver});
# needs to be here for caller() context
$driverconf->{plugin} = (caller)[0];
my ($package, $phase) = ((caller)[0], undef);
if ($package =~ m/::(Discover|Arpnip|Macsuck|Expire|Nbtstat)::(\w+)/) {
$phase = lc( $1 .'_'. $2 );
}
else { return error "worker Package does not match standard naming" }
my $hook = sub {
$workerconf->{hook} ||= 'after';
return error "bad hook param to register_core_worker"
unless $workerconf->{hook} =~ m/^(?:before|on|after)$/;
my $worker = sub {
my $device = shift or return false;
my $no = (exists $driverconf->{no} ? $driverconf->{no} : undef);
my $only = (exists $driverconf->{only} ? $driverconf->{only} : undef);
my $no = (exists $workerconf->{no} ? $workerconf->{no} : undef);
my $only = (exists $workerconf->{only} ? $workerconf->{only} : undef);
my @newuserconf = ();
my @userconf = @{ setting('device_auth') || [] };
# reduce device_auth by driver, plugin, driver's only/no
# reduce device_auth by driver, plugin, worker's only/no
foreach my $stanza (@userconf) {
next if $no and check_acl_no($device, $no);
next if $only and not check_acl_only($device, $only);
next if exists $stanza->{driver}
and (($stanza->{driver} || '') ne $driverconf->{driver});
next if exists $stanza->{plugin}
and (($stanza->{plugin} || '') ne $driverconf->{plugin});
and (($stanza->{driver} || '') ne $workerconf->{driver});
push @newuserconf, $stanza;
}
@@ -48,17 +48,21 @@ register 'register_core_driver' => sub {
my $guard = guard { set(device_auth => \@userconf) };
set(device_auth => \@newuserconf);
# run driver
# run worker
my $happy = false;
try {
$code->($device, $driverconf);
$code->($device, $workerconf);
$happy = true;
}
catch { debug $_ };
return $happy;
};
Dancer::Factory::Hook->instance->register_hook($driverconf->{phase}, $hook);
my $hook = $workerconf->{hook} .'_'. $phase;
Dancer::Factory::Hook->instance->install_hooks($hook)
unless Dancer::Factory::Hook->instance->hook_is_registered($hook);
Dancer::Factory::Hook->instance->register_hook($hook, $worker);
};
register_plugin;
@@ -66,43 +70,38 @@ true;
=head1 NAME
App::Netdisco::Core::Plugin - Netdisco Backend Drivers
App::Netdisco::Core::Plugin - Netdisco Core Workers
=head1 Introduction
L<App::Netdisco>'s plugin system allows users to create backend I<drivers>
which use different I<transports> to gather information from network devices
and store in the database.
L<App::Netdisco>'s plugin system allows users to write I<workers> to gather
information from network devices using different I<transports> and store
results in the database.
For example, transports might be SNMP, SSH, or HTTPS. Drivers might be
For example, transports might be SNMP, SSH, or HTTPS. Workers might be
combining those transports with application protocols such as SNMP, NETCONF
(OpenConfig with XML), RESTCONF (OpenConfig with JSON), eAPI, or even CLI
scraping.
scraping. The combination of transport and protocol is known as a I<driver>.
Drivers can be restricted to certain vendor platforms using familiar ACL
Workers can be restricted to certain vendor platforms using familiar ACL
syntax. They are also attached to specific phases in Netdisco's backend
operation.
operation (discover, macsuck, etc).
=head1 Application Configuration
The C<collector_plugins> and C<extra_collector_plugins> settings list in YAML
format the set of Perl module names which are the plugins to be loaded.
The C<core_plugins> and C<extra_core_plugins> settings list in YAML format the
set of Perl module names which are the plugins to be loaded.
Any change should go into your local C<deployment.yml> configuration file. If
you want to view the default settings, see the C<share/config.yml> file in the
C<App::Netdisco> distribution.
Driver phases are in the C<core_phases> setting and for a given backend
action, the registered drivers at one or more phases will be executed if they
apply to the target device. Each phase ("X") also gets a C<before_X> and
C<after_X> phase added for preparatory or optional work, respectively.
=head1 How to Configure
The C<extra_collector_plugins> setting is empty, and used only if you want to
add new plugins but not change the set enabled by default. If you do want to
add to or remove from the default set, then create a version of
C<collector_plugins> instead.
The C<extra_core_plugins> setting is empty, and used only if you want to add
new plugins but not change the set enabled by default. If you do want to add
to or remove from the default set, then create a version of C<core_plugins>
instead.
Netdisco prepends "C<App::Netdisco::Core::Plugin::>" to any entry in the list.
For example, "C<Discover::Wireless::UniFi>" will load the
@@ -121,9 +120,9 @@ plugins. As an example, if your plugin is called
~netdisco/nd-site-local/lib/App/NetdiscoX/Core/Plugin/MyPluginName.pm
The order of the entries is significant, drivers being executed in the order
which they appear in C<collector_plugins> and C<extra_collector_plugins>
(although see L<App::Netdisco::Manual::WritingBackendDrivers> for caveats).
The order of the entries is significant, workers being executed in the order
which they appear in C<core_plugins> and C<extra_core_plugins> (although see
L<App::Netdisco::Manual::WritingCoreWorkers> for caveats).
Finally, you can also prepend module names with "C<X::>", to support the
"Netdisco extension" namespace. For example,