show aggreate parent in device ports

This commit is contained in:
Oliver Gorwits
2014-01-12 19:14:48 +00:00
parent 3a4beed2f1
commit 79c69f5a0f
4 changed files with 42 additions and 7 deletions

View File

@@ -183,6 +183,22 @@ __PACKAGE__->might_have(
} }
); );
=head2 agg_master
Returns another row from the C<device_port> table if this port is slave
to another in a link aggregate.
=cut
__PACKAGE__->belongs_to(
agg_master => 'App::Netdisco::DB::Result::DevicePort', {
'foreign.ip' => 'self.ip',
'foreign.port' => 'self.slave_of',
}, {
join_type => 'LEFT',
}
);
=head2 neighbor_alias =head2 neighbor_alias
When a device port has an attached neighbor device, this relationship will When a device port has an attached neighbor device, this relationship will

View File

@@ -64,9 +64,9 @@ sub with_is_free {
->search({}, ->search({},
{ {
'+columns' => { is_free => '+columns' => { is_free =>
\["up != 'up' and " \["me.up != 'up' and "
."age(now(), to_timestamp(extract(epoch from device.last_discover) " ."age(now(), to_timestamp(extract(epoch from device.last_discover) "
."- (device.uptime - lastchange)/100)) " ."- (device.uptime - me.lastchange)/100)) "
."> ?::interval", ."> ?::interval",
[{} => $interval]] }, [{} => $interval]] },
join => 'device', join => 'device',
@@ -93,11 +93,11 @@ sub only_free_ports {
->search_rs($cond, $attrs) ->search_rs($cond, $attrs)
->search( ->search(
{ {
'up' => { '!=' => 'up' }, 'me.up' => { '!=' => 'up' },
},{ },{
where => where =>
\["age(now(), to_timestamp(extract(epoch from device.last_discover) " \["age(now(), to_timestamp(extract(epoch from device.last_discover) "
."- (device.uptime - lastchange)/100)) " ."- (device.uptime - me.lastchange)/100)) "
."> ?::interval", ."> ?::interval",
[{} => $interval]], [{} => $interval]],
join => 'device' }, join => 'device' },

View File

@@ -108,6 +108,13 @@ get '/ajax/content/device/ports' => require_login sub {
$set = $set->search({-or => \@combi}); $set = $set->search({-or => \@combi});
} }
# get aggregate master status
$set = $set->search({}, {
'join' => 'agg_master',
'+select' => [qw/agg_master.up_admin agg_master.up/],
'+as' => [qw/agg_master_up_admin agg_master_up/],
});
# make sure query asks for formatted timestamps when needed # make sure query asks for formatted timestamps when needed
$set = $set->with_times if param('c_lastchange'); $set = $set->with_times if param('c_lastchange');

View File

@@ -66,10 +66,22 @@
[% ELSE %] [% ELSE %]
<td nowrap> <td nowrap>
[% END %] [% END %]
<a class="nd_linkcell nd_this-port-only" href="[% uri_for('/device', <a class="nd_this-port-only" href="[% uri_for('/device',
self_options) %]&q=[% params.q | uri %]&f=[% row.port | uri %]&prefer=port"> self_options) %]&q=[% params.q | uri %]&f=[% row.port | uri %]&prefer=port">
[% row.port | html_entity %] [% row.port | html_entity %]</a>
</a></td> [% IF row.slave_of %]<br/>
[% IF row.get_column('agg_master_up_admin') != 'up' %]
<i class="icon-angle-down"></i>
[% ELSIF row.get_column('agg_master_up') == 'up' %]
<i class="icon-angle-up text-success"></i>
[% ELSE %]
<i class="icon-angle-down text-error"></i>
[% END %]
<a class="nd_this-port-only" href="[% uri_for('/device',
self_options) %]&q=[% params.q | uri %]&f=[% row.slave_of | uri %]&prefer=port">
[% row.slave_of | html_entity %]</a>
[% END %]
</td>
[% END %] [% END %]
[% FOREACH config IN settings._extra_device_port_cols %] [% FOREACH config IN settings._extra_device_port_cols %]