« blib/lib/App/Netdisco/DB/Result/DevicePower.pm
↑ Summary
blib/lib/App/Netdisco/DB/Result/DeviceVrf.pm »
| 1 | use utf8; | ||
| 2 | package App::Netdisco::DB::Result::DeviceVlan; | ||
| 3 | |||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use 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 => \"LOCALTIMESTAMP", | ||
| 21 | is_nullable => 1, | ||
| 22 | original => { default_value => \"LOCALTIMESTAMP" }, | ||
| 23 | }, | ||
| 24 | "last_discover", | ||
| 25 | { | ||
| 26 | data_type => "timestamp", | ||
| 27 | default_value => \"LOCALTIMESTAMP", | ||
| 28 | is_nullable => 1, | ||
| 29 | original => { default_value => \"LOCALTIMESTAMP" }, | ||
| 30 | }, | ||
| 31 | ); | ||
| 32 | __PACKAGE__->set_primary_key("ip", "vlan"); | ||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | =head1 RELATIONSHIPS | ||
| 37 | |||
| 38 | =head2 device | ||
| 39 | |||
| 40 | Returns 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 | |||
| 48 | Link 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 | |||
| 66 | Link 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 | |||
| 84 | Link 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 | |||
| 95 | Returns 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 | |||
| 103 | Returns 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 | |||
| 109 | 1; |