slow, but sort of works

This commit is contained in:
Oliver Gorwits
2015-03-07 09:00:42 +00:00
parent 179ae2553f
commit 7a7c973f87
3 changed files with 114 additions and 1 deletions

View File

@@ -0,0 +1,82 @@
package App::Netdisco::DB::Result::Virtual::MLAGPeers;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
__PACKAGE__->table('mlag_peers');
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
SELECT d1.dns AS dns, dp1.ip AS ip, dp1.port AS port, dp1.slave_of AS lag,
d2.dns AS mid, dp2.ip AS mid_ip, dp2.port AS mid_port, dp2.slave_of AS mid_lag,
d3.dns AS peer, dp5.ip AS peer_ip, dp5.port AS peer_port, dp6.port AS peer_lag
FROM device_port dp1 LEFT JOIN device_port dp2
ON dp1.remote_ip = dp2.ip
AND dp1.remote_port = dp2.port
LEFT JOIN device_port dp3
ON dp2.ip = dp3.ip
AND dp2.slave_of = dp3.port
RIGHT JOIN device_port dp4
ON dp4.remote_ip != dp1.ip
AND dp3.ip = dp4.ip
AND dp3.port = dp4.slave_of
LEFT JOIN device_port dp5
ON dp4.remote_ip = dp5.ip
AND dp4.remote_port = dp5.port
LEFT JOIN device_port dp6
ON dp5.ip = dp6.ip
AND dp5.slave_of = dp6.port
LEFT JOIN device d1
ON dp1.ip = d1.ip
LEFT JOIN device d3
ON dp5.ip = d3.ip
LEFT JOIN device d2
ON dp3.ip = d2.ip
WHERE dp1.slave_of IS NOT NULL
AND dp5.ip IS NOT NULL
ORDER BY d1.dns, dp1.port
ENDSQL
);
__PACKAGE__->add_columns(
'dns' => {
data_type => 'text',
},
'ip' => {
data_type => 'inet',
},
'port' => {
data_type => 'text',
},
'lag' => {
data_type => 'text',
},
'mid' => {
data_type => 'text',
},
'mid_ip' => {
data_type => 'inet',
},
'mid_port' => {
data_type => 'text',
},
'mid_lag' => {
data_type => 'text',
},
'peer' => {
data_type => 'text',
},
'peer_ip' => {
data_type => 'inet',
},
'peer_port' => {
data_type => 'text',
},
'peer_lag' => {
data_type => 'text',
},
);
1;

View File

@@ -167,11 +167,30 @@ get '/ajax/content/device/ports' => require_login sub {
my $results = [ sort { &App::Netdisco::Util::Web::sort_port($a->port, $b->port) } $set->all ];
return unless scalar @$results;
# retrieve MLAG peers
my ($siblings, $peers) = ({}, {});
my $prs = schema('netdisco')->resultset('Virtual::MLAGPeers')
->search({ -or => [ {'me.ip' => $device->ip}, {'me.peer_ip' => $device->ip} ]});
while (my $p = $prs->next) {
if ($p->ip eq $device->ip) {
push @{$peers->{ $p->lag }},
{dns => $p->mid, ip => $p->mid_ip, port => $p->mid_port};
}
else {
push @{$siblings->{ $p->lag }},
{dns => $p->mid, ip => $p->mid_ip, port => $p->mid_port,
sibl_dns => $p->peer, sibl_ip => $p->peer_ip, sibl_lag => $p->peer_lag};
}
};
if (request->is_ajax) {
template 'ajax/device/ports.tt', {
results => $results,
nodes => $nodes_name,
nodes => $nodes_name,
device => $device,
peers => $peers,
siblings => $siblings,
vmember_ok => $vmember_ok,
}, { layout => undef };
}

View File

@@ -262,6 +262,17 @@
<td>
[% IF params.c_neighbors AND (row.remote_ip OR row.is_uplink) %]
[% IF row.neighbor %]
[% IF peers.exists(row.port) %]
[% FOREACH peer IN peers.item(row.port) %]
<i class="icon-link"></i>
<a href="[% uri_for('/device', self_options) %]&q=[% peer.ip | uri %]">
[% peer.dns.remove(settings.domain_suffix) || peer.ip | html_entity %]</a>
-
<a href="[% uri_for('/device', self_options) %]&q=[% peer.ip | uri %]&f=[% peer.port | uri %]&prefer=port">
[% peer.port | html_entity %]</a>
[% '<br/>' IF NOT loop.last %]
[% END %]
[% ELSE %]
<i class="icon-link[% ' text-warning' IF row.manual_topo %]"></i>
[% IF row.remote_type AND row.remote_type.match('(?i)ip.phone') %]
<i class="icon-phone"></i>&nbsp;
@@ -275,6 +286,7 @@
<a href="[% uri_for('/device', self_options) %]&q=[% row.neighbor.ip | uri %]&f=[% row.remote_port | uri %]&prefer=port">
[% row.remote_port | html_entity %]</a>
[% END %]
[% END %]
<br/>
[% IF params.neigh_id and (row.remote_id or row.remote_type) %]
([% 'id: '_ row.remote_id IF row.remote_id %]