Merge branch 'master' into og-autoload

Conflicts:
	Netdisco/share/public/javascripts/netdisco_portcontrol.js
This commit is contained in:
Oliver Gorwits
2014-07-31 21:32:30 +01:00
12 changed files with 124 additions and 48 deletions

View File

@@ -4,7 +4,7 @@ use strict;
use warnings;
use 5.010_000;
our $VERSION = '2.028012';
our $VERSION = '2.028013';
use App::Netdisco::Configuration;
use Module::Find ();

View File

@@ -43,7 +43,8 @@ setting('plugins')->{DBIC}->{daemon} = {
# defaults for workers
setting('workers')->{queue} ||= 'PostgreSQL';
setting('workers')->{interactives} ||= 1;
setting('workers')->{interactives} = 1
if setting('workers') and not exists setting('workers')->{interactives};
# force skipped DNS resolution, if unset
setting('dns')->{hosts_file} ||= '/etc/hosts';

View File

@@ -666,7 +666,7 @@ sub store_neighbors {
my $c_platform = $snmp->c_platform;
my $c_cap = $snmp->c_cap;
foreach my $entry (List::MoreUtils::uniq( (keys %$c_ip), (keys %$c_cap) )) {
foreach my $entry (sort (List::MoreUtils::uniq( (keys %$c_ip), (keys %$c_cap) ))) {
if (!defined $c_if->{$entry} or !defined $interfaces->{ $c_if->{$entry} }) {
debug sprintf ' [%s] neigh - port for IID:%s not resolved, skipping',
$device->ip, $entry;
@@ -695,11 +695,11 @@ sub store_neighbors {
my $phone_flag = grep {/phone/i} @$remote_cap;
my $ap_flag = grep {/wlanAccessPoint/} @$remote_cap;
if ($phone_flag or $remote_type =~ m/(mitel.5\d{3})/i) {
if ($phone_flag or $remote_type =~ m/mitel.5\d{3}/i) {
$remote_type = 'IP Phone: '. $remote_type
if $remote_type !~ /ip phone/i;
}
elsif ($ap_flag) {
elsif ($ap_flag or $remote_type =~ m/\bw?ap\b/i) {
$remote_type = 'AP: '. $remote_type;
}
@@ -730,7 +730,22 @@ sub store_neighbors {
if (!defined $neigh) {
my $mac = Net::MAC->new(mac => $remote_id, 'die' => 0, verbose => 0);
if (not $mac->get_error) {
$neigh = $devices->single({mac => $remote_id});
$neigh = $devices->single({mac => $mac->as_IEEE()});
}
}
# some HP switches send 127.0.0.1 as remote_ip if no ip address
# on default vlan for HP switches remote_ip looks like
# "myswitchname(012345-012345)"
if (!defined $neigh) {
(my $tmpid = $remote_id) =~ s/.([0-9a-f]{6})-([0-9a-f]{6})./$1$2/;
my $mac = Net::MAC->new(mac => $tmpid, 'die' => 0, verbose => 0);
if (not $mac->get_error) {
info sprintf
'[%s] neigh - found neighbor %s by MAC %s',
$device->ip, $remote_id, $mac->as_IEEE();
$neigh = $devices->single({mac => $mac->as_IEEE()});
}
}

View File

@@ -5,7 +5,7 @@ use Dancer::Plugin::DBIC 'schema';
use base 'Exporter';
our @EXPORT = ();
our @EXPORT_OK = qw/ add_jobs capacity_for take_jobs reset_jobs/;
our @EXPORT_OK = qw/ add_jobs capacity_for take_jobs reset_jobs release_jobs /;
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
schema('daemon')->deploy;
@@ -59,4 +59,11 @@ sub reset_jobs {
->update({wid => 0});
}
# not used by workers, only the daemon when reinitializing a worker
sub release_jobs {
my ($jid) = @_;
debug "releasing local job ID $jid";
$queue->search({job => $jid})->delete;
}
1;

View File

@@ -27,7 +27,16 @@ sub set_portcontrol {
(my $sa = $job->subaction) =~ s/-\w+//;
$job->subaction($sa);
return _set_port_generic($job, 'up_admin');
if ($sa eq 'bounce') {
$job->subaction('down');
my @stat = _set_port_generic($job, 'up_admin');
return @stat if $stat[0] ne 'done';
$job->subaction('up');
return _set_port_generic($job, 'up_admin');
}
else {
return _set_port_generic($job, 'up_admin');
}
}
sub set_vlan {

View File

@@ -143,12 +143,19 @@ sub jq_lock {
return $happy;
}
# PostgreSQL engine depends on LocalQueue, which is accessed synchronously via
# the main daemon process. This is only used by daemon workers which can use
# MCE ->do() method.
sub jq_defer {
my $job = shift;
my $happy = false;
# lock db row and update to show job is available
try {
# other local workers are polling the central queue, so
# to prevent a race, first delete the job in our local queue
MCE->do('release_jobs', $job->id);
# lock db row and update to show job is available
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Admin')
->find($job->id, {for => 'update'})