implementation of store_power

This commit is contained in:
Oliver Gorwits
2013-04-04 19:32:14 +01:00
parent b7fb8c64a0
commit c2ac19e647
4 changed files with 88 additions and 2 deletions

View File

@@ -110,6 +110,14 @@ Returns the set of ports on this Device.
__PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePort', 'ip' ); __PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePort', 'ip' );
=head2 power_modules
Returns the set of power modules on this Device.
=cut
__PACKAGE__->has_many( power_modules => 'App::Netdisco::DB::Result::DevicePower', 'ip' );
=head2 port_vlans =head2 port_vlans
Returns the set of VLANs known to be configured on Ports on this Device, Returns the set of VLANs known to be configured on Ports on this Device,

View File

@@ -25,6 +25,15 @@ __PACKAGE__->set_primary_key("ip", "module");
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 # Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:awZRI/IH2VewzGlxISsr7w # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:awZRI/IH2VewzGlxISsr7w
=head1 RELATIONSHIPS
=head2 device
Returns the entry from the C<device> table on which this power module was discovered.
=cut
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
# You can replace this text with custom code or comments, and it will be preserved on regeneration # You can replace this text with custom code or comments, and it will be preserved on regeneration
1; 1;

View File

@@ -45,7 +45,7 @@ sub discover {
store_interfaces($device, $snmp); store_interfaces($device, $snmp);
store_wireless($device, $snmp); store_wireless($device, $snmp);
store_vlans($device, $snmp); store_vlans($device, $snmp);
#store_power($device, $snmp); store_power($device, $snmp);
#store_modules($device, $snmp); #store_modules($device, $snmp);
return job_done("Ended Discover for $host"); return job_done("Ended Discover for $host");

View File

@@ -10,7 +10,7 @@ use base 'Exporter';
our @EXPORT = (); our @EXPORT = ();
our @EXPORT_OK = qw/ our @EXPORT_OK = qw/
store_device store_interfaces store_wireless store_device store_interfaces store_wireless
store_vlans store_vlans store_power
/; /;
our %EXPORT_TAGS = (all => \@EXPORT_OK); our %EXPORT_TAGS = (all => \@EXPORT_OK);
@@ -342,4 +342,73 @@ sub store_vlans {
}); });
} }
=head2 store_power( $device, $snmp )
Given a Device database object, and a working SNMP connection, discover and
store the device's PoE information.
The Device database object can be a fresh L<DBIx::Class::Row> object which is
not yet stored to the database.
=cut
sub store_power {
my ($device, $snmp) = @_;
my $p_watts = $snmp->peth_power_watts;
my $p_status = $snmp->peth_power_status;
if (!defined $p_watts) {
# TODO log
return;
}
# build device module power info suitable for DBIC
my @devicepower;
foreach my $entry (keys %$p_watts) {
push @devicepower, {
module => $entry,
power => $p_watts->{$entry},
status => $p_status->{$entry},
};
}
my $interfaces = $snmp->interfaces;
my $p_ifindex = $snmp->peth_port_ifindex;
my $p_admin = $snmp->peth_port_admin;
my $p_pstatus = $snmp->peth_port_status;
my $p_class = $snmp->peth_port_class;
my $p_power = $snmp->peth_port_power;
# build device port power info suitable for DBIC
my %portpower;
foreach my $entry (keys %$p_ifindex) {
my $port = $interfaces->{ $p_ifindex->{$entry} };
next unless $port;
my ($module) = split m/\./, $entry;
$portpower{$port} = [];
push @{$portpower{$port}}, {
module => $module,
admin => $p_admin->{$entry},
status => $p_pstatus->{$entry},
class => $p_class->{$entry},
power => $p_power->{$entry},
};
}
schema('netdisco')->txn_do(sub {
$device->power_modules->delete;
$device->power_modules->populate(\@devicepower);
foreach my $port (keys %portpower) {
my $port = $device->ports->find({port => $port});
$port->power->delete if $port->power;
$port->create_related('power', $portpower{$port});
}
});
}
1; 1;