implement dynamic sizing option

This commit is contained in:
Oliver Gorwits
2017-12-24 18:12:04 +00:00
parent e4b19be5d7
commit 938848551e
7 changed files with 63 additions and 15 deletions

View File

@@ -191,6 +191,15 @@ Returns the row from the community string table, if one exists.
__PACKAGE__->might_have(
community => 'App::Netdisco::DB::Result::Community', 'ip');
=head2 throughput
Returns a sum of speeds on all ports on the device.
=cut
__PACKAGE__->has_one(
throughput => 'App::Netdisco::DB::Result::Virtual::DevicePortSpeed', 'ip');
=head1 ADDITIONAL METHODS
=head2 is_pseudo

View File

@@ -11,10 +11,8 @@ __PACKAGE__->table('device_links');
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
SELECT dp.ip AS left_ip, dp.port AS left_port, dp.name AS left_descr,
dp.speed AS speed,
dp2.ip AS right_ip, dp2.port AS right_port, dp2.name AS right_descr
FROM ( SELECT device_port.ip, device_port.port, device_port.name,
device_port.speed,
device_port.remote_ip, device_port.remote_port
FROM device_port
WHERE device_port.remote_port IS NOT NULL ) dp
@@ -35,9 +33,6 @@ __PACKAGE__->add_columns(
'left_descr' => {
data_type => 'text',
},
'speed' => {
data_type => 'text',
},
'right_ip' => {
data_type => 'inet',
},

View File

@@ -0,0 +1,36 @@
package App::Netdisco::DB::Result::Virtual::DevicePortSpeed;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
__PACKAGE__->table('device_port_speed');
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
SELECT ip,
sum(btrim(speed, ' MGTbps')::float *
(CASE btrim(speed, ' 0123456789.')
WHEN 'Gbps' THEN 1000
WHEN 'Tbps' THEN 1000000
ELSE 1 END)) AS total
FROM device_port
WHERE type = 'ethernetCsmacd'
AND speed LIKE '%bps'
GROUP BY ip
ORDER BY total DESC
ENDSQL
);
__PACKAGE__->add_columns(
'total' => {
data_type => 'integer',
},
);
__PACKAGE__->belongs_to('device', 'App::Netdisco::DB::Result::Device',
{ 'foreign.ip' => 'self.ip' });
1;