diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/MLAGPeers.pm b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/MLAGPeers.pm new file mode 100644 index 00000000..20cb8f91 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/MLAGPeers.pm @@ -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(<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; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm index be8eb8f5..a691600f 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm @@ -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 }; } diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index b5e4ffcc..b528f0f9 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -262,6 +262,17 @@ [% 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) %] + + + [% peer.dns.remove(settings.domain_suffix) || peer.ip | html_entity %] + - + + [% peer.port | html_entity %] + [% '
' IF NOT loop.last %] + [% END %] + [% ELSE %] [% IF row.remote_type AND row.remote_type.match('(?i)ip.phone') %]   @@ -275,6 +286,7 @@ [% row.remote_port | html_entity %] [% END %] + [% END %]
[% IF params.neigh_id and (row.remote_id or row.remote_type) %] ([% 'id: '_ row.remote_id IF row.remote_id %]