diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm index 91933e90..fd46020c 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm @@ -86,14 +86,6 @@ The C variants add an additional column C, a preformatted value for the Node's C field, which reads as "X days/weeks/months/years". -=over 4 - -=item * - -Rows returned are sorted by the Node MAC address. - -=back - =cut __PACKAGE__->has_many( nodes => 'Netdisco::DB::Result::Node', @@ -205,7 +197,6 @@ the database. =cut -# make this more efficient by specifying the full join to DBIC? sub neighbor { my $row = shift; return eval { $row->neighbor_alias->device || undef }; diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePortVlanNative.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePortVlanNative.pm new file mode 100644 index 00000000..337923d8 --- /dev/null +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePortVlanNative.pm @@ -0,0 +1,19 @@ +use utf8; +package Netdisco::DB::Result::DevicePortVlanNative; + +use strict; +use warnings; + +use base 'Netdisco::DB::Result::DevicePortVlan'; + +__PACKAGE__->load_components('Helper::Row::SubClass'); +__PACKAGE__->subclass; + +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); +__PACKAGE__->table("device_port_vlan_native"); +__PACKAGE__->result_source_instance->is_virtual(1); +__PACKAGE__->result_source_instance->view_definition(q{ + SELECT * FROM device_port_vlan WHERE native +}); + +1; diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePortVlanTagged.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePortVlanTagged.pm index 117b4800..40627cc3 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DevicePortVlanTagged.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePortVlanTagged.pm @@ -1,81 +1,19 @@ use utf8; package Netdisco::DB::Result::DevicePortVlanTagged; -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - use strict; use warnings; -use base 'DBIx::Class::Core'; -__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); +use base 'Netdisco::DB::Result::DevicePortVlan'; +__PACKAGE__->load_components('Helper::Row::SubClass'); +__PACKAGE__->subclass; + +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); __PACKAGE__->table("device_port_vlan_tagged"); __PACKAGE__->result_source_instance->is_virtual(1); -__PACKAGE__->result_source_instance->view_definition( - 'SELECT * FROM device_port_vlan WHERE NOT native' -); - -__PACKAGE__->add_columns( - "ip", - { data_type => "inet", is_nullable => 0 }, - "port", - { data_type => "text", is_nullable => 0 }, - "vlan", - { data_type => "integer", is_nullable => 0 }, - "native", - { data_type => "boolean", default_value => \"false", is_nullable => 0 }, - "creation", - { - data_type => "timestamp", - default_value => \"current_timestamp", - is_nullable => 1, - original => { default_value => \"now()" }, - }, - "last_discover", - { - data_type => "timestamp", - default_value => \"current_timestamp", - is_nullable => 1, - original => { default_value => \"now()" }, - }, -); -__PACKAGE__->set_primary_key("ip", "port", "vlan"); - - -# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/3KLjJ3D18pGaPEaw9EU5w - -=head1 RELATIONSHIPS - -=head2 device - -Returns the entry from the C table which hosts the Port on which this -VLAN is configured. - -=cut - -__PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip' ); - -=head2 port - -Returns the entry from the C table on which this VLAN is configured. - -=cut - -__PACKAGE__->belongs_to( port => 'Netdisco::DB::Result::DevicePort', { - 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port', -}); - -=head2 vlan - -Returns the entry from the C table describing this VLAN in -detail, typically in order that the C can be retrieved. - -=cut - -__PACKAGE__->belongs_to( vlan => 'Netdisco::DB::Result::DeviceVlan', { - 'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan', +__PACKAGE__->result_source_instance->view_definition(q{ + SELECT * FROM device_port_vlan WHERE NOT native }); 1; diff --git a/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm b/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm index b1c651ad..a6372a0a 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm @@ -53,14 +53,8 @@ Link relationship for C, see below. =cut -__PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan', - { - 'foreign.ip' => 'self.ip', - 'foreign.vlan' => 'self.vlan', - }, - { - where => { -not_bool => 'me.native' }, - } +__PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlanTagged', + { 'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan' }, ); =head2 port_vlans_native @@ -69,14 +63,8 @@ Link relationship to support C, see below. =cut -__PACKAGE__->has_many( port_vlans_native => 'Netdisco::DB::Result::DevicePortVlan', - { - 'foreign.ip' => 'self.ip', - 'foreign.vlan' => 'self.vlan', - }, - { - where => { -bool => 'me.native' }, - } +__PACKAGE__->has_many( port_vlans_native => 'Netdisco::DB::Result::DevicePortVlanNative', + { 'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan' }, ); =head2 tagging_ports