From 134b7a7646cb3baaad1a66fe3cc5d65ee7d95399 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 10 Jan 2014 19:36:08 +0000 Subject: [PATCH] Remove reference to "native" VLAN in code and replace with "untagged" --- Netdisco/Changes | 5 +++ .../lib/App/Netdisco/DB/Result/DevicePort.pm | 22 +++++++---- .../App/Netdisco/DB/Result/DevicePortVlan.pm | 2 +- .../lib/App/Netdisco/DB/Result/DeviceVlan.pm | 39 ++++++++++++------- .../DB/Result/Virtual/DevicePortVlanNative.pm | 19 --------- .../DB/Result/Virtual/DevicePortVlanTagged.pm | 19 --------- .../App/Netdisco/DB/ResultSet/DevicePort.pm | 3 +- 7 files changed, 48 insertions(+), 61 deletions(-) delete mode 100644 Netdisco/lib/App/Netdisco/DB/Result/Virtual/DevicePortVlanNative.pm delete mode 100644 Netdisco/lib/App/Netdisco/DB/Result/Virtual/DevicePortVlanTagged.pm diff --git a/Netdisco/Changes b/Netdisco/Changes index 47919718..858c3824 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,5 +1,10 @@ 2.021001 + [ENHANCEMENTS] + + * [#66] Remove reference to "native" VLAN in code and replace with "untagged" + * [#66] DB Schema update to add "native" column to PK of device_port_vlan table + [BUG FIXES] * Correct is_discoverable check in Undiscovered Neighbors report diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm index 7ccf135c..ff590c89 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm @@ -84,8 +84,8 @@ __PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' ); Returns the set of C entries associated with this Port. -These will be both native and non-native (tagged). See also -C and C. +These will be both tagged and untagged. See also C and +C. =cut @@ -190,13 +190,19 @@ port, where the VLANs are all tagged. =cut -__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::Virtual::DevicePortVlanTagged', - { - 'foreign.ip' => 'self.ip', - 'foreign.port' => 'self.port', +__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::DevicePortVlan', + sub { + my $args = shift; + return { + "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, + "$args->{foreign_alias}.port" => { -ident => "$args->{self_alias}.port" }, + -not_bool => "$args->{foreign_alias}.native", + }; + }, + { + join_type => 'LEFT', + cascade_copy => 0, cascade_update => 0, cascade_delete => 0, }, - { join_type => 'LEFT', - cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }, ); =head2 tagged_vlans diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DevicePortVlan.pm b/Netdisco/lib/App/Netdisco/DB/Result/DevicePortVlan.pm index 684e4acd..fca103d2 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/DevicePortVlan.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/DevicePortVlan.pm @@ -35,7 +35,7 @@ __PACKAGE__->add_columns( "vlantype", { data_type => "text", is_nullable => 1 }, ); -__PACKAGE__->set_primary_key("ip", "port", "vlan"); +__PACKAGE__->set_primary_key("ip", "port", "vlan", "native"); # Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DeviceVlan.pm b/Netdisco/lib/App/Netdisco/DB/Result/DeviceVlan.pm index 06d328c5..c23f8ded 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/DeviceVlan.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/DeviceVlan.pm @@ -49,23 +49,37 @@ __PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' ); =head2 port_vlans_tagged -Link relationship for C, see below. +Link relationship for C, see below. =cut -__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::Virtual::DevicePortVlanTagged', - { 'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan' }, +__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::DevicePortVlan', + sub { + my $args = shift; + return { + "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, + "$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" }, + -not_bool => "$args->{foreign_alias}.native", + }; + }, { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } ); -=head2 port_vlans_native +=head2 port_vlans_untagged -Link relationship to support C, see below. +Link relationship to support C, see below. =cut -__PACKAGE__->has_many( port_vlans_native => 'App::Netdisco::DB::Result::Virtual::DevicePortVlanNative', - { 'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan' }, +__PACKAGE__->has_many( port_vlans_untagged => 'App::Netdisco::DB::Result::DevicePortVlan', + sub { + my $args = shift; + return { + "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, + "$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" }, + -bool => "$args->{foreign_alias}.native", + }; + }, { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } ); @@ -80,21 +94,20 @@ __PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePortVlan', { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } ); -=head2 tagging_ports +=head2 tagged_ports Returns the set of Device Ports on which this VLAN is configured to be tagged. =cut -__PACKAGE__->many_to_many( tagging_ports => 'port_vlans_tagged', 'port' ); +__PACKAGE__->many_to_many( tagged_ports => 'port_vlans_tagged', 'port' ); -=head2 native_ports +=head2 untagged_ports -Returns the set of Device Ports on which this VLAN is the native VLAN (that -is, untagged). +Returns the set of Device Ports on which this VLAN is an untagged VLAN. =cut -__PACKAGE__->many_to_many( native_ports => 'port_vlans_native', 'port' ); +__PACKAGE__->many_to_many( untagged_ports => 'port_vlans_untagged', 'port' ); 1; diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DevicePortVlanNative.pm b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DevicePortVlanNative.pm deleted file mode 100644 index d2930465..00000000 --- a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DevicePortVlanNative.pm +++ /dev/null @@ -1,19 +0,0 @@ -use utf8; -package App::Netdisco::DB::Result::Virtual::DevicePortVlanNative; - -use strict; -use warnings; - -use base 'App::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/App/Netdisco/DB/Result/Virtual/DevicePortVlanTagged.pm b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DevicePortVlanTagged.pm deleted file mode 100644 index 0cdfa1a9..00000000 --- a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DevicePortVlanTagged.pm +++ /dev/null @@ -1,19 +0,0 @@ -use utf8; -package App::Netdisco::DB::Result::Virtual::DevicePortVlanTagged; - -use strict; -use warnings; - -use base 'App::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(q{ - SELECT * FROM device_port_vlan WHERE NOT native -}); - -1; diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm index 1bb18f49..1d1006ad 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm @@ -125,11 +125,12 @@ sub with_vlan_count { ->search({}, { '+columns' => { tagged_vlans_count => - $rs->result_source->schema->resultset('Virtual::DevicePortVlanTagged') + $rs->result_source->schema->resultset('DevicePortVlan') ->search( { 'dpvt.ip' => { -ident => 'me.ip' }, 'dpvt.port' => { -ident => 'me.port' }, + -not_bool => { -ident => 'dpvt.native' }, }, { alias => 'dpvt' } )->count_rs->as_query