diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm index 8160bb1d..884f8796 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm @@ -80,16 +80,29 @@ Returns the Device table entry to which the given Port is related. __PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' ); -=head2 vlans +=head2 port_vlans Returns the set of C entries associated with this Port. +These will be both tagged and untagged. Use this relation in search conditions. -These will be both tagged and untagged. See also C and -C. +See also C. =cut -__PACKAGE__->has_many( vlans => 'App::Netdisco::DB::Result::DevicePortVlan', +__PACKAGE__->has_many( port_vlans => 'App::Netdisco::DB::Result::DevicePortVlan', + { 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' } ); + +=head2 all_port_vlans + +Returns the set of C entries associated with this Port. +These will be both tagged and untagged. Use this relation when prefetching related +C rows. + +See also C. + +=cut + +__PACKAGE__->has_many( all_port_vlans => 'App::Netdisco::DB::Result::DevicePortVlan', { 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' } ); =head2 nodes / active_nodes / nodes_with_age / active_nodes_with_age @@ -183,39 +196,17 @@ __PACKAGE__->has_many( neighbor_alias => 'App::Netdisco::DB::Result::DeviceIp', { join_type => 'LEFT' }, ); -=head2 port_vlans_tagged +=head2 vlans -Returns a set of rows from the C table relating to this -port, where the VLANs are all tagged. - -=cut - -__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, - }, -); - -=head2 tagged_vlans - -As compared to C, this relationship returns a set of VLAN +As compared to C, this relationship returns a set of VLAN row objects for the VLANs on the given port, which might be more useful if you want to find out details such as the VLAN name. -See also C. +See also C. =cut -__PACKAGE__->many_to_many( tagged_vlans => 'port_vlans_tagged', 'vlan' ); +__PACKAGE__->many_to_many( vlans => 'all_port_vlans', 'vlan' ); =head2 oui @@ -259,26 +250,26 @@ sub neighbor { =head2 native -An alias for the C column, which stores the PVID (that is, the VLAN +An alias for the C column, which stores the PVID (that is, the VLAN ID assigned to untagged frames received on the port). =cut -sub native { return (shift)->pvid } +sub native { return (shift)->vlan } -=head2 tagged_vlans_count +=head2 vlan_count -Returns the number of tagged VLANs active on this device port. Enable this -column by applying the C modifier to C. +Returns the number of VLANs active on this device port. Enable this column by +applying the C modifier to C. =cut -sub tagged_vlans_count { return (shift)->get_column('tagged_vlans_count') } +sub vlan_count { return (shift)->get_column('vlan_count') } =head2 lastchange_stamp Formatted version of the C field, accurate to the minute. Enable -this column by applying the C modifier to C. +this column by applying the C modifier to C. The format is somewhat like ISO 8601 or RFC3339 but without the middle C between the date stamp and time stamp. That is: diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm index 1d1006ad..46429de0 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/DevicePort.pm @@ -111,7 +111,7 @@ will add the following additional synthesized columns to the result set: =over 4 -=item tagged_vlans_count +=item vlan_count =back @@ -124,15 +124,14 @@ sub with_vlan_count { ->search_rs($cond, $attrs) ->search({}, { - '+columns' => { tagged_vlans_count => + '+columns' => { vlan_count => $rs->result_source->schema->resultset('DevicePortVlan') ->search( { - 'dpvt.ip' => { -ident => 'me.ip' }, - 'dpvt.port' => { -ident => 'me.port' }, - -not_bool => { -ident => 'dpvt.native' }, + 'dpv.ip' => { -ident => 'me.ip' }, + 'dpv.port' => { -ident => 'me.port' }, }, - { alias => 'dpvt' } + { alias => 'dpv' } )->count_rs->as_query }, }); diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 52f872b7..3b06abd0 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -21,8 +21,8 @@ hook 'before' => sub { { name => 'c_speed', label => 'Speed', default => '' }, { name => 'c_mac', label => 'Port MAC', default => '' }, { name => 'c_mtu', label => 'MTU', default => '' }, - { name => 'c_vlan', label => 'Native VLAN', default => 'on' }, - { name => 'c_vmember', label => 'Tagged VLANs', default => 'on' }, + { name => 'c_pvid', label => 'Native VLAN', default => 'on' }, + { name => 'c_vmember', label => 'VLAN Membership', default => 'on' }, { name => 'c_power', label => 'PoE', default => '' }, { name => 'c_nodes', label => 'Connected Nodes', default => '' }, { name => 'c_neighbors', label => 'Connected Devices', default => 'on' }, diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm index 735aa273..4e7533c8 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm @@ -27,18 +27,18 @@ get '/ajax/content/device/ports' => require_login sub { if (param('invert')) { $set = $set->search({ 'me.vlan' => { '!=' => $f }, - 'port_vlans_tagged.vlan' => [ + 'port_vlans.vlan' => [ '-or' => { '!=' => $f }, { '=' => undef } ], - }, { join => 'port_vlans_tagged' }); + }, { join => 'port_vlans' }); } else { $set = $set->search({ -or => { 'me.vlan' => $f, - 'port_vlans_tagged.vlan' => $f, + 'port_vlans.vlan' => $f, }, - }, { join => 'port_vlans_tagged' }); + }, { join => 'port_vlans' }); } return unless $set->count; @@ -116,7 +116,7 @@ get '/ajax/content/device/ports' => require_login sub { # run single collapsed query for all relations, but only if we're not # also fetching archived data (tests show it's better this way) - $set = $set->search_rs({}, { prefetch => [{ port_vlans_tagged => 'vlan'}] }) + $set = $set->search_rs({}, { prefetch => 'all_port_vlans' }) if param('c_vmember') and not (param('c_nodes') and param('n_archived')); # what kind of nodes are we interested in? diff --git a/Netdisco/lib/App/Netdisco/Web/PortControl.pm b/Netdisco/lib/App/Netdisco/Web/PortControl.pm index 4dea3385..b362fb70 100644 --- a/Netdisco/lib/App/Netdisco/Web/PortControl.pm +++ b/Netdisco/lib/App/Netdisco/Web/PortControl.pm @@ -18,7 +18,7 @@ ajax '/ajax/portcontrol' => require_role port_control => sub { 'contact' => 'contact', 'c_port' => 'portcontrol', 'c_name' => 'portname', - 'c_vlan' => 'vlan', + 'c_pvid' => 'vlan', 'c_power' => 'power', ); diff --git a/Netdisco/share/public/javascripts/netdisco_portcontrol.js b/Netdisco/share/public/javascripts/netdisco_portcontrol.js index 5e8a60db..dd810a27 100644 --- a/Netdisco/share/public/javascripts/netdisco_portcontrol.js +++ b/Netdisco/share/public/javascripts/netdisco_portcontrol.js @@ -146,7 +146,7 @@ $(document).ready(function() { else if (nl) { event.preventDefault(); - if (td.data('field') == 'c_vlan') { + if (td.data('field') == 'c_pvid') { $('#nd_portlog').one('hidden', function() { port_control(cell); // save }); diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index 0cc58174..f314ec87 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -129,10 +129,10 @@ [% row.mtu | html_entity %] [% END %] - [% IF params.c_vlan %] + [% IF params.c_pvid %] [% IF user_can_port_control AND params.c_admin %] + data-field="c_pvid" data-for-device="[% device.ip | html_entity %]" data-for-port="[% row.port | html_entity %]">
[% IF row.vlan %][% row.vlan | html_entity %][% END %] @@ -149,17 +149,17 @@ [% IF params.c_vmember %] - [% IF row.tagged_vlans_count %] + [% IF row.vlan_count %] [% SET output = '' %] [% SET vlanlist = [] %] - [% FOREACH vlan IN row.tagged_vlans %][% vlanlist.push(vlan.vlan) %][% END %] + [% FOREACH vlan IN row.all_port_vlans %][% vlanlist.push(vlan.get_column('vlan')) %][% END %] [% FOREACH vlan IN vlanlist.nsort %] [% SET output = output _ '' _ vlan _ '' %] [% SET output = output _ ', ' IF NOT loop.last %] [% END %] - [% IF row.tagged_vlans_count > 10 %] [%# TODO make this a settable variable %] - [% SET output = '
(' _ row.tagged_vlans_count + [% IF row.vlan_count > 10 %] [%# TODO make this a settable variable %] + [% SET output = '
(' _ row.vlan_count _ ')
Show VLANs
' _ output %] diff --git a/Netdisco/share/views/ajax/device/ports_csv.tt b/Netdisco/share/views/ajax/device/ports_csv.tt index 08fe42e3..63343a00 100644 --- a/Netdisco/share/views/ajax/device/ports_csv.tt +++ b/Netdisco/share/views/ajax/device/ports_csv.tt @@ -95,15 +95,15 @@ [% myport.push(row.mtu) %] [% END %] - [% IF params.c_vlan %] + [% IF params.c_pvid %] [% myport.push(row.vlan) %] [% END %] [% IF params.c_vmember %] - [% IF row.tagged_vlans_count %] + [% IF row.vlan_count %] [% SET output = '' %] [% SET vlanlist = [] %] - [% FOREACH vlan IN row.tagged_vlans %][% vlanlist.push(vlan.vlan) %][% END %] + [% FOREACH vlan IN row.all_port_vlans %][% vlanlist.push(vlan.get_column('vlan')) %][% END %] [% FOREACH vlan IN vlanlist.nsort %] [% SET output = output _ ',' IF NOT loop.first %] [% SET output = output _ vlan %] diff --git a/Netdisco/share/views/ajax/search/port.tt b/Netdisco/share/views/ajax/search/port.tt index 7d00832f..88416bb1 100644 --- a/Netdisco/share/views/ajax/search/port.tt +++ b/Netdisco/share/views/ajax/search/port.tt @@ -16,7 +16,7 @@ [% ' (' _ row.device.dns _ ')' IF row.device.dns %] [% row.descr | html_entity %] - [% row.vlan | html_entity %] + [% row.vlan | html_entity %] [% END %] diff --git a/Netdisco/share/views/ajax/search/port_csv.tt b/Netdisco/share/views/ajax/search/port_csv.tt index 6f97c7f7..11c56e6a 100644 --- a/Netdisco/share/views/ajax/search/port_csv.tt +++ b/Netdisco/share/views/ajax/search/port_csv.tt @@ -9,4 +9,4 @@ [% END %] [% CSV.dump(mylist) %] -[% END %] \ No newline at end of file +[% END %]