From df54d5e4f9079cc1aac54d897e185c9ba6284542 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 19 Dec 2012 22:23:04 +0000 Subject: [PATCH] new netdisco-deploy script to do all deployment tasks at once --- Netdisco/bin/netdisco-db-deploy | 48 ------------- Netdisco/bin/netdisco-deploy | 118 ++++++++++++++++++++++++++++++++ Netdisco/lib/App/Netdisco.pm | 21 +++++- 3 files changed, 137 insertions(+), 50 deletions(-) create mode 100755 Netdisco/bin/netdisco-deploy diff --git a/Netdisco/bin/netdisco-db-deploy b/Netdisco/bin/netdisco-db-deploy index 37308944..7e0f49a4 100755 --- a/Netdisco/bin/netdisco-db-deploy +++ b/Netdisco/bin/netdisco-db-deploy @@ -7,11 +7,6 @@ use App::Netdisco; use Dancer ':script'; use Dancer::Plugin::DBIC 'schema'; -use 5.10.0; -use Term::UI; -use Term::ReadLine; - -use HTTP::Tiny; use Try::Tiny; =head1 netdisco-db-deploy @@ -23,10 +18,6 @@ user with rights to create tables in that database. Both the table and user name must match those configured in your environment YAML file (default C). -Additionally this script will download the latest MAC address vendor prefix -data from the Internet, and update the OUI table in the database. Hence -Internet access is required to run the script. - Simply run this script, which connects to the database and runs without user interaction. If there's no Nedisco schema, it is deployed. If there's an unversioned schema then versioning is added, and updates applied. Otherwise @@ -56,20 +47,6 @@ Version 4 (not yet created) B =cut -say 'The following must be in place:'; -say ' * Internet access'; -say ' * Database added to PostgreSQL for Netdisco'; -say ' * User added to PostgreSQL with rights to the Database'; -say ' * "environments/development.yml" file configured with Database dsn/user/pass'; -say ''; - -my $term = Term::ReadLine->new('netdisco'); -my $bool = $term->ask_yn( - prompt => 'Ready to deploy?', default => 'n', -); - -exit(0) unless $bool; - my $schema = schema('netdisco'); # installs the dbix_class_schema_versions table with version "1" @@ -94,29 +71,4 @@ try { # upgrade from whatever dbix_class_schema_versions says, to $VERSION $schema->txn_do(sub { $schema->upgrade }); -# now populate/update the OUI data - -my $url = 'http://standards.ieee.org/develop/regauth/oui/oui.txt'; -my $resp = HTTP::Tiny->new->get($url); -my %data = (); - -if ($resp->{success}) { - foreach my $line (split /\n/, $resp->{content}) { - if ($line =~ m/^(.{2}-.{2}-.{2})\s+\(hex\)\s+(.*)\s*$/i) { - my ($oui, $company) = ($1, $2); - $oui =~ s/-/:/g; - $data{lc($oui)} = $company; - } - } - - if ((scalar keys %data) > 15_000) { - $schema->txn_do(sub{ - $schema->resultset('Oui')->delete; - $schema->resultset('Oui')->populate([ - map {{oui => $_, company => $data{$_}}} keys %data - ]); - }); - } -} - exit 0; diff --git a/Netdisco/bin/netdisco-deploy b/Netdisco/bin/netdisco-deploy new file mode 100755 index 00000000..8bad1781 --- /dev/null +++ b/Netdisco/bin/netdisco-deploy @@ -0,0 +1,118 @@ +#!/usr/bin/env perl + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use App::Netdisco; + +use Dancer ':script'; +use Dancer::Plugin::DBIC 'schema'; + +use 5.10.0; +use Term::UI; +use Term::ReadLine; + +use Archive::Extract; +use HTTP::Tiny; +use Try::Tiny; + +=head1 netdisco-deploy + +This script deploys the Netdisco database schema, OUI data, and MIBs. Each of +these is an optional service which the user is asked to confirm. + +Pre-existing requirements are that there be a database table created and a +user with rights to create tables in that database. Both the table and user +name must match those configured in your environment YAML file (default +C). + +This script will download the latest MAC address vendor prefix data from the +Internet, and update the OUI table in the database. Hence Internet access is +required to run the script. + +Similarly the latest Netdisco MIB bundle is also downloaded, placed into the +user's home directory, and Netdisco reconfigured for its use. + +=cut + +say 'This is the Netdisco II deployment script.'; +say ''; +say 'Before we continue, the following prerequisites must be in place:'; +say ' * Internet access'; +say ' * Database added to PostgreSQL for Netdisco'; +say ' * User added to PostgreSQL with rights to the Netdisco Database'; +say ' * "environments/development.yml" file configured with Database dsn/user/pass'; +say ''; +say 'You will be asked to confirm all changes to your system.'; +say ''; + +my $term = Term::ReadLine->new('netdisco'); +my $bool = $term->ask_yn( + prompt => 'So, is all the above in place?', default => 'n', +); + +exit(0) unless $bool; + +say ''; +$bool = $term->ask_yn( + prompt => 'Would you like to deploy or upgrade your database schema?', default => 'n', +); +deploy_db() if $bool; + +say ''; +$bool = $term->ask_yn( + prompt => 'Would you like to download and update vendor MAC prefixes (OUI data)?', default => 'n', +); +deploy_oui() if $bool; + +say ''; +$bool = $term->ask_yn( + prompt => 'Would you like to download and update MIB files?', default => 'n', +); +deploy_mibs() if $bool; + +sub deploy_db { system 'netdisco-db-deploy' } + +sub deploy_oui { + my $schema = schema('netdisco'); + $schema->source->disconnect; + + my $url = 'http://standards.ieee.org/develop/regauth/oui/oui.txt'; + my $resp = HTTP::Tiny->new->get($url); + my %data = (); + + if ($resp->{success}) { + foreach my $line (split /\n/, $resp->{content}) { + if ($line =~ m/^(.{2}-.{2}-.{2})\s+\(hex\)\s+(.*)\s*$/i) { + my ($oui, $company) = ($1, $2); + $oui =~ s/-/:/g; + $data{lc($oui)} = $company; + } + } + + if ((scalar keys %data) > 15_000) { + $schema->txn_do(sub{ + $schema->resultset('Oui')->delete; + $schema->resultset('Oui')->populate([ + map {{oui => $_, company => $data{$_}}} keys %data + ]); + }); + } + } + + say 'OUI update complete.'; +} + +sub deploy_mibs { + my $url = 'http://downloads.sourceforge.net/project/netdisco/netdisco-mibs/latest-snapshot/netdisco-mibs-snapshot.tar.gz'; + my $file = "$ENV{HOME}/netdisco-mibs-snapshot.tar.gz"; + my $resp = HTTP::Tiny->new->mirror($url, $file); + + if ($resp->{success}) { + my $ae = Archive::Extract->new(archive => $file, type => 'tgz'); + $ae->extract(to => $ENV{HOME}); + } + + say 'MIBs update complete.'; +} + +exit 0; diff --git a/Netdisco/lib/App/Netdisco.pm b/Netdisco/lib/App/Netdisco.pm index e1e238d7..0c198427 100644 --- a/Netdisco/lib/App/Netdisco.pm +++ b/Netdisco/lib/App/Netdisco.pm @@ -34,8 +34,13 @@ The contents of this distribution is the next major version of the Netdisco network management tool. See L for further information on the project. -If you have any trouble getting the frontend running, or it blows up in your -face, please speak to someone in the C<#netdisco> IRC channel (on freenode). +So far L provides a web frontend and a backend daemon to handle +interactive requests such as changing port or device properties. There is not +yet a device poller, so please still use the old Netdisco's discovery, arpnip, +and macsuck. + +If you have any trouble getting the frontend running, please speak to someone +in the C<#netdisco> IRC channel (on freenode). =head1 Dependencies @@ -103,6 +108,18 @@ to be appropriate for your local site. =head1 Bootstrap +The database either needs configuring if new, or updating from the current +release of Netdisco (1.x). You also need vendor MAC address prefixes (OUI +data) and some MIBs if you want to run the daemon. The following script will +take care of all this for you: + + DANCER_ENVDIR=~/environments localenv netdisco-deploy + +If you don't want that level of automation, check out the database schema diff +from the current release of Netdisco, and apply it yourself: + + ~/perl5/lib/perl5/App/Netdisco/DB/schema_versions/Netdisco-DB-2-3-PostgreSQL.sql + =head1 Startup Run the following command to start the web server: