1use utf8; 2package App::Netdisco::DB::Result::DeviceVlan; 3 4 5use strict; 6use warnings; 7 8use base 'App::Netdisco::DB::Result'; 9__PACKAGE__->table("device_vlan"); 10__PACKAGE__->add_columns( 11 "ip", 12 { data_type => "inet", is_nullable => 0 }, 13 "vlan", 14 { data_type => "integer", is_nullable => 0 }, 15 "description", 16 { data_type => "text", is_nullable => 1 }, 17 "creation", 18 { 19 data_type => "timestamp", 20 default_value => \"current_timestamp", 21 is_nullable => 1, 22 original => { default_value => \"now()" }, 23 }, 24 "last_discover", 25 { 26 data_type => "timestamp", 27 default_value => \"current_timestamp", 28 is_nullable => 1, 29 original => { default_value => \"now()" }, 30 }, 31); 32__PACKAGE__->set_primary_key("ip", "vlan"); 33 34 35 36=head1 RELATIONSHIPS 37 38=head2 device 39 40Returns the entry from the C<device> table on which this VLAN entry was discovered. 41 42=cut 43 44__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' ); 45 46=head2 port_vlans_tagged 47 48Link relationship for C<tagged_ports>, see below. 49 50=cut 51 52__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::DevicePortVlan', 53 sub { 54 my $args = shift; 55 return { 56 "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, 57 "$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" }, 58 -not_bool => "$args->{foreign_alias}.native", 59 }; 60 }, 61 { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } 62); 63 64=head2 port_vlans_untagged 65 66Link relationship to support C<untagged_ports>, see below. 67 68=cut 69 70__PACKAGE__->has_many( port_vlans_untagged => 'App::Netdisco::DB::Result::DevicePortVlan', 71 sub { 72 my $args = shift; 73 return { 74 "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, 75 "$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" }, 76 -bool => "$args->{foreign_alias}.native", 77 }; 78 }, 79 { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } 80); 81 82=head2 ports 83 84Link relationship to support C<ports>. 85 86=cut 87 88__PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePortVlan', 89 { 'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan' }, 90 { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } 91); 92 93=head2 tagged_ports 94 95Returns the set of Device Ports on which this VLAN is configured to be tagged. 96 97=cut 98 99__PACKAGE__->many_to_many( tagged_ports => 'port_vlans_tagged', 'port' ); 100 101=head2 untagged_ports 102 103Returns the set of Device Ports on which this VLAN is an untagged VLAN. 104 105=cut 106 107__PACKAGE__->many_to_many( untagged_ports => 'port_vlans_untagged', 'port' ); 108 1091; 110